[Merged by Bors] - Fix size_hint for partially consumed QueryIter and QueryCombinationIter#5214
[Merged by Bors] - Fix size_hint for partially consumed QueryIter and QueryCombinationIter#5214nicopap wants to merge 4 commits intobevyengine:mainfrom
Conversation
ee4a84b to
c94a1b3
Compare
|
We already keep track of which items we iterated over in the For |
| 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.
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. |
alice-i-cecile
left a comment
There was a problem hiding this comment.
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.
Note that this test was redundant with query_filtered_combination_size because we merged the two, and is why it's deleted.
james7132
left a comment
There was a problem hiding this comment.
Took a bit to review the math, but LGTM.
…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
QueryIterinsize_hint, we return the count of remaining elements. ThisFixes #5149 even when #5148 gets merged.
Changelog
QueryIterandQueryCombinationIterhaving invalidsize_hint