-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add insert_batch
and variations
#15702
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 insert_batch
and variations
#15702
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good! I have some nits and notes, but nothing blocking.
Do note that I'm unfamiliar with ECS internals, so I'd like someone with more experience to check over those parts of the PR.
I'm far from an expert, but I'm not sure if it's doable in the same way. The I'd imagine that we would want to include all the other The best I've got is passing in an enum or something, but that's obvious so there's probably a reason that's not how it works already (too fragile, ugly, etc). Notably, a lower level Edit from days later: I think I missed the main part of the question, which is just adding |
Maybe this could be its own PR, but the original PR has some unhealthy usage of Here's the context: The problem was that I needed access to both the
I originally used an So, eventually I figured out a (hopefully) proper solution: deal with the first entity in the iterator on its own, so you can make a |
Should I remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding correctly that this could potentially allocate twice if we're moving multiple entities into the same archetype? And also make multiple moves of entities in the old table as we're moving entities out of it? Probably some room for future optimizations if so.
edit: I guess it would depend on how it's being used if it's worth it or not.
I think keeping multiple inserters allocated would run into borrow problems, since they all need a &mut World |
I'm not sure I follow. We do have a
It would definitely require something different from BundleInserter and probably a bunch of unsafe. |
Just wasn't sure if it was possible, I'll leave them alone then |
Objective
insert_or_spawn_batch
exists, but a version for just inserting doesn'tSolution
Add
insert_batch
, along with the most commoninsert
variations:World::insert_batch
World::insert_batch_if_new
World::try_insert_batch
World::try_insert_batch_if_new
Commands::insert_batch
Commands::insert_batch_if_new
Commands::try_insert_batch
Commands::try_insert_batch_if_new
Testing
Added tests, and added a benchmark for
insert_batch
.Performance is slightly better than
insert_or_spawn_batch
when only inserting:old benchmark
This was before reworking it to remove the
UnsafeWorldCell
:Showcase
Usage is the same as
insert_or_spawn_batch
: