Here are some numbers from http://moodle.org/mod/choice/view.php?id=158
Displaying view.php as admin:
45.419154 secs
RAM: 30.1MB
RAM peak: 51.8MB
Included 55 files
DB queries 51810 (!!!!!)
Log writes 1
ticks: 4542 user: 1969 sys: 86 cuser: 0 csys: 0
Load average: 1.60
Record cache hit/miss ratio : 0/8
Displaying view.php as ordinary user:
26.286735 secs
RAM: 28MB
RAM peak: 49.6MB
Included 41 files
DB queries 51805
Log writes 1
ticks: 2629 user: 1792 sys: 69 cuser: 0 csys: 0
Load average: 1.98
Record cache hit/miss ratio : 0/8
Displaying report.php as admin (with patch, thanks, because it runs out of memory without patch):
69.938082 secs
RAM: 28.1MB
RAM peak: 49.6MB
Included 42 files
DB queries 59945
Log writes 1
ticks: 6994 user: 2128 sys: 463 cuser: 0 csys: 0
Load average: 1.43
Record cache hit/miss ratio : 1/9
There is still a long way to go here (look at all those db accesses for has_capability inside loops). Really we should be able to get all the data with one SQL statement and some joins.
Oddly, there are 4367 active participants in Using Moodle currently, but Choice says there's 8407 responses, so something is wrong.
Originally, the choice module only showed and counted answers from currently enrolled people. I'm guessing the code is still trying to do that (but it seems to be failing to do so accurately).
On the other hand perhaps we COULD let it show just all the choices that have been recorded (back until the course start date perhaps or even a choice start date). This would be bog-simple SQL and fast.
It's related to using too much memory (usually these are a get_records type call)
[Fri Feb 15 17:34:26 2008] [error] [client 220.227.31.67] PHP Fatal error: Allowed memory size of 100663296 bytes exhausted (tried to allocate 71 bytes) in /var/www/html/moodle/lib/adodb/adodb.inc.php on line 3004, referer: http://moodle.org/mod/choice/view.php?id=6689