bevy/crates/bevy_transform/src
Rostyslav Toch d30391b583
Optimize transform propagation (#14373)
# Objective

- Optimize the `propagate_recursive` function in the transform system to
reduce CPU usage.
- Addresses performance bottleneck in transform propagation, especially
for scenes with complex hierarchies.

## Solution

- Avoided unnecessary cloning of `global_transform` when creating the
tuple in the `propagate_recursive` function.
- Used `as_ref()` method on `Mut<GlobalTransform>` when passing it to
the recursive call, avoiding an extra dereference.
- These changes significantly reduced the CPU usage of this function
from 4.91% to 1.16% of self function time.

## Testing

- Performance testing was conducted using the Hotspot GUI tool,
comparing CPU usage before and after the changes.
- `cargo run --release --example many_foxes`
- Tested on Fedora Linux.
---

## Showcase

Here are the PERF GUI results showing the improvement in CPU usage:

### Before

![image](https://github.com/user-attachments/assets/b5c52800-710b-4793-bf75-33e3eb1d2083)

### After

![image](https://github.com/user-attachments/assets/654a4feb-924c-41c8-8ff9-3a1027bd28b9)

As we can see, the CPU usage for the `propagate_recursive` function has
been reduced from 4.91% to 1.16%, resulting in a significant performance
improvement.

## Migration Guide

This change does not introduce any breaking changes. Users of the Bevy
engine will automatically benefit from this performance improvement
without needing to modify their code.
2024-07-22 18:53:16 +00:00
..
components Clarify GlobalTransform::transform_point (#14292) 2024-07-15 15:59:29 +00:00
bundles.rs Fix intra-doc links and make CI test them (#14076) 2024-07-11 13:08:31 +00:00
commands.rs impl BuildChildrenTransformExt for EntityWorldMut (#14022) 2024-06-26 14:59:20 +00:00
helper.rs Merge BuildWorldChildren and BuildChildren traits. (#14052) 2024-07-01 14:29:39 +00:00
lib.rs Fix intra-doc links and make CI test them (#14076) 2024-07-11 13:08:31 +00:00
plugins.rs bevy_transform split up to allow feature gate modularity (#13599) 2024-05-31 16:40:36 +00:00
systems.rs Optimize transform propagation (#14373) 2024-07-22 18:53:16 +00:00
traits.rs bevy_transform split up to allow feature gate modularity (#13599) 2024-05-31 16:40:36 +00:00