Skip to content
Open
22 changes: 0 additions & 22 deletions benches/benches/bevy_ecs/world/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,6 @@ pub fn insert_commands(criterion: &mut Criterion) {
command_queue.apply(&mut world);
});
});
group.bench_function("insert_or_spawn_batch", |bencher| {
let mut world = World::default();
let mut command_queue = CommandQueue::default();
let mut entities = Vec::new();
for _ in 0..entity_count {
entities.push(world.spawn_empty().id());
}

bencher.iter(|| {
let mut commands = Commands::new(&mut command_queue, &world);
let mut values = Vec::with_capacity(entity_count);
for entity in &entities {
values.push((*entity, (Matrix::default(), Vec3::default())));
}
#[expect(
deprecated,
reason = "This needs to be supported for now, and therefore still needs the benchmark."
)]
commands.insert_or_spawn_batch(values);
command_queue.apply(&mut world);
});
});
group.bench_function("insert_batch", |bencher| {
let mut world = World::default();
let mut command_queue = CommandQueue::default();
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async_executor = ["std", "bevy_tasks/async_executor"]
## on `no_std` targets, but provides access to certain additional features on
## supported platforms.
std = [
"dep:thread_local",
"bevy_reflect?/std",
"bevy_tasks/std",
"bevy_utils/std",
Expand Down Expand Up @@ -132,6 +133,8 @@ variadics_please = { version = "1.1", default-features = false }
tracing = { version = "0.1", default-features = false, optional = true }
log = { version = "0.4", default-features = false }
bumpalo = "3"
crossbeam-utils = { version = "0.8.11", default-features = false }
thread_local = { version = "1", optional = true }

[target.'cfg(not(all(target_has_atomic = "8", target_has_atomic = "16", target_has_atomic = "32", target_has_atomic = "64", target_has_atomic = "ptr")))'.dependencies]
concurrent-queue = { version = "2.5.0", default-features = false, features = [
Expand Down
11 changes: 3 additions & 8 deletions crates/bevy_ecs/src/entity/clone_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use alloc::boxed::Box;

use crate::component::{ComponentCloneBehavior, ComponentCloneFn};
use crate::entity::hash_map::EntityHashMap;
use crate::entity::{Entities, EntityMapper};
use crate::entity::EntityMapper;
use crate::relationship::RelationshipHookMode;
use crate::system::Commands;
use crate::{
Expand Down Expand Up @@ -82,7 +82,6 @@ pub struct ComponentCloneCtx<'a, 'b> {
target_component_written: bool,
bundle_scratch: &'a mut BundleScratch<'b>,
bundle_scratch_allocator: &'b Bump,
entities: &'a Entities,
source: Entity,
target: Entity,
component_info: &'a ComponentInfo,
Expand All @@ -108,7 +107,6 @@ impl<'a, 'b> ComponentCloneCtx<'a, 'b> {
target: Entity,
bundle_scratch_allocator: &'b Bump,
bundle_scratch: &'a mut BundleScratch<'b>,
entities: &'a Entities,
component_info: &'a ComponentInfo,
entity_cloner: &'a mut EntityCloner,
mapper: &'a mut dyn EntityMapper,
Expand All @@ -122,7 +120,6 @@ impl<'a, 'b> ComponentCloneCtx<'a, 'b> {
bundle_scratch,
target_component_written: false,
bundle_scratch_allocator,
entities,
mapper,
component_info,
entity_cloner,
Expand Down Expand Up @@ -274,9 +271,8 @@ impl<'a, 'b> ComponentCloneCtx<'a, 'b> {
self.type_registry
}

/// Queues the `entity` to be cloned by the current [`EntityCloner`]
pub fn queue_entity_clone(&mut self, entity: Entity) {
let target = self.entities.reserve_entity();
/// Queues the `entity` to be cloned by the current [`EntityCloner`] into `target`.
pub fn queue_entity_clone(&mut self, entity: Entity, target: Entity) {
self.mapper.set_mapped(entity, target);
self.entity_cloner.clone_queue.push_back(entity);
}
Expand Down Expand Up @@ -519,7 +515,6 @@ impl EntityCloner {
target,
&bundle_scratch_allocator,
&mut bundle_scratch,
world.entities(),
info,
self,
mapper,
Expand Down
12 changes: 3 additions & 9 deletions crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ impl<'m> SceneEntityMapper<'m> {

/// Creates a new [`SceneEntityMapper`], spawning a temporary base [`Entity`] in the provided [`World`]
pub fn new(map: &'m mut EntityHashMap<Entity>, world: &mut World) -> Self {
// We're going to be calling methods on `Entities` that require advance
// flushing, such as `alloc` and `free`.
world.flush_entities();
Self {
map,
// SAFETY: Entities data is kept in a valid state via `EntityMapper::world_scope`
Expand All @@ -222,8 +219,9 @@ impl<'m> SceneEntityMapper<'m> {
pub fn finish(self, world: &mut World) {
// SAFETY: Entities data is kept in a valid state via `EntityMap::world_scope`
let entities = unsafe { world.entities_mut() };
assert!(entities.free(self.dead_start).is_some());
assert!(entities.reserve_generations(self.dead_start.index(), self.generations));
assert!(entities
.free_with_reserve_generations(self.dead_start, self.generations)
.is_some());
}

/// Creates an [`SceneEntityMapper`] from a provided [`World`] and [`EntityHashMap<Entity>`], then calls the
Expand Down Expand Up @@ -301,15 +299,11 @@ mod tests {
let mut world = World::new();
// "Dirty" the `Entities`, requiring a flush afterward.
world.entities.reserve_entity();
assert!(world.entities.needs_flush());

// Create and exercise a SceneEntityMapper - should not panic because it flushes
// `Entities` first.
SceneEntityMapper::world_scope(&mut Default::default(), &mut world, |_, m| {
m.get_mapped(Entity::PLACEHOLDER);
});

// The SceneEntityMapper should leave `Entities` in a flushed state.
assert!(!world.entities.needs_flush());
}
}
Loading