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.
Objective
Solution
ViewVisibilitycomponent, which already hides its internal structure as a private implementation detail. I initially added a new component to track the previous visibility, a more direct translation from the hash set to using components, but using bitflags is even faster because I can use half the memory with a singleu8instead of twobools. This also removes the need for having required components as it is just an internal state detail of the visibility component.Testing
EntityHashSetandEntityHashMap. Worth investigating that further, as I've seen that bimodal behavior before, and blamed it on pcores vs ecores, but I verified that is not happening.A high level comparison of the change in CPU time by looking at just PostUpdate between old(red) and new(yellow)
Before
After
caldera hotel - all entities in view
For this test, I didn't touch the camera, so all entities were in view at all times.
check_visibilityreset_view_visibilitymark_newly_hidden_entities_invisibleThis is 23us slower than the "fast mode" of the existing code on main, but 180-250us faster than the weird "slow mode" on main. The new code is significantly more stable, and does not exhibit the super slow mode.
caldera hotel - no entities in view
For this test, I immediately rotated the camera so the hotel was not in view.
check_visibilityThis is largely a wash. The old code is 2us faster, but this is likely in the realm of noise.
reset_view_visibilityThis is a big win. The main peak is about 30us faster now, but the major win is the worst case, which is nearly 500us faster.
mark_newly_hidden_entities_invisibleSame story as the other caldera comparison with everything in view, this is a bit slower than the fast mode, but way faster than the slow mode on main.