[1.12.2-5.4.0-hotfix1] Connecting a quest to the 2nd (or higher) parent freezes the game completely for 1-2 minutes
Atricos opened this issue ยท 2 comments
Hi! I'm playing HQM version 1.12.2-5.4.0-hotfix1.
I've been creating quite a large Quest Book (currently about 700 quests through 14 Chapters), and only recently (after about 650 quests added) have I started noticing this issue: When selecting a quest to connect to a single parent, the game works fine, but when trying to connect the same quest a different parent as well, the game lags out horribly, and freezes for about 1-2 minutes.
(Note: Nothing else freezes my game this much. It's certainly not an issue with my PC.)
My guess is that there is some unoptimized algorithm running in the background to try to simplify the connections, that really doesn't like large quest chains. Everything is connected to the first couple of quests so it's a huge directed acyclic graph (DAG). Whatever the algorithm running is, please try to reduce its runtime. There are several great fast graph algorithms that you could use, especially for DAGs.
Right now it's excruciating to add new quests, because I have to constantly wait for my game to unfreeze when adding certain connections. My fear is that this wait time is just going to get worse and worse as I add more quests. It would be incredible and I'd be greatful if you could fix this.
Thank you,
Atricos
After checking out the relevant code, it looks like it has to do with how it checks for potential circular requirements before adding the requirement. During this process of iterating parent quests and child quests, it does not appear to do anything to avoid iterating the same quests multiple times. This of course becomes very inefficient with the quest structure that you're describing, where it easily ends up checking the same quests several times.
A simple solution would be to add a set to track which quests has already been checked during this process.
I found an okay-ish workaround for this. Find a quest that's an ancestor of all later quests and is only connected to 1 parent. Disconnect it to make the later portion of the quest chain much smaller. (And later, when the quests are done, add back the missing connection.) Then the described lag only lasts for 2-3 seconds, which is bearable.
Nonetheless, this is still a bug that needs to be fixed.