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

ComponentSystems add/beforeremove events issue. #7202

Open
Maksims opened this issue Dec 16, 2024 · 0 comments
Open

ComponentSystems add/beforeremove events issue. #7202

Maksims opened this issue Dec 16, 2024 · 0 comments
Labels
performance Relating to load times or frame rate

Comments

@Maksims
Copy link
Collaborator

Maksims commented Dec 16, 2024

The problem:

ComponentSystem has a very large subscriber lists for add/beforeremove events with mostly irrelevant subscribers. Leading to higher cost of adding/removing components.

Details:

Many ComponentSystems do provide a way to inform when component has been added or is about to be removed, and it provides a single event name for that: add and beforeremove on ComponentSystem. As an argument, it provide an Entity and a Component.
Then every single system's Component, will subscribe to such event, only to check then if then entity is the same as this Component's entity.

This leads to a single callbacks list that has a very large number of subscribers, where only a few of hundreds/thousands of subscribers are relevant.

So then on every added/remove Component, this will lead to wasted time going through irrelevant callbacks and calling them only to return early.
This has also an extra overhead due to high cost of removing event handles from massive arrays. With the introduction of a more efficient EventHandle.off, this can be improved, but this does not solve the original problem.

The solution:

If a subscriber needs to know when it is about to be removed or added, it then should be subscribed and handled on that subscriber (Component) itself. This will avoid large callback lists on a ComponentSystem, and will be way more efficient when adding/removing entities with components.

@willeastcott willeastcott changed the title ComonenSystems add/beforeremove events issue. ComonentSystems add/beforeremove events issue. Dec 16, 2024
@willeastcott willeastcott changed the title ComonentSystems add/beforeremove events issue. ComponentSystems add/beforeremove events issue. Dec 16, 2024
@willeastcott willeastcott added the performance Relating to load times or frame rate label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Relating to load times or frame rate
Projects
None yet
Development

No branches or pull requests

2 participants