How I cut GTA Online loading times by 70%

https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70

  • GTA’s JSON parsing code is accidentally quadratic, and parsing 10MB of JSON this way takes many minutes. Patching it with a dll improved load times from 6m to ~2m.
  • The primary issue seems to be that sscanf calls strlen internally, which causes a full traversal for every incremental read. Another slowdown is caused by the use of an array instead of a hash map.
  • A big takeaway here is the number of investigative/diagnostic tools the author is familiar with - debugging this would’ve been impossible without some prior knowledge of this ecosystem:

Well, did it work then?

Original online mode load time:        ~6m flat
Time with only duplication check patch: 4m 30s
Time with only JSON parser patch:       2m 50s
Time with both issues patched:          1m 50s

(6*60 - (1*60+50)) / (6*60) = 69.4% load time improvement (nice!)

Hell yes, it did! :))

Most likely, this won’t solve everyone’s load times - there might be other bottlenecks on different systems, but it’s such a gaping hole that I have no idea how R* has missed it all these years.

Edit