Skip to content

Add Commands::insert_batch #8384

@wzjsun

Description

@wzjsun

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

Creating multiple entities of the same prototype in the system is a very common requirement, and existing Commands::spawn_batch can create entities in bulk and achieve efficient insertion, but this interface cannot return the Enity I have already created. If I need these entities, I have adopted the following method:

let mut entity_ list = Vec::new();

let mut bundle_ list= Vec::new();
for _ in 0..100 {
  let entity = commands.spawn_ empty();
  entity_ list.push(entity);
  bundle_ list.push((entity, Bundle))
}
commands.insert_ or_ spawn_ batch(bundle_list.into_iter());

But I encountered a very serious performance issue, some entities may need to check if they are in pending , and this inspection will go through an iterative process, and the code snippet is:

else if let Some(index) = self.pending.iter().position(|item| *item == entity.index) {
  self.pending.swap_ remove(index);
  let new_ free_ cursor = self.pending.len() as IdCursor;
  *self.free_ cursor.get_ mut() = new_ free_ cursor;
  self.len += 1;
  AllocAtWithoutReplacement::DidNotExist
}

This approach is slower than inserting one at a time

What solution would you like?

Add Commands::insert_batch, but do not check if each entity is in pending, panic If the entity does not exist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-PerformanceA change motivated by improving speed, memory usage or compile times

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions