Theoretical improvements to workerAutomation performance#14617
Open
Ambeco wants to merge 3 commits intoyairm210:masterfrom
Open
Theoretical improvements to workerAutomation performance#14617Ambeco wants to merge 3 commits intoyairm210:masterfrom
Ambeco wants to merge 3 commits intoyairm210:masterfrom
Conversation
added 3 commits
February 27, 2026 12:06
…oving features. Before, when #getImprovementRanking was calculating the score of removing something, it would then calculate all possible improvements on top of that. So when #chooseImprovement was scoring TradingPost, Camp, Fort, and RemoveJungle, then while scoring removeJungle it would recalculate TradingPost, Camp, and Fort. Now, #chooseImprovement passes a list of improvements it knows of to getImprovementRanking, so that when scoring removeJungle, it no longer recalculates TradingPost, Camp, and Fort, though still calculates any new improvements. Signed-off-by: MPD <mooing_psycho_duck@hotmail.com>
…ork to do tileHasWorkToDo is expensive. It used to call tileHasWorkToDo on all cities, and then sort. Now it sorts, and then calls tileHasWorkToDo until one returns true. Signed-off-by: MPD <mooing_psycho_duck@hotmail.com>
chooseImprovement stores priority in RankedImprovements, and does the rest of the calculations with those. To make this work I also had to ensure that tile.improvement was in the list, even if this unit can't build it, but when the unit CAN build it, the priority is only calculated once and shared. This also forces all improvements to be in ruleSet.tileImprovements, but the only way that could have failed was if currentTile.improvementInProgress or currentTile.improvement were not in that map, which can only occur for loading an invalid save anyway, so that should be fine. Signed-off-by: MPD <mooing_psycho_duck@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getImprovementRanking used to double-calculate improvements after removing features.
Before, when #getImprovementRanking was calculating the score of removing something, it would then calculate all possible improvements on top of that. So when #chooseImprovement was scoring TradingPost, Camp, Fort, and RemoveJungle, then while scoring removeJungle it would recalculate TradingPost, Camp, and Fort.
Now, #chooseImprovement passes a list of improvements it knows of to getImprovementRanking, so that when scoring removeJungle, it no longer recalculates TradingPost, Camp, and Fort, though still calculates any new improvements.
tryHeadTowardsUndevelopedCity stops when it finds a close city with work to do
tileHasWorkToDo is expensive. It used to call tileHasWorkToDo on all cities, and then sort. Now it sorts, and then calls tileHasWorkToDo until one returns true.
chooseImprovement now only ranks improvements once and caches results
chooseImprovement stores priority in RankedImprovements, and does the rest of the calculations with those.
To make this work I also had to ensure that tile.improvement was in the list, even if this unit can't build it, but when the unit CAN build it, the priority is only calculated once and shared.
This also forces all improvements to be in ruleSet.tileImprovements, but the only way that could have failed was if currentTile.improvementInProgress or currentTile.improvement were not in that map, which can only occur for loading an invalid save anyway, so that should be fine.
Performance
Annoyingly, when I (badly) measured the performance, it was statistically insignificant. :(