The backup_get_all_users currently does:
$users = get_records_sql("SELECT DISTINCT id,id
FROM {$CFG->prefix}user");
if ($users) {
foreach ($users as $user)
}
but there is a way to limit the output to the repeated id column with native Moodle data functions too:
$result = get_records("user", "", "", "", "id, id");
This avoids an unnecessary global $CFG also. Strangely the foreach above (for 10K users) took 20 seconds on out production machine, but just around 2 seconds on my Windows machine... WIth the get_records-trick it takes less than a second in both machines. I'm attaching a patch for completeness.