Skip to content

Add bevy_transform benchmarks#23906

Merged
alice-i-cecile merged 6 commits intobevyengine:mainfrom
Sieluna:transform
Apr 21, 2026
Merged

Add bevy_transform benchmarks#23906
alice-i-cecile merged 6 commits intobevyengine:mainfrom
Sieluna:transform

Conversation

@Sieluna
Copy link
Copy Markdown
Contributor

@Sieluna Sieluna commented Apr 21, 2026

Objective

  • Add dedicated benchmarks for bevy_transform's propagation systems to catch performance regressions.

Solution

Benchmarks (benches/benches/bevy_transform/propagate.rs):

Added small benchmarks targeting each stage of the propagation pipeline individually.

  • mark_dirty_trees — localized vs. distributed leaf update patterns
  • propagate_parent_transforms — full recompute with roots changed vs. leaves changed (static optimization disabled to isolate traversal cost)
  • transform_pipeline — end-to-end pipeline with static optimization on/off, plus ChildOf reparent churn

The hierarchy setup uses 48 roots × 6 depth layers with mixed fanout (4-4-3-3-2-2) and extra archetype padding (MarkerA/B/C) to reflect realistic gameplay scenes.

Testing

cargo bench -p benches --bench transform

@Sieluna Sieluna changed the title Transform Add bevy_transform benchmarks and align feature gates Apr 21, 2026
@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change A-Transform Translations, rotations and scales 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 Apr 21, 2026
@alice-i-cecile alice-i-cecile requested a review from aevyrie April 21, 2026 01:23
@alice-i-cecile
Copy link
Copy Markdown
Member

I really like both of these changes, but can you please split them into two separate PRs to make them easier to review? :)

@Sieluna Sieluna changed the title Add bevy_transform benchmarks and align feature gates Add bevy_transform benchmarks Apr 21, 2026
@Sieluna
Copy link
Copy Markdown
Contributor Author

Sieluna commented Apr 21, 2026

I really like both of these changes, but can you please split them into two separate PRs to make them easier to review? :)

Thanks for the suggestion. I've rebased this PR onto the latest upstream, and it now only includes the benchmark. The other part will be moved to a separate PR.

@alice-i-cecile alice-i-cecile removed the C-Code-Quality A section of code that is hard to understand or change label Apr 21, 2026
Comment thread crates/bevy_transform/Cargo.toml Outdated
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Benchmarks look fine to me, and I think that including dedicated micro-benchmarks for this is very reasonable.

The Cargo.toml change needs to reverted for this PR though :)

This reverts commit 052a06a.
@alice-i-cecile alice-i-cecile added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Apr 21, 2026
Comment thread benches/benches/bevy_transform/propagate.rs
Comment thread benches/benches/bevy_transform/propagate.rs
Comment thread benches/benches/bevy_transform/propagate.rs
Copy link
Copy Markdown
Contributor

@ickshonpe ickshonpe left a comment

Choose a reason for hiding this comment

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

I haven't written any benchmarks before using criterion (at least that I can recall) but this looks very well constructed to me, except for the minor nit about the schedule ordering.

It'd be nice if we could set up something similar for UI transforms and layout.

Co-Authored-By: ickshonpe <27962798+ickshonpe@users.noreply.github.com>
@kfc35 kfc35 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 Apr 21, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 21, 2026
Merged via the queue into bevyengine:main with commit 738b147 Apr 21, 2026
44 checks passed
pull Bot pushed a commit to orzogc/bevy that referenced this pull request Apr 22, 2026
# Objective

`bevy_transform`'s multi-threading behavior was previously gated on
`feature = "std"`, which incorrectly conflated standard library
availability with multi-threading capability. This means:

- Users who enabled `no_std` but had multi-threading available lost
parallelism unintentionally.
- Users who had `std` but wanted single-threaded execution (e.g. WASM)
still attempted to use the parallel path.
- `bevy_internal`'s `multi_threaded` feature did not propagate down to
`bevy_transform`, so the parallel implementation was not activated when
expected.
- The `bevy_log` dependency was pulled in unconditionally via the `std`
feature, when the only use was optional trace-level warnings.

## Solution

- Added an explicit `multi_threaded` feature to `bevy_transform`, backed
by `bevy_tasks/multi_threaded`, matching the pattern used by `bevy_ecs`
and other crates.
- Replaced all `#[cfg(feature = "std")]` / `#[cfg(not(feature =
"std"))]` guards on parallel/serial code paths with
`#[cfg(all(not(target_arch = "wasm32"), feature = "multi_threaded"))]` /
`#[cfg(any(target_arch = "wasm32", not(feature = "multi_threaded")))]` —
the same guard pattern already used in `bevy_ecs`.
- Added `bevy_transform/multi_threaded` to `bevy_internal`'s and
`bevy_render`'s `multi_threaded` feature lists so parallel transforms
are activated end-to-end when building Bevy with `multi_threaded`.
- Removed the `bevy_log` dependency from `bevy_transform`. Its sole
usage was a `warn_once!` inside `propagate_transforms_for`. This is
replaced with a direct `tracing::warn!` wrapped in `bevy_utils::once!`,
gated on a new opt-in `trace` feature (`dep:tracing`). This keeps the
default build lighter.
- Inlined the `trace` feature spans in `mark_dirty_trees` that
previously depended on `bevy_log`'s re-exported `tracing`, now using
`tracing` directly under `#[cfg(feature = "trace")]`.

## Testing

- All existing unit tests in `bevy_transform::systems::test` pass
unchanged — no behavioral changes, only cfg guard corrections.
- No performance regressions observed by
[Benchmark](bevyengine#23906).

---

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Kevin Chen <chen.kevin.f@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Transform Translations, rotations and scales 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.

4 participants