-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use batch spawn in benchmarks #11611
Merged
Merged
Conversation
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
BD103
changed the title
chore(bench): batch spawn iter_simple entities
Use batch spawn in benchmarks
Jan 29, 2024
alice-i-cecile
approved these changes
Jan 29, 2024
alice-i-cecile
added
A-ECS
Entities, components, systems, and events
C-Benchmarks
Stress tests and benchmarks used to measure how fast things are
labels
Jan 29, 2024
What is the improvement in the benches from this? |
it shouldn't change the benches has it's in the setup, but would be nice to confirm |
I tried benchmarking Before:
After:
Code used to test this// Before
group.bench_function("bd103", |b| {
use bevy_ecs::prelude::*;
use glam::*;
#[derive(Component, Copy, Clone)]
struct Transform(Mat4);
#[derive(Component, Copy, Clone)]
struct Position(Vec3);
#[derive(Component, Copy, Clone)]
struct Rotation(Vec3);
#[derive(Component, Copy, Clone)]
struct Velocity(Vec3);
b.iter(|| {
let mut world = World::new();
for _ in 0..10_000 {
world.spawn((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
));
}
})
});
// After
group.bench_function("bd103", |b| {
use bevy_ecs::prelude::*;
use glam::*;
#[derive(Component, Copy, Clone)]
struct Transform(Mat4);
#[derive(Component, Copy, Clone)]
struct Position(Vec3);
#[derive(Component, Copy, Clone)]
struct Rotation(Vec3);
#[derive(Component, Copy, Clone)]
struct Velocity(Vec3);
b.iter(|| {
let mut world = World::new();
world.spawn_batch(
std::iter::repeat((
Transform(Mat4::from_scale(Vec3::ONE)),
Position(Vec3::X),
Rotation(Vec3::X),
Velocity(Vec3::X),
))
.take(10_000)
);
})
}); |
Nice faster and less noisy |
hymm
approved these changes
Feb 1, 2024
hymm
added
the
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
label
Feb 1, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 1, 2024
# Objective - The benchmarks for `bevy_ecs`' `iter_simple` group use `for` loops instead of `World::spawn_batch`. - There's a TODO comment that says to batch spawn them. ## Solution - Replace the `for` loops with `World::spawn_batch`.
tjamaan
pushed a commit
to tjamaan/bevy
that referenced
this pull request
Feb 6, 2024
# Objective - The benchmarks for `bevy_ecs`' `iter_simple` group use `for` loops instead of `World::spawn_batch`. - There's a TODO comment that says to batch spawn them. ## Solution - Replace the `for` loops with `World::spawn_batch`.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-ECS
Entities, components, systems, and events
C-Benchmarks
Stress tests and benchmarks used to measure how fast things are
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
bevy_ecs
'iter_simple
group usefor
loops instead ofWorld::spawn_batch
.Solution
for
loops withWorld::spawn_batch
.