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

Replace remaining uses of &T, Changed<T> with Ref in UI system queries #8567

Merged

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented May 7, 2023

Objective

Replace Query<&T, Changed<T>> style queries with the more efficient Query<Ref<T>> form in two of the UI systems.


Changelog

Replaced use of Changed with Ref in queries in the ui_layout_system and calc_bounds UI systems.

@ickshonpe ickshonpe changed the title Replace use of Changed with Ref Replace Changed with Ref in UI system queries May 7, 2023
@ickshonpe ickshonpe changed the title Replace Changed with Ref in UI system queries Replace remaining uses of &T, Changed<T> with Ref in UI system queries May 8, 2023
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change labels May 8, 2023
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.

Much clearer!

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 8, 2023
@mockersf mockersf added this pull request to the merge queue May 8, 2023
Merged via the queue into bevyengine:main with commit 8581f60 May 8, 2023
@vultix
Copy link

vultix commented May 9, 2023

I'm a bit confused by this - how is Query<Ref<T>> more efficient than Query<&T, Changed<T>>?

I'd assumed that using Changed<T> would do archetype filtering, leading to reduced iterations. With Ref<T> you need to iterate through all entities containing T, even if they are only changed sparsely, right?

@alice-i-cecile
Copy link
Member

Changed<T> doesn't operate on an archetype level currently: only individual entities.

@inodentry
Copy link
Contributor

@alice-i-cecile I have a question. Didn't we at some point talk about possibly tracking that information at the archetype level in the ECS in the future, to allow for more efficient change detection? So that query filters can actually result in an efficiency improvement by only accessing changed entities?

This PR seems counterproductive. If we ever do that, we would have to change it back.

Also, performance aside, I really disagree that using Ref is always necessarily clearer. If the intent is to only access changed entities, then the query filter makes that clear. If the intent is to access all entities, but be able to do different logic if entities were changed or not, then Ref is clearer.

I know this PR was merged long ago, and me expressing an opinion now probably doesn't matter much, but this really feels like the wrong direction to me.

@alice-i-cecile
Copy link
Member

That's a valid position, and yeah, we should be able to have multiple layers of change detection for faster operation in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change 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.

5 participants