How Views and Groups work in Zig ECS
masterZig ECS provides two primary ways to query and iterate over entities: Views and Groups.
- Views: These store no data within the ECS itself. They iterate over entities on the fly without a cache. They are the recommended starting point for most queries due to their simplicity and low overhead. You can always upgrade to a Group if performance becomes a bottleneck.
- Groups: These maintain a cached list of all entities that match a specific query. This cache speeds up iteration because the ECS already knows exactly which entities match, but it incurs a cost in memory and CPU cycles to keep the cache synchronized as entities are added or removed.
- OwningGroups: A specialized type of Group where the component storage containers for the specified components are constantly reordered to ensure there are no gaps in the data. This allows for extremely fast, direct iteration. While memory usage is low, it is more CPU-intensive when there is high 'churn' (frequent adding or removing of the owned components).