Digital Foundry explains how a smart programmer reduced GTA Online load times by 70% • Eurogamer.net

GTA Online remains a popular (and incredibly profitable) game seven years after launch, thanks to the steady flow of new content, but one thing that Rockstar seems unable to improve is the game’s notoriously long loading time. Over the weekend, an enterprising developer named t0st finally figured out why GTA Online takes so long to load – even on machines with fast processors and storage like the PlayStation 5 and PC – and fixed those problems, reducing its loading time by 70 percent .

The blog written by t0st explaining the problems and corrections is brilliant, complete with excellent illustrations by MSPaint, but it is a little difficult to follow if you have no programming experience. I’ll try to summarize as best I can!

So: after struggling for a six-minute load for GTA Online on his mid-range PC, he opened the Task Manager the next time he loaded the game and noticed something strange: after the one-minute mark, CPU usage of your computer has increased dramatically, but storage and network usage were almost nonexistent. This suggested that long load times were not caused by Rockstar’s servers or data read from a drive – instead, something was running on the CPU. Something that required a lot of processing to complete and used only a single thread.

Armed with this knowledge, t0st used a series of programming and debugging tools to discover two main problems.

First, the game was reading in a text file all the items that can be purchased in the game – and after each of the 63,000 items, that counts each character in the 10MB text file again. Doing this count once is no big deal, but doing it 63,000 times results in a lot of wasted CPU time.

Second, to prepare all the item data that has been read, the game records the Dice associated with that item (for example, its name, price, category, statistics) and a hash of that item (essentially a calculated ‘fingerprint’ that uniquely identifies it). Each time the game stores an item on the list – which, remember, happens 63,000 times – it checks the hash value of the item being stored against the hash value of all others item that has already been stored.

At first, this does not take long, but as the number of items successfully loaded into the game increases, this check takes more and more. Altogether, t0st estimates that there were 1,984,531,500 checks (almost two billion!), Again taking up a ton of CPU time. The game does this to ensure that there are no duplicate items in the final list, but since the list is completely empty to start and the file being loaded has no duplicates, the verification is essentially useless.

To solve the problems, t0st wrote its own code that overrides some of the game’s functions. To solve the problem of ‘reading in items’, he created a basic cache, which calculates the length of the list of items once and returns the same value without actually doing the calculation again whenever the length is requested by the Rockstar code. This reduces the number of times the check needs to be done from 63,000 to one, saving a huge amount of unnecessary work.

The second correction is even easier. As he realized that there is no need to check for duplicate items, his code just inserts the new item directly, without performing the hash check. This means that none of the nearly two billion checks need to take place, and the CPU can fire during the process.

With both fixes in place, GTA Online loads manner faster. On the t0st PC, avoiding the check for duplicate items reduces the loading time from six minutes to four and a half minutes, and adding the item loading correction also reduces that time even further, to just one minute and 50 seconds. that is a 69.4 percent reduced loading times, which is absolutely incredible, since it required modifying only two functions.

So what happens now? Well, if you are an experienced game programmer with the right tools, you can download the source code here and try the fix yourself. Please note that modifying the game’s functions while the game is running in this way is classic hacking behavior, so be careful not to end up with a permanent ban.

For everyone else, your best bet is to wait for Rockstar to implement the fixes in a future GTA patch. The relative simplicity of the fix and the magnitude of the time savings should mean that it is worth investigating, especially for players on console or PCs with older AMD processors. As he himself said:

“If that gets to Rockstar in any way: problems shouldn’t take more than a day for a single developer to resolve. Do something about it:

“You can switch to a hashmap for de-duplication or skip it completely at startup for a faster fix. For the JSON parser – just swap the library for a more performing one. I don’t think there is an easier way out.

ty <3 "

Given the attention this story has received since it was published on February 28th, you expect Rockstar to at least give an answer, given how long the loading time for a bugbear has been for GTA Online throughout its long history. We will update this story if Rockstar speaks publicly about it.

Source