You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
willeastcott
changed the title
ComonenSystems add/beforeremove events issue.
ComonentSystems add/beforeremove events issue.
Dec 16, 2024
willeastcott
changed the title
ComonentSystems add/beforeremove events issue.
ComponentSystems add/beforeremove events issue.
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
andbeforeremove
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.
The text was updated successfully, but these errors were encountered: