Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions benches/benches/bevy_ecs/world/entity_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,57 @@ pub fn entity_allocator_benches(criterion: &mut Criterion) {
}

group.finish();

let mut group = criterion.benchmark_group("entity_allocator_allocate_fresh_remote");
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(4));

for entity_count in ENTITY_COUNTS {
group.bench_function(format!("{entity_count}_entities"), |bencher| {
bencher.iter_batched_ref(
|| {
let world = World::new();
world.entity_allocator().build_remote_allocator()
},
|remote| {
for _ in 0..entity_count {
let entity = remote.alloc();
black_box(entity);
}
},
BatchSize::SmallInput,
);
});
}

group.finish();

let mut group = criterion.benchmark_group("entity_allocator_allocate_reused_remote");
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(4));

for entity_count in ENTITY_COUNTS {
group.bench_function(format!("{entity_count}_entities"), |bencher| {
bencher.iter_batched_ref(
|| {
let mut world = World::new();
let mut entities =
Vec::from_iter(world.entity_allocator().alloc_many(entity_count));
entities
.drain(..)
.for_each(|e| world.entity_allocator_mut().free(e));
world.entity_allocator().build_remote_allocator()
},
|remote| {
for _ in 0..entity_count {
let entity = remote.alloc();
black_box(entity);
}
},
BatchSize::SmallInput,
);
});
}

group.finish();
}
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl EntityAllocator {

/// Builds a new remote allocator that hooks into this [`EntityAllocator`].
/// This is useful when you need to allocate entities without holding a reference to the world (like in async).
pub fn build_remote_allocator(&mut self) -> RemoteAllocator {
pub fn build_remote_allocator(&self) -> RemoteAllocator {
RemoteAllocator::new(&self.inner)
}

Expand Down