A Programmer Reduced GTA Online Load Times By 70 Percent
Rockstar is one of the biggest game developers on the planet and has some of the most popular and profitable games out there. One of its very popular and profitable games is GTA Online. While the game has been available for seven years and is still wildly popular. One of the things that many gamers complain about is that the game loads very slowly no matter how powerful the hardware it's being played on.
Recently, a programmer going by t0st use some creative programming techniques to reduce load times by 70 percent. T0st was sitting through a six-minute load for GTA Online on a mid-range gaming PC and opened Task Manager, where he discovered something interesting. After the one-minute mark, the programmer said the CPU usage of his computer spiked dramatically while storage and network usage were virtually nonexistent.
T0st realized that meant long load times weren't caused by Rockstar servers or data being read from a drive. Something was running directly on the processor that needed a lot of processing power to complete while using only a single thread. T0st then turned to a series of programming and debugging tools leading to two significant issues being uncovered.
The first significant issue was that the game was reading a text file of all purchasable items in the game, 63,000 items in total. It was counting every character in the 10-megabyte text file for each of the 63,000 items meaning a lot of wasted processor time. The other issue was that in preparation for the data to be read, the game recorded both the data associated with that item, such as its name, price, category, and stats, and a hash of that item that uniquely identified it. That process happened 63,000 times.
Load time increases each time more items are loaded into the game. T0st estimated that the game was forming nearly 2 billion checks eating up massive amounts of processor time. To alleviate the issues, the programmer wrote code overwriting some of the game's functions solving the item reading issue.
He created a basic cache to calculate the length of a list of items once that's able to return the same value without doing the calculation again whenever the length is asked for by code in the game. That trick slashed the number of times the check needed to be performed from 63,000 to one. The custom code also skips the check for duplicate items chopping nearly 2 billion checks that didn't need to occur, resulting in a load time cut from around six minutes to less than two minutes.