forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
System
responsible for updating its own archetypes (bevyengine…
…#4115) # Objective - Make it possible to use `System`s outside of the scheduler/executor without having to define logic to track new archetypes and call `System::add_archetype()` for each. ## Solution - Replace `System::add_archetype(&Archetype)` with `System::update_archetypes(&World)`, making systems responsible for tracking their own most recent archetype generation the way that `SystemState` already does. This has minimal (or simplifying) effect on most of the code with the exception of `FunctionSystem`, which must now track the latest `ArchetypeGeneration` it saw instead of relying on the executor to do it. Co-authored-by: Carter Anderson <[email protected]>
- Loading branch information
Showing
15 changed files
with
264 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use bevy_ecs::{ | ||
component::Component, | ||
schedule::{Stage, SystemStage}, | ||
world::World, | ||
}; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
|
||
criterion_group!(benches, no_archetypes, added_archetypes); | ||
criterion_main!(benches); | ||
|
||
#[derive(Component)] | ||
struct A<const N: u16>(f32); | ||
|
||
fn setup(system_count: usize) -> (World, SystemStage) { | ||
let mut world = World::new(); | ||
fn empty() {} | ||
let mut stage = SystemStage::parallel(); | ||
for _ in 0..system_count { | ||
stage.add_system(empty); | ||
} | ||
stage.run(&mut world); | ||
(world, stage) | ||
} | ||
|
||
/// create `count` entities with distinct archetypes | ||
fn add_archetypes(world: &mut World, count: u16) { | ||
for i in 0..count { | ||
let mut e = world.spawn(); | ||
if i & 1 << 0 != 0 { | ||
e.insert(A::<0>(1.0)); | ||
} | ||
if i & 1 << 1 != 0 { | ||
e.insert(A::<1>(1.0)); | ||
} | ||
if i & 1 << 2 != 0 { | ||
e.insert(A::<2>(1.0)); | ||
} | ||
if i & 1 << 3 != 0 { | ||
e.insert(A::<3>(1.0)); | ||
} | ||
if i & 1 << 4 != 0 { | ||
e.insert(A::<4>(1.0)); | ||
} | ||
if i & 1 << 5 != 0 { | ||
e.insert(A::<5>(1.0)); | ||
} | ||
if i & 1 << 6 != 0 { | ||
e.insert(A::<6>(1.0)); | ||
} | ||
if i & 1 << 7 != 0 { | ||
e.insert(A::<7>(1.0)); | ||
} | ||
if i & 1 << 8 != 0 { | ||
e.insert(A::<8>(1.0)); | ||
} | ||
if i & 1 << 9 != 0 { | ||
e.insert(A::<9>(1.0)); | ||
} | ||
if i & 1 << 10 != 0 { | ||
e.insert(A::<10>(1.0)); | ||
} | ||
if i & 1 << 11 != 0 { | ||
e.insert(A::<11>(1.0)); | ||
} | ||
if i & 1 << 12 != 0 { | ||
e.insert(A::<12>(1.0)); | ||
} | ||
if i & 1 << 13 != 0 { | ||
e.insert(A::<13>(1.0)); | ||
} | ||
if i & 1 << 14 != 0 { | ||
e.insert(A::<14>(1.0)); | ||
} | ||
if i & 1 << 15 != 0 { | ||
e.insert(A::<15>(1.0)); | ||
} | ||
} | ||
} | ||
|
||
fn no_archetypes(criterion: &mut Criterion) { | ||
let mut group = criterion.benchmark_group("no_archetypes"); | ||
for i in 0..=5 { | ||
let system_count = i * 20; | ||
let (mut world, mut stage) = setup(system_count); | ||
group.bench_with_input( | ||
BenchmarkId::new("system_count", system_count), | ||
&system_count, | ||
|bencher, &_system_count| { | ||
bencher.iter(|| { | ||
stage.run(&mut world); | ||
}); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
fn added_archetypes(criterion: &mut Criterion) { | ||
const SYSTEM_COUNT: usize = 100; | ||
let mut group = criterion.benchmark_group("added_archetypes"); | ||
for archetype_count in [100, 200, 500, 1000, 2000, 5000, 10000] { | ||
group.bench_with_input( | ||
BenchmarkId::new("archetype_count", archetype_count), | ||
&archetype_count, | ||
|bencher, &archetype_count| { | ||
bencher.iter_batched( | ||
|| { | ||
let (mut world, stage) = setup(SYSTEM_COUNT); | ||
add_archetypes(&mut world, archetype_count); | ||
(world, stage) | ||
}, | ||
|(mut world, mut stage)| { | ||
stage.run(&mut world); | ||
}, | ||
criterion::BatchSize::LargeInput, | ||
) | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.