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
SUMMARY: Performance "Build bitmap cache of field locations."
Purpose of change
Continuing with profile guided optimization, simply enumerating submaps with active fields (even when there are no fields!) was taking ~7.5% of execution time while waiting on an empty map.
Describe the solution
Created a bitmap of submaps containing an active field in addition to the submap field_count field. Used this bitmap to determine whether a submap needs field processing, dropping execution time in my test to 1.1%.
Describe alternatives you've considered
Could have been a sparse tripoint set instead of a bitmap, but we frequently expect a lot of fields on the map, and if the map grows larger than the bitmap, the map loses hard, so I feel a bitmap is a much more performant option here.
The code that re-syncs submaps with the cache after a submap with fields is processed is pretty bad, it visits each adjacent submap and forcibly syncs the value of field_count to the cache, this works and considering we just did a probably very expensive field update, it's probably inconsequential, but I'd love a better option.
Also the code that updates the new cache is pretty gross, I'd appreciate suggestions for cleaning it up.
Additional context
Take a fairly close look at running around and doing strange things while fields are updating, I shook out a bunch of bugs this had and I can no longer break it, but there might be something I missed.