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 ✨ |
BD103
left a comment
There was a problem hiding this comment.
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.
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_batchexists, but a version for just inserting doesn'tSolution
Add
insert_batch, along with the most commoninsertvariations:World::insert_batchWorld::insert_batch_if_newWorld::try_insert_batchWorld::try_insert_batch_if_newCommands::insert_batchCommands::insert_batch_if_newCommands::try_insert_batchCommands::try_insert_batch_if_newTesting
Added tests, and added a benchmark for
insert_batch.Performance is slightly better than
insert_or_spawn_batchwhen only inserting:old benchmark
This was before reworking it to remove the
UnsafeWorldCell:Showcase
Usage is the same as
insert_or_spawn_batch: