Page 1 of 1

Possiblity for significantly lowering game load time

Posted: Fri Dec 12, 2014 3:02 pm
by WanderingAirhead
Now, this is not really an idea, but suggestion on the significant performance issue, that in my opinion is the loading time of the game (the loading of the game takes more than a minute on my laptop). Having no access to the game sources I can't be sure, but what i suspect happens is, when the game starts it loads all of the lua files of the base mod in their raw, text form and compiles them on the fly, and only goes to the menu once all resources are loaded.

Well the thing you may want to do is using luac to precompile all the lua resources and during game bootup only load the compiled sources. The loading of the precompiled files is usually more than 100 times faster than loading the text file and compiling it on the fly. And it doesn't require much in the way of changes to introduce.

The 'require' method of lua handles the compiled sources the same way it does the text ones, so there is no need to make any changes in the resource files. The only thing you would have to do is edit the package.path to enable searching for names other than *.lua and *.so.

Of course the problem you face then is - what happens when someone creates a mod, or modifies the base mod. Well, either you add an option to the factorio executable like --force-recompile to tell the game that the lua resources changed and force it to recompile, or the second option is to search the mod directory and check all the raw *.lua files and compare their modification times to those of the compiled resources, and only recompile those resources, where the *.lua files was modified more recently. The check could take a moment, but nowhere near the time necessary to compile everything.

Another thing to contemplate, if you actually use the precompiled lua resources, is loading everything in the background, and only load imidiately the things that are necessary to show the menu, and possibly block the user only when he tries to start the actual game, which should give the background thread a couple of seconds to boost the user experience. Of course this option is by far more complicated and requires a lof of work, so you would probably want to put it in some distant corner of your backlog.

Well in case I'm wrong about how the things work - I was only trying to help :)

Re: Possiblity for significantly lowering game load time

Posted: Fri Dec 12, 2014 3:32 pm
by sillyfly
Judging by the loading screen text, the thing that takes most of the time is loading the graphical assets... I'm not sure how much overhead the loading of mods adds, but I did notice that loading takes a bit longer the first time a mod is "installed", so maybe this is already done?

Re: Possiblity for significantly lowering game load time

Posted: Fri Dec 12, 2014 5:30 pm
by Architekt
WanderingAirhead wrote:Now, this is not really an idea, but suggestion on the significant performance issue, that in my opinion is the loading time of the game (the loading of the game takes more than a minute on my laptop). ...
If it takes more than minute on your laptop than you have issue with your laptop. On mine it takes about 10 seconds, most of the time loading sprites.

Re: Possiblity for significantly lowering game load time

Posted: Fri Dec 12, 2014 5:50 pm
by n9103
Every additional mod adds time to the load, depending on how large the mod is. It's quite easy to use mods in moderation, and still take longer to load the mods than the rest of the game.
One possible problem with load times for the average user is the large amount of fragmentation that downloaded files then to get.

As for the speed increase, I would bet a month's pay that it's a result of the disk or RAM cache, and not the game loading some compiled version. (Being that I'm in the directory structure a lot, this isn't a fair bet ;))
That aside, a compiled version may gain a speed increase, but that speed increase depends on how slow the current parsing function is, and how large a file is being loaded.
I can't really comment on the current parsing speed, though it does seem a touch on the slow side if the current form of it is the final version. (I highly doubt that it won't receive optimization in the future).
But I am rather certain that the size aspect is irrelevant, as mods tend to max out a a few MB, far less than the rest of the game files that are loaded, meaning I/O speed isn't a factor here.

Re: Possiblity for significantly lowering game load time

Posted: Sat Dec 13, 2014 7:19 am
by Xecutor
As much as I hate lua, I cannot deny that lua compiler is very fast.
While loading either luac or lua files the bottleneck is always hard drive.
Especially if it's laptop where 5400rpm drives are often used.
In my case majority of loading time is loading of graphics.
I wonder if it is possible to put base mod in zip file to save on seeks and directory content reading?

Re: Possiblity for significantly lowering game load time

Posted: Sat Dec 13, 2014 8:00 am
by n9103
It will be treated like any other mod if zipped and placed in mod directory. Will load fine.
Time to process compressed zip is not significantly improved over time to load from disk [in most cases]. (I myself use a standard speed drive.) PNG files (and images in general) do not compress well. For PNGs specifically, it's because they're already space optimized. For most other images, it's because the data is generally too variable to make repeating patterns of bits common.
Did not test extensively, only generating a new game.

Re: Possiblity for significantly lowering game load time

Posted: Sat Dec 13, 2014 12:03 pm
by Xecutor
Huh... I tried to zip base and place it into mods. It works.
But loading time actually become much worse, even if zip was created in store mode (i.e. without any compression).
Normal loading time is 7 seconds, with base zipped loading time is 39 seconds.
It looks like zip handling is somewhat inefficient. Probably some unnecessary memory movements are involved?

Re: Possiblity for significantly lowering game load time

Posted: Sun Dec 14, 2014 6:21 am
by n9103
Your entire load process only takes 7 seconds?
You have to account for more than just the initial section that loads mods.
Did you happen to have the base folder and the base zip present at the same time?
Is the base.zip file horribly fragmented? (assuming not on SSD)

Re: Possiblity for significantly lowering game load time

Posted: Sun Dec 14, 2014 12:38 pm
by Xecutor
n9103 wrote:Your entire load process only takes 7 seconds?
Yes. But with only 3 or 4 lightweight mods installed.
n9103 wrote:You have to account for more than just the initial section that loads mods.
Did you happen to have the base folder and the base zip present at the same time?
Nope. I moved away base folder and then zipped it into mods. as base_0.11.6.zip.
n9103 wrote:Is the base.zip file horribly fragmented? (assuming not on SSD)
It's not on ssd. But since I just zipped it, it's all in the file cache.
So it is definitely the way the game handles zip files that is slow.