playcanvas / playcanvas/engine
ComponentSystems add/beforeremove events issue.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 16.8k
- Forks
- 2k
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 222
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ComponentSystem's add and beforeremove event subscriptions, then inspect how components currently receive and filter those events. Done means subscribers handle relevant add/remove notifications on the component itself, avoiding large ComponentSystem callback lists while preserving the existing notification behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100