SirDiazo / AGExt

Action Groups Extended
13 stars 18 forks source link

DeleteOldSaveGames + lots of quicksave files = 2 minute KSC load time #11

Closed jgottula closed 9 years ago

jgottula commented 9 years ago

I have about 200 quicksave files in my main savegame, created with the alt-F5 shortcut (named quicksave #1.sfs, quicksave #2.sfs, and so on, all the way up to quicksave #200.sfs). I recently noticed that going to the KSC scene from the main menu suddenly started taking a ridiculously long time; 2 minutes on average.

Then I noticed in Process Monitor that KSP was going through every single .sfs file in my savegame directory and loading each and every one of the 200 files into memory, presumably parsing each one as it went. I eventually was able to find a call stack for one of the thousands of ReadFile calls, and mono_pmip led me to the culprit, ActionGroupsExtended.AGExtMainMenu.DeleteOldSaveGames.

I appreciate the intent of DeleteOldSaveGames to keep the savegame directory free of unnecessary AGExt*.cfg files, but surely there's a better way to do this than to load and parse every single .sfs file in the directory every time a savegame gets loaded. Keeping 200 quicksaves around might sound a little excessive, but I did it under the understandable assumption that the game would never have any reason to load and parse all of them.

Short of rewriting the DeleteOldSaveGames function to be more efficient, perhaps an option could be added to AGExt.cfg to disable this cleanup functionality? Or at the very least, it would probably be helpful to print something on the KSP log so others who run into this problem can get an idea of what's taking so long; tracking down the source of this slowdown was a bit of a pain.

SirDiazo commented 9 years ago

-Add option to not clean up old AGX files.

Okay, I am surprised that 200 files would take that long to progress. I can only assume that KSP is doing something odd in the background (loading each .sfs entirely, but with several readfiles per.sfs file?) You evidence is pretty conclusive though.

Looking at my code I see nothing that I could streamline, it is pretty straightforward, I'm after a single number stored in my AGExtScenario node.

I will add a disable switch for you, that is pretty straightforward.

SirDiazo commented 9 years ago

Option is added to version 1.17a, available from the forum.