Consider compacting ComputedVisibility via bitsets #4661
Labels
A-Rendering
Drawing game state to the screen
C-Feature
A new feature, making something new possible
C-Performance
A change motivated by improving speed, memory usage or compile times
What problem does this solve or what need does it fill?
ComputedVisibility
is effectively a newtype around abool
that is recomputed every frame. This representation requires a one-bytebool
value and a 8-byte change tick in ECS space. This works well right now, but 7 of the 8 bits in the bool effectively go unused. A more compact representation can lead to better cache locality.What solution would you like?
Remove
ComputedVisibility
as a component, and replace it with aComputedVisibilities
resource which wraps aFixedBitset
. This removes the change detection overhead and uses only one bit per entity. This compact representation uses up to 72x less memory, is much more cache friendly, and reduces the fragmented iteration costs of visibility systems. The bitset would be keyed only by Entity ID, ignoring the generation to minimize memory usage. AsEntities
attempts to minimize holes in entity coverage, this bitset would be relatively dense. The API for such a resource could be roughly outlined as follows:As computed visibility typically follows the pattern of a once-per-frame update system, followed by the all of the extraction systems reading it in parallel, a singular resource can be used without needing additional locking.
What alternative(s) have you considered?
#3796 changes Visibility and ComputedVisibility into ZST marker components. This removes the
bool
entirely, but introduces further archetype fragmentation, and makes it heavier to mark certain entities as visible or not. This alternative isn't 100% incompatible with this design, as this issue only proposes changingComputedVisibility
, though using a bitset basedVisibilities
resource could reduce the time spent copying initial visibility state.The text was updated successfully, but these errors were encountered: