bevy/benches/benches/bevy_ecs/iteration/heavy_compute.rs
Chris Russell 571b3ba475
Remove ArchetypeComponentId and archetype_component_access (#19143)
# Objective

Remove `ArchetypeComponentId` and `archetype_component_access`.
Following #16885, they are no longer used by the engine, so we can stop
spending time calculating them or space storing them.

## Solution

Remove `ArchetypeComponentId` and everything that touches it.  

The `System::update_archetype_component_access` method no longer needs
to update `archetype_component_access`. We do still need to update query
caches, but we no longer need to do so *before* running the system. We'd
have to touch every caller anyway if we gave the method a better name,
so just remove `System::update_archetype_component_access` and
`SystemParam::new_archetype` entirely, and update the query cache in
`Query::get_param`.

The `Single` and `Populated` params also need their query caches updated
in `SystemParam::validate_param`, so change `validate_param` to take
`&mut Self::State` instead of `&Self::State`.
2025-05-27 19:04:32 +00:00

53 lines
1.5 KiB
Rust

use bevy_ecs::prelude::*;
use bevy_tasks::{ComputeTaskPool, TaskPool};
use criterion::Criterion;
use glam::*;
pub fn heavy_compute(c: &mut Criterion) {
#[derive(Component, Copy, Clone)]
struct Position(Vec3);
#[derive(Component, Copy, Clone)]
struct Rotation(Vec3);
#[derive(Component, Copy, Clone)]
struct Velocity(Vec3);
#[derive(Component, Copy, Clone)]
struct Transform(Mat4);
let mut group = c.benchmark_group("heavy_compute");
group.warm_up_time(core::time::Duration::from_millis(500));
group.measurement_time(core::time::Duration::from_secs(4));
group.bench_function("base", |b| {
ComputeTaskPool::get_or_init(TaskPool::default);
let mut world = World::default();
world.spawn_batch((0..1000).map(|_| {
(
Transform(Mat4::from_axis_angle(Vec3::X, 1.2)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
)
}));
fn sys(mut query: Query<(&mut Position, &mut Transform)>) {
query.par_iter_mut().for_each(|(mut pos, mut mat)| {
for _ in 0..100 {
mat.0 = mat.0.inverse();
}
pos.0 = mat.0.transform_vector3(pos.0);
});
}
let mut system = IntoSystem::into_system(sys);
system.initialize(&mut world);
b.iter(move || system.run((), &mut world));
});
group.finish();
}