We have one very large Moodle 'course' with 300,000+ users. (It is not really a course. It is our documentation site where people get auto-enrolled when they visit.) In this course, if you go to Groups -> Overview, then you get a PHP out-of-memory error. Not totally suprising, but I decided to investigate a bit, which lead my done a bit of a rabbit-hole.
It turns out (MDL-66327) that get_records uses a lot more RAM than necessary. My test script makes a PHP array with ~500,000 entries first just using PHP code, and then my querying the DB. Quering the DB ends up with slighly larger memory use, but the problem is that the Peak RAM use is massively higher.
When generating the array in PHP, the peak RAM use is 322MB. Loading it with get_recordset, Peak RAM = 354 MB. Loading it with get_records, Peak RAM = 554MB. Ouch!
(I always though that get_records did get_recordset then a for loop to copy it to an array, but I was wrong! Also, PHP is weird. Generating the array in PHP code, but using sprintf, uses lots more memory. I have no idea why.)
If someone could fix this, it looks like being a useful performance win. I don't have time to do that at the moment, so please step up if you are interested. Also, I was just testing on Postgres. It would be good if someone could run my script on MySQL (bits of it may need to be edited. Thanks.