What would be the solution for Inno to solve this if they could? Asking because I find this bizarre enough to pique my interest.
It would pretty much be to only load the NPCs close to the player exist. There are a few issues with doing that at the moment (I'll cover that below) but it's not insurmountable.
So the solution is to just not have many NPCs in your save file? Or is it basically impossible if you play for a long amount of time?
I believe it can be fixed. I've hacked together a
You must be registered to see the links
(greatly reduces the amount of status updates per turn, particularly on files with a ton of NPCs), and resolving this would taking that to its logical conclusion.
Is that something you can implement so late into development? I was curious if maybe it's too much at this point for the code.
Yep. There are some things to consider, but with the way LT's code is structured it shouldn't be too bad.
One of the reasons that all of the NPCs currently need to remain loaded at all times is due to the way status effects work. Right now, every single turn, the game runs through all of the status effects and updates any NPC that has those status effects. When there's a lot of NPCs, this causes a ton of memory usage (all of those NPCs must remain loaded, and the game tracks a surprising amount of data for each character) as well as CPU usage (the status effect calculations are pretty comprehensive and occur across all NPCs every time the player does anything).
There are a few things that would have to happen. Firstly, status effects would have to have some sort of flag indicating their scope. Basically, indicating how far-reaching the status's effects would reach. In the case of pregnancy, at this time it seems like the offspring would appear within the same city, so a pregnant NPC in Lilaya's Manor would have to be kept active while the player is in Dominion (including Submission, since the offspring could be an imp), but if the player is in the Fields the update could be deferred. If the status effect is a clothing effect, it can be deferred until the player shares a tile with the NPC.
After status effects have been extended appropriately, an NPC loader/unloader would have to be implemented. This could fire off whenever the player enters or leaves an area. After all, you normally don't need Slave Alley NPCs loaded if the player is roaming the streets of Dominion.
I think the trickiest part about this is that it is going to essentially require the game to autosave. Right now you can massively improve inter-map performance by disabling autosaves, but that NPC data is going to have to be dumped to and restored from
somewhere if it's not going to live in memory in perpetuity. I contributed a patch that cuts down save times by 33-50%, but if you have a couple thousand NPCs that still leaves you with a 2-3 second save time, which is pretty nuts.
I suspect that skipping the XML serialization step might be a viable solution as well. Using a compressed binary cache for something like this would probably be pretty fast.
It's probably possible to reduce the memory footprint of a GameCharacter instance, since that thing is kind of an untamed monster. I haven't looked into that too much yet.