Skip to content

Add a benchmark for spawn_batch#22439

Merged
mockersf merged 4 commits intobevyengine:mainfrom
ChristopherBiscardi:spawn_batch_bench
Jan 11, 2026
Merged

Add a benchmark for spawn_batch#22439
mockersf merged 4 commits intobevyengine:mainfrom
ChristopherBiscardi:spawn_batch_bench

Conversation

@ChristopherBiscardi
Copy link
Contributor

@ChristopherBiscardi ChristopherBiscardi commented Jan 8, 2026

Objective

There was no benchmark for spawn_batch that I could find.

Solution

Add one.

The intent here is to make it comparable to the spawn_world benchmark, so I kept the construction of the vec of component data in the benchmark.

The benchmark uses the iter to use batch sizes from 1 to 10,000, which also explains the addition of the 1000 level.

Testing

cargo bench -p benches -- world_spawn

Showcase

spawn_world/1_entities  time:   [47.966 ns 48.690 ns 49.464 ns]
                        change: [+2.1054% +4.5065% +6.9285%] (p = 0.00 < 0.05)
                        Performance has regressed.
spawn_world/100_entities
                        time:   [4.8244 µs 4.8961 µs 4.9715 µs]
                        change: [−2.9086% −0.5143% +1.9117%] (p = 0.68 > 0.05)
                        No change in performance detected.
spawn_world/10000_entities
                        time:   [473.97 µs 481.61 µs 490.26 µs]
                        change: [−0.5065% +1.7613% +4.2000%] (p = 0.14 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

spawn_world_batch/1_entities
                        time:   [663.32 µs 669.68 µs 677.00 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
spawn_world_batch/100_entities
                        time:   [379.35 µs 386.57 µs 394.14 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) low mild
spawn_world_batch/1000_entities
                        time:   [354.48 µs 361.06 µs 367.44 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) low mild
spawn_world_batch/10000_entities
                        time:   [382.73 µs 392.63 µs 402.06 µs]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

@ChristopherBiscardi ChristopherBiscardi added S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Benchmarks Stress tests and benchmarks used to measure how fast things are A-ECS Entities, components, systems, and events labels Jan 8, 2026
@hymm
Copy link
Contributor

hymm commented Jan 8, 2026

The intent here is to make it comparable to the spawn_world benchmark, so I kept the construction of the vec of component data in the benchmark.

I'm not sure I follow this logic. We could iter map over a range to avoid the allocation of the vec in this case or use an array on the stack. Are most of the real world cases going to allocate?

Does 100,000 show a bigger difference between the two benches?

@alice-i-cecile alice-i-cecile added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Jan 9, 2026
@ChristopherBiscardi
Copy link
Contributor Author

We could iter map over a range to avoid the allocation of the vec

agreed, I will push that change. The below content includes it:

Does 100,000 show a bigger difference between the two benches?

This is 100,000 entities individually for spawn_world and 100,000 entities batched into 1/100/1000/10000 batches using an iterator for the batching:

world.spawn_batch(
    (0..batch_count)
        .into_iter()
        .map(|_| (A(Mat4::default()), B(Vec4::default()))),
);
spawn_world/100000_entities
    time:   [4.4663 ms 4.4975 ms 4.5356 ms]

spawn_world_batch/1_entities
    time:   [4.9562 ms 4.9847 ms 5.0201 ms]
spawn_world_batch/100_entities
    time:   [3.6878 ms 3.7176 ms 3.7510 ms]
spawn_world_batch/1000_entities
    time:   [3.8739 ms 3.8968 ms 3.9229 ms]
spawn_world_batch/10000_entities
    time:   [3.5281 ms 3.5536 ms 3.5854 ms]

vs 10,000

spawn_world/10000_entities
    time:   [467.68 µs 475.37 µs 484.19 µs]

spawn_world_batch/1_entities
    time:   [504.04 µs 510.41 µs 517.83 µs]
spawn_world_batch/100_entities
    time:   [355.42 µs 362.17 µs 369.38 µs]
spawn_world_batch/1000_entities
    time:   [340.51 µs 348.52 µs 356.60 µs]
spawn_world_batch/10000_entities
    time:   [366.15 µs 374.17 µs 381.91 µs]

@IceSentry IceSentry added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 11, 2026
Co-authored-by: François Mockers <francois.mockers@vleue.com>
@mockersf mockersf added this pull request to the merge queue Jan 11, 2026
Merged via the queue into bevyengine:main with commit 238e1ea Jan 11, 2026
38 checks passed
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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants