Skip to content

Fix child_builder and Parent / Children management #1076

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

Closed
wants to merge 13 commits into from
Closed
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
7 changes: 7 additions & 0 deletions crates/bevy_transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ bevy_utils = { path = "../bevy_utils", version = "0.3.0" }

# other
smallvec = { version = "1.4", features = ["serde"] }

[dev-dependencies]
bencher = "0.1.5"

[[bench]]
name = "push_children"
harness = false
46 changes: 0 additions & 46 deletions crates/bevy_transform/benches/local_to_world.rs

This file was deleted.

64 changes: 64 additions & 0 deletions crates/bevy_transform/benches/push_children.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use bencher::*;

use bevy_ecs::{Command, Commands, Component, DynamicBundle, Entity, Resources, World};
use bevy_transform::prelude::*;

fn push_children_1_parent_to_many_children(bench: &mut Bencher) {
let mut world = World::default();
let mut commands = Commands::default();
let mut resources = Resources::default();

let entities = world
.spawn_batch((0..1000).map(|i| (i,)))
.collect::<Vec<_>>();

bench.iter(|| {
commands.push_children(entities[999], &entities[0..998]);
commands.apply(&mut world, &mut resources);
})
}

fn push_children_many_parents_with_1_child(bench: &mut Bencher) {
let mut world = World::default();
let mut commands = Commands::default();
let mut resources = Resources::default();

let entities = world
.spawn_batch((0..2000).map(|i| (i,)))
.collect::<Vec<_>>();

bench.iter(|| {
for parent in 0..1000 {
let child = parent + 1000;
commands.push_children(entities[parent], &entities[child..=child]);
}
commands.apply(&mut world, &mut resources);
})
}

fn push_children_many_parents_with_8_children(bench: &mut Bencher) {
let mut world = World::default();
let mut commands = Commands::default();
let mut resources = Resources::default();

let entities = world
.spawn_batch((0..9000).map(|i| (i,)))
.collect::<Vec<_>>();

bench.iter(|| {
for parent in 0..1000 {
let child_a = parent * 8 + 1000;
let child_z = (parent + 1) * 8 + 1000;
commands.push_children(entities[parent], &entities[child_a..child_z]);
}
commands.apply(&mut world, &mut resources);
})
}

benchmark_group!(
benches,
push_children_1_parent_to_many_children,
push_children_many_parents_with_1_child,
push_children_many_parents_with_8_children
);
benchmark_main!(benches);
2 changes: 1 addition & 1 deletion crates/bevy_transform/src/components/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bevy_reflect::{Reflect, ReflectComponent, ReflectMapEntities};
use smallvec::SmallVec;
use std::ops::Deref;

#[derive(Default, Clone, Debug, Reflect)]
#[derive(Default, Clone, Debug, Reflect, Eq, PartialEq)]
#[reflect(Component, MapEntities)]
pub struct Children(pub(crate) SmallVec<[Entity; 8]>);

Expand Down
Loading