Skip to content

Conversation

@ecoskey
Copy link
Contributor

@ecoskey ecoskey commented Dec 4, 2025

Objective

Allow reborrowing for QueryData types. The end goal here is to work towards a fast System::run_iter api, avoiding the overhead of get_param with each iteration. Funnily enough the only system param that actually needs this is Single, but it seems worthwhile to have anyways

Next steps:

  1. SystemParam::reborrow
  2. SystemIter

Solution

Add reborrow method to QueryData

@ecoskey ecoskey added A-ECS Entities, components, systems, and events D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Dec 4, 2025
@ecoskey ecoskey force-pushed the feature/query_reborrow branch 3 times, most recently from 6f0ab87 to 2538b79 Compare December 9, 2025 02:11
Copy link
Contributor

@NicoZweifel NicoZweifel left a comment

Choose a reason for hiding this comment

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

This is pretty neat! This makes total sense to me in terms of utility functions and the like. I suggested a test that tests exactly this use case.

Other than that there are only a few minor things:

  • For the EntityRef types, we can dereference and use the Copy implementations instead of manually creating the struct again, which is a bit more maintainable.

  • The implemention of Ref<> can also be slightly simplified since ComponentTicksRef implements Clone.

  • I noticed a few missing square brackets in the doc comments.

Copy link
Contributor

@chescock chescock left a comment

Choose a reason for hiding this comment

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

Oh, neat!

Add ReborrowQueryData, an optional subtrait (though almost all QueryData types should implement this in practice)

Do we have any QueryData types today that can't implement it? If not, then I would vote for putting the method directly on QueryData so that we don't need to add a new trait. We already require covariance through shrink(), so this wouldn't be that much more of a requirement.

  • For the EntityRef types, we can dereference and use the Copy implementations instead of manually creating the struct again, which is a bit more maintainable.
  • The implemention of Ref<> can also be slightly simplified since ComponentTicksRef implements Clone.

Could we make Ref: Copy, too? I don't see any reason why it can't be, and that would avoid needing a Ref::reborrow() method entirely. (I guess it has to be a manual impl instead of #[derive(Copy)] since we don't want a T: Copy bound on the impl.)

@ecoskey ecoskey force-pushed the feature/query_reborrow branch from 2538b79 to 80779a9 Compare December 14, 2025 02:43
@ecoskey ecoskey changed the title Add subtrait for reborrowing QueryData types Add method for reborrowing QueryData types Dec 15, 2025
@ecoskey ecoskey 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 Dec 18, 2025
@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Dec 18, 2025
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 would prefer to get the System::run_iter change in at the same time as this work. It's hard to evaluate the utility of this change in isolation, and compile time / binary size costs mean that adding more methods to core traits like this is not free.

@alice-i-cecile alice-i-cecile added the M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Dec 18, 2025
@ecoskey
Copy link
Contributor Author

ecoskey commented Dec 28, 2025

closing these for now, will wrap into a later PR if perf looks good

@ecoskey ecoskey closed this Dec 28, 2025
@NicoZweifel
Copy link
Contributor

closing these for now, will wrap into a later PR if perf looks good

@ecoskey you can ping me if you want another review in a similar PR

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-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants