We had a site where there were over 200 students and several site groups. Assessments were being released to those groups. We saw load times as much as 5 minutes to access the Total Scores page, but if the assessment was NOT released to a group, the Total Scores page loaded in a few seconds.
The reason was that there was an inefficiency in how the code decided which users were supposed to be in the list for assessments released to groups. For each of the 200+ students, it had to do some DB checks to see if that student was a member of the group(s) the assessment was released to. That's 200+ individual queries where it could be done in one.
I created a new method which returns the list of members who should be in a supplied list of site groups. This only requires a single query, and in our case it dramatically decreased the load time. I had to create a new method in the kernel for this.
See attached patch.
NOTE: do not use the original "sam-groupLoad01.patch" patch as there are issues with it (see the comments below for details)