bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Transform propagation sometimes takes a very long time (300ms+)

Open Ekranos opened this issue 7 months ago • 2 comments

Bevy version

0.16.0

Relevant system information

cargo 1.89.0-nightly (47c911e9e 2025-05-14) Windows 11

What you did

Sometimes we move a lot of objects around (floating origin) and need the transforms to be updated for later systems. If we need to move everything we call.

commands.run_system_cached(bevy::transform::systems::propagate_parent_transforms);

After some trial and error and reading the docs, we now call:

commands.run_system_cached(bevy::transform::systems::mark_dirty_trees);
commands.run_system_cached(bevy::transform::systems::propagate_parent_transforms);
commands.run_system_cached(bevy::transform::systems::sync_simple_transforms);

Sadly i was unable to find in which order these should be called.

In 0.15.0 we only scheduled propagate_transforms.

What went wrong

After upgrading to bevy 0.16.0 transform propagation sometimes takes very long (even 300+ms). In 0.15.0 the transform propagation wasn't even something we noticed in tracy.

Additional information

Screenshot of tracy displaying the time distribution, notice the stragglers at the right. Image

These seem to coincide with the long running transform propagation. Seems odd to have so many threads taking so long. Image

Example of a scene: Image

Ekranos avatar May 28 '25 16:05 Ekranos

@aevyrie

JMS55 avatar May 29 '25 03:05 JMS55

You can use the old propagation system if you'd like. It's likely the case we optimized for (large static scenes) isn't a good fit for what you are doing, and you're better off using a system that blindly propagates all transforms.

It's suspicious this is showing up inside a render system (command buffer generation tasks). I suspect this is a contention issue with the multi threaded system executor, and the transform propagation is a red herring - it just happens to be the thing that hits the thread pool the hardest so it's easy to blame for scheduler issues.

I'm also not familiar with the implications of running a system like this with locals and thread coordination using commands.run_system_cached(bevy::transform::systems::sync_simple_transforms) in addition to it running in the schedule.

aevyrie avatar May 29 '25 05:05 aevyrie

We will try around a bit and comment here in a few days with our findings.

Ekranos avatar Jun 09 '25 19:06 Ekranos