Closed EngineOfDarkness closed 3 years ago
Did some rudimentary benchmarking with os.clock() - things to keep in mind is that this code isn't purely "lua" (since it interfaces with the xray engine on several occasions like reading / copying and writing the files aswell as the system ltx reload) but it does feel considerably slower to load when the measured time is higher ("black screen time" while loading the game up).
So while the seconds itself may not be exact, it does correlate with longer loading times (good enough for the purposes of this issue)
Between each tries I made sure that all files generated by my Library are removed. I always launched the game from the Launcher.
For the Seconds before Fix
I measured the complete loop in autoloader.script
- code was unchanged otherwise
for _, filename in ipairs(loaders) do
printf("AUTOLOADER: Executing %s.%s()", filename, callbackFunctionName)
_G[filename][callbackFunctionName]()
end
after reload
is the time the loop took, including the reload_ini_sys code that is called in the other autoloaders.
This has no before reload
measurement because the reload is done inside the autoloaders
For the Seconds after Fix
I removed the following code from Ini:reloadSystemIni
and put it after the autoloader loop (see above) in autoloader.script
- this means in this test the reload_ini_sys is always executed (and therefore is slower than the default code when NO mods are installed, because the default code only executes reload_ini_sys when changed have been made)
printf("LTX-LIBRARY: Reloading and Clearing ini cache")
reload_ini_sys()
clear_ini_cache(ini_sys)
before reload
is just the the time loop took
after reload
is the time the look took + the reload_ini_sys code
Situation | Seconds before Fix | Seconds after Fix |
---|---|---|
No Mods | ||
before reload | n/a | ~0.004 |
after reload | ~0.003 | ~0.155 |
system.ltx autoloader registering 4 different Changesets from 4 Files with a total of 86 changes | ||
before reload | n/a | ~0.619 |
after reload | ~0.926 | ~0.942 |
trader ltx autoloader registering 7 different Changesets from 6 Files with a total of 8 changes | ||
before reload | n/a | ~0.143 |
after reload | ~1.054 | ~0.297 |
combined | ||
before reload | n/a | ~0.745 |
after reload | ~3.002 | ~1.068 |
So the "simple" fix is a bit slower when no Mods are installed, has the same speed if only System ltx changing mods are installed but is way faster in case multiple trader changing mods are installed or a combination with system.ltx changes.
The "no mods" case for the fix should be fixable so it's just about as fast - however I won't put too much time into that case because if you have No Mods that use this library, why even install it?
Now these times aren't absolute - I expect as the amount of Changes climbs that the startup time is going to get worse somewhat. But that's something for another optimization ticket.
For the "No Mods Case" I made use of SetEvent and GetEvent (from Anomaly Scripts) - the two autoloaders (system ltx & trader ltx) signal the core autoloader if reload_ini_sys
needs to be called.
I'm pretty sure I noticed the startup getting slower with more trader files (I mainly use for manual testing, until #4 is done).
I am quite certain this is because of repeated calls to reloadSystemIni.
When I was testing this engine function ingame originally (before 0.1.0 was released), I noticed that the game would hang for ~1 second - so I guess that the startup time will only get worse the more Changesets are registered.
I need to refactor this, so that
reloadSystemIni
is only called once, after all Changesets are applied globally (so system.ltx changes, trader changes, etc.)This means I need to move this out of the
Ini.lua
- it doesn't belong in there anyway.