-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Fix size_hint for partially consumed QueryIter and QueryCombinationIter #5214
Conversation
ee4a84b
to
c94a1b3
Compare
We already keep track of which items we iterated over in the For |
crates/bevy_ecs/src/query/iter.rs
Outdated
fn choose(n: usize, k: usize) -> Option<usize> { | ||
if k > n || n == 0 { | ||
return Some(0); | ||
} | ||
let k = k.min(n - k); | ||
let ks = 1..=k; | ||
let ns = (n + 1 - k..=n).rev(); | ||
ks.zip(ns) | ||
.try_fold(1_usize, |acc, (k, n)| Some(acc.checked_mul(n)? / k)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as #5148 (comment)
The checked_mul
might be overdoing it though, it makes the code harder to read for little benefit
@alice-i-cecile Done now. Should be good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic and tests make sense to me. My understanding is that this is off the iteration hot-path, so we can get away with doing the right thing here.
Can you run a before/after on the iteration benchmarks to double-check that nothing funny is happening?
@james7132 I want your opinion on this.
Note that |
Here are the criterion results https://nicopap.ch/p/bevy_exact_size_iter_criterion_results/all_changes.html The benchmark ran on a very clean machine with a minimal amount of concurrent processes. I've noticed they were fairly consistent with regard to reproducibility. But multithreading seems to be very noisy on my machine, no idea why. |
Thanks for the criterion results. I'm happy to call that a wash; multithreading is noisy and there's no critical regressions. |
I don't think any of these benches shown above use the query iterator. Do you have results for the benches in this folder? https://github.com/bevyengine/bevy/tree/main/benches/benches/bevy_ecs/iteration edit: I also don't think we have any benches for iter combinations, which I would be more worried about the performance of. |
Wow my bad! I updated the page with the actual ECS iteration benches. The bench are a bit more consistent. It seems I did the benches for the |
46400ba
to
3a4c633
Compare
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
3a4c633
to
5ef7e5c
Compare
@@ -57,100 +57,6 @@ mod tests { | |||
|
|||
#[test] | |||
fn query_filtered_exactsizeiterator_len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this test was redundant with query_filtered_combination_size
because we merged the two, and is why it's deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a bit to review the math, but LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
…er (#5214) # Objective Fix #5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes #5149 even when #5148 gets merged. - #5149 - #5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
…er (#5214) # Objective Fix #5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes #5149 even when #5148 gets merged. - #5149 - #5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
…er (bevyengine#5214) # Objective Fix bevyengine#5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes bevyengine#5149 even when bevyengine#5148 gets merged. - bevyengine#5149 - bevyengine#5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
Objective
Fix #5149
Solution
Instead of returning the total count of elements in the
QueryIter
insize_hint
, we return the count of remaining elements. ThisFixes #5149 even when #5148 gets merged.
Changelog
QueryIter
andQueryCombinationIter
having invalidsize_hint