Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only propagate transforms entities with GlobalTransforms. #14384

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

StarArawn
Copy link
Contributor

@StarArawn StarArawn commented Jul 18, 2024

Objective

Fixes a performance issue when you have 1000s of entities in a bevy hierarchy without transforms.

This was prominently happening in bevy_ecs_tilemap.

Solution

Filter out entities that don't have a global transform.

Testing

CI
We should test some other way...

Migration Guide

  • To avoid surprising performance pitfalls, Transform / GlobalTransform propagation is no longer performed down through hierarchies where intermediate parent are missing a GlobalTransform. To restore the previous behavior, add GlobalTransform::default to intermediate entities.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times A-Transform Translations, rotations and scales A-Hierarchy Parent-child entity hierarchies labels Jul 18, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Jul 18, 2024
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jul 18, 2024
Copy link
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.

I think this is the correct behavior. We shouldn't waste serious amounts of time in real applications trying to propagate transforms that don't exist.

@StarArawn
Copy link
Contributor Author

Just to be clear in a scenario where you have this tree:
Transform entity> no transform entity > transform entity propagation would not flow up the tree.

@janhohenheim
Copy link
Member

janhohenheim commented Jul 20, 2024

Approved, but I want to point out that this might be a surprising change for people who use organizational entities in their tree with only names, e.g.

  • Player (has transform)
    • PhysicsStuff (has no transform)
      • Collider (has transform)
      • Joint (has transform)
      • Sensor (has transform)

This code would now suddenly break in a subtle way. Maybe a migration guide or some documentation would be good.

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 20, 2024
@alice-i-cecile
Copy link
Member

I wrote up a nice little migration guide, and added a bit more context to the PR description :)

@alice-i-cecile alice-i-cecile changed the title Only propagate on entities with GlobalTransforms. Only propagate transforms entities with GlobalTransforms. Jul 20, 2024
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

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

LGTM

@mockersf
Copy link
Member

I think that it's showing something very wrong is happening.

Transform/GlobalTransform are supposed to be on all levels of the hierarchy. If you have holes, what is happening is pretty much undefined, and you're not using transforms in the way expected by the engine.

This should at minimum be a warning, at best be rejected

@mockersf
Copy link
Member

This was prominently happening in bevy_ecs_tilemap.

What is bevy_ecs_tilemap doing to have that, and what does it expect?

@janhohenheim
Copy link
Member

janhohenheim commented Jul 20, 2024

I assume they don't have holes but just big hierarchies without any transforms, which should be supported. I think the note about holes no longer being supported is just pointing out the logical consequences of this PR.

I would be careful with adding checks for warnings to transform propagation as it's quite a hot path. If they're added, I'd like to see a benchmark.

@alice-i-cecile alice-i-cecile added the X-Contentious There are nontrivial implications that should be thought through label Jul 20, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 22, 2024
Merged via the queue into bevyengine:main with commit d1f4262 Jul 22, 2024
36 checks passed
@aevyrie
Copy link
Member

aevyrie commented Jul 23, 2024

I assume they don't have holes but just big hierarchies without any transforms, which should be supported. I think the note about holes no longer being supported is just pointing out the logical consequences of this PR.

I would be careful with adding checks for warnings to transform propagation as it's quite a hot path. If they're added, I'd like to see a benchmark.

Bevy already has validation for components that should exist uninterrupted all the way up the tree, but they run in a separate system. There is no reason validation logic has to live inside the propagation code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Hierarchy Parent-child entity hierarchies A-Transform Translations, rotations and scales C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants