Skip to content

Add bevy_feathers spawning benchmark#24057

Open
greeble-dev wants to merge 7 commits into
bevyengine:mainfrom
greeble-dev:bench-feathers
Open

Add bevy_feathers spawning benchmark#24057
greeble-dev wants to merge 7 commits into
bevyengine:mainfrom
greeble-dev:bench-feathers

Conversation

@greeble-dev
Copy link
Copy Markdown
Contributor

@greeble-dev greeble-dev commented May 1, 2026

Objective

Add a spawning benchmark for bevy_feathers. This can also serve as a general benchmark for BSN scene spawning.

I found a need for this while testing some BSN changes - I wanted to benchmark a large and complex scene, but the existing BSN benchmarks are all pretty small and simple.

Solution

I copy and pasted feathers_gallery into a benchmark. That's a bit crude, but gets the job done for now.

As requested by #24044, the benchmark is behind an experimental_bevy_feathers feature.

The PR is a bit behind the current state of feathers_gallery - it's functional but missing some style updates and minor fixes. I'll update if the PR looks likely to land.

Testing

cargo bench -p benches --bench feathers --features "experimental_bevy_feathers"

Results

In case anyone's curious, here's the results for my desktop Zen 4:

benchmark time
construct_and_drop 4.8us Constructing and dropping the scene
drop 0.94us Dropping the scene
spawn_cold 1230us Spawning into an empty world
spawn_warm 562us Spawning into a world with one copy of the scene already spawned

…ded for benchmarking. This allowed removing the `tracing` dependency.
- Renamed `construct` to `construct_and_drop`.
- Added `drop`.
- Changed `construct_and_spawn` to `spawn_warm` and `spawn_cold`.
    - Neither reuse the same app, as that seems like it would distort things with the ECS growing over time.
    - `spawn_cold` spawns into a fresh world, so it measures ECS table and archetype creation.
    - `spawn_warm` spawns into a world with one copy of the scene already spawned, so tables and archetypes are warmed up.
Comment on lines +50 to +55
// Cconstruct and drop the scene.
group.bench_function("construct_and_drop", |b| {
b.iter(move || {
scene();
});
});
Copy link
Copy Markdown
Contributor Author

@greeble-dev greeble-dev May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have liked to isolate construction, but I didn't find a good way to do this. Instead, the cost of construction can be estimated by subtracting the drop benchmark.

The alternative solutions were:

  1. Return the scene from the benchmark, but that still doesn't isolate the construct since the ~15KB value needs to be copied.
  2. std::mem::forget, but that means the benchmark needs 2GB of memory.

Comment thread benches/Cargo.toml
# `bench!` macro refers to it in its documentation.
criterion = { version = "0.8.0", features = ["html_reports"] }
seq-macro = "0.3.6"
bevy_feathers = { path = "../crates/bevy_feathers", optional = true }
Copy link
Copy Markdown
Contributor Author

@greeble-dev greeble-dev May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, new dependencies went under [dev-dependencies]. But these new dependencies were added to [dependencies] because [dev-dependencies] can't be optional.

@greeble-dev greeble-dev added A-UI Graphical user interfaces, styles, layouts, and widgets C-Benchmarks Stress tests and benchmarks used to measure how fast things are S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 1, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI May 1, 2026
@cart cart closed this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in UI May 5, 2026
@cart cart reopened this May 5, 2026
@github-project-automation github-project-automation Bot moved this from Done to Needs SME Triage in UI May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets C-Benchmarks Stress tests and benchmarks used to measure how fast things are S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants