I was playing with
MDL-6856, and while debugging, I've detected that the <USERS> section in backup files is processed twice, one for creating users (and associated data like preferences, tags...) and another one to process role assignments and role overrides.
IMO, the second XML parsing should be unnecessary because all the data is stored (role assignments and role overrides includes) in the first pass.
Try to avoid the second pass and access to saved data. Will be really noticeable in courses with a lot lot of users!