Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid iterating through all the entities #24

Closed
kvark opened this issue Apr 11, 2016 · 3 comments
Closed

Avoid iterating through all the entities #24

kvark opened this issue Apr 11, 2016 · 3 comments

Comments

@kvark
Copy link
Member

kvark commented Apr 11, 2016

In a lot of cases, the fraction of entities that do need to be processed is just a fraction of all entities. We lose a lot of time by checking all the entity components to exist. This information could be cached and re-used.

We could get a small speedup (in general) by early exiting if one of the components is not found. Similarly, we could advice users to convert problematic runXwYr calls to custom run calls and early-exit manually.

As a last resort, one could separate the ECS into two, so that the component coverage is denser in each (like, don't mix particle entities with UI entities with game entities, etc).

One way to properly address this is to use tables. @csherratt reported the speedup from ~260us to ~50us by building on top of our Storage interface.

Another way would be to have Aspect as a special construct that tracks which entities have a required set of components, proposed by @OvermindDL1.

@OvermindDL1
Copy link

For note, my 'Aspects' only defined where they looked in the Aspect cache. If someone in my system creates an Aspect.match<HealthComponent, DamageComponent>, Aspect.optional>() it just returns a single pointer into the aspect cache, the cache itself was a recursive map of maps with keys of component atoms/ids and values of the matched ones with sub-matches with other components requested. You 'should' create any Aspects as early as possible as the first time a certain matchspec is defined it will iterate over all entities to see which go in, but from then on that cache is kept up to date among all aspects that match on the same matchspec.

The old system I based the style off of (Artemis, don't bother looking at it, this was the only good part about its system) used each Aspect as its own cache and they just registered event handlers to hear when components were added/removed, which caused more indirect function calls compared to mine.

Plus duplicated data

@OvermindDL1
Copy link

I just looked in the Tables library a bit more (I still have so much more to learn about rust syntax, I have the ideas, but just the syntax... >.>), looks like it would work very well as a backing store while also using Aspects, they are not competing concepts but rather seem to attack two different issues in their own efficient ways. Perhaps they should both be integrated.

@kvark
Copy link
Member Author

kvark commented Apr 15, 2016

Fixed by #29

@kvark kvark closed this as completed Apr 15, 2016
xMAC94x pushed a commit to xMAC94x/specs that referenced this issue Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants