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.
Summary
None
Purpose of change
While testing NPCs in #54307 I noticed the game was running pretty slow:
Describe the solution
It looks like
overmapbuffer::find_closest
is a little too expensive to be running every turn. I decided to cache this value, and refresh it when the NPC moves between OMTs and on game load. In-game, the turn speed went from ~5 seconds/turn to ~2 turns/second (x10 improvement). This is compiled with all debug flags andNOOPT=1
.perf
shows a pretty significant improvement:Describe alternatives you've considered
I guess
npc::long_term_goal_action
could be delayed for X turns before being called again (not sure about the repercussions of that).Testing
Stepping through
npc::set_omt_destination
, the goal is cached for each need. Moving OMTs forces the goal to be recalculated (which is noticeable in-game, being a bit slower). The location candidates for each need don't change anyway, so there's no benefit from running this check every time.Additional context
This is mostly a problem for NPCs without a set destination (which is most NPCs, apparently).