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

Add Commands::insert_batch and remove_batch for faster component modification #2693

Open
alice-i-cecile opened this issue Aug 19, 2021 · 2 comments
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

Inserting and removing components one at a time is slow.

What solution would you like?

Add Commands::insert_batch and remove_batch to modify components en-masse in a more efficient way.

What alternative(s) have you considered?

Work towards #1613 for component modification and exclusively use that in performance-critical code.

We could use insert_or_spawn_batch for the insertion case, but that does not fail in the desired ways at all.

Additional context

Follows up on the work from #2673, which added insert_or_spawn_batch. Ideally we can use the same strategy for this work, and perform similar benchmarks.

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! labels Aug 19, 2021
@alice-i-cecile
Copy link
Member Author

We should also include despawn_batch as part of this PR (or in an immediate follow-up PR) for performance reasons.

@cart
Copy link
Member

cart commented Sep 17, 2021

I don't think despawn_batch would meaningfully benefit from batching. Removing arbitrary entities is random-access (even if you somehow managed to sort by archetype, the internal swap remove would still be random). And the recent Commands rework ensures that we reuse allocations. In fact, despawn(a), despawn(b), ... would be faster than despawn_batch(![a, b, ...]) because we could reuse the command allocations across frames, whereas the Vec would need to be allocated each frame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

2 participants