Possiblity for significantly lowering game load time
Posted: Fri Dec 12, 2014 3:02 pm
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
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