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
Improve performance of map::generate. This was triggered by #75166, but I don't consider this to solve that report.
Describe the solution
Replace repeated calls to MAPBUFFER.lookup_submap to see if it exists with a single check to a new submap_exists operation and then store the results in a vector that's then used for the subsequent existence checks.
Describe alternatives you've considered
Edit: Tried it and didn't it to work properly (light isn't set properly), but nevertheless, a performance test showed no significant performance change compared to the master code, presumably because juggling vectors to store state gobbles up the gains made elsewhere. Abandoning this as a failure.
Testing
Bumbling running of the VS profiler before and after modifying the code.
The results seemed to indicate a drop of the overall CPU consumption of map::generate from 15.17% of the CPU budget before the change to 5.28% after. An intermediate run after the changes to generate but before the addition to mapbuffer gave a result that was somewhere in between these two values.
Running the game by teleporting straight to the east to the edge of the revealed map (guaranteeing it hasn't been generated), starting recording and then keep moving east by keeping the movement key pressed until safe mode reported a monster showed it still hesitates at times (and I think it's probably on OMT boundaries). I can't say if the effect is smaller. I'd probably need a slower computer for that.
Additional context
It's quite possible the variability in results from different runs is high enough to make single measurements rather pointless.