Hello there,
I'm currently implementing an ECS model and wanted to get some feedback from the community regarding a concern.
In my ECS model, entities are simply IDs that associate components. Each component possesses an "entity ID" member such that systems can determine who each component belongs to. My components live in "component pools" that are grabbed and released as needed by an "EntityManager". The component pool ensures that all active components are living in contiguous memory. For example, let's say I have a component pool of 20 active components. If I were to release component 5, I would essentially move component 20 to the vacant slot at position 5 and then decrement the active count to 19. This ensure there are no empty spots when my systems iterate over component data.
This implementation seemed to make sense to me. However, I'm now running into the realization that my systems will likely be operating on multiple component types. For example, let's say I have a "Health System" that reads in a "collision component" and updates a "health component". My model is set up such that I can efficiently iterate through components within a single pool. But because components are organized within their own pools, there is no guarantee that components belonging to the same entity share the same position in their respective component pools. For example, component 1 of the collision component pool might belong to entity 63, but component 1 of the health component pool might belong to entity 5.
Essentially, my main concern is that my ECS model will be efficient in reading input components, but it will be inefficient in writing output components. I am not concerned with the book-keeping (each component pool contains an "entity map" such that I can easily grab a component by providing its entity ID). I am simply concerned about the efficiency of updating the output components.
Is this a valid concern?
Edit: I would like to expand on my thoughts.
When I have systems reading input components, I would consider this efficient because the system is iterating upward through contiguous memory (there is no jumping around to different addresses). When the system is updating output components however, I would consider this less efficient because the system has to write to memory that is not simply incrementing addresses (e.g. update component 20, update component 2, update component 25, etc.) However, I've started to realize that even though I'm "jumping around", the memory is still relatively close to one another. Would I need to be concerned about cache misses in this case? For some reason I've always assumed memory caching grabbed increasing address memory only.