[Merged by Bors] - Speed up Query::get_many and add benchmarks#6400
Closed
joseph-gio wants to merge 6 commits intobevyengine:mainfrom
Closed
[Merged by Bors] - Speed up Query::get_many and add benchmarks#6400joseph-gio wants to merge 6 commits intobevyengine:mainfrom
Query::get_many and add benchmarks#6400joseph-gio wants to merge 6 commits intobevyengine:mainfrom
Conversation
james7132
requested changes
Oct 28, 2022
crates/bevy_ecs/src/query/state.rs
Outdated
| last_change_tick, | ||
| change_tick, | ||
| )?; | ||
| values[i] = MaybeUninit::new(item); |
Member
There was a problem hiding this comment.
This does a bounds check. It's a bit more verbose, but slice::get_unchecked_mut might further speed things up a bit. We know the index must be valid because i must be less than N.
Member
Author
There was a problem hiding this comment.
I ended up using an iterator to remove the bounds checks -- I measured the same performance for both iterators and get_unchecked_mut.
alice-i-cecile
approved these changes
Oct 29, 2022
james7132
reviewed
Oct 29, 2022
james7132
reviewed
Oct 29, 2022
Member
james7132
left a comment
There was a problem hiding this comment.
Can we get one more round of benchmarks to ensure that the review changes haven't shifted the perf that significantly?
Member
Author
|
Here's another run:
Criterion output: https://github.com/JoJoJet/files/blob/c4b99129978e2566b2139efb5e96462094c77aed/get-many-benches-output.zip |
james7132
approved these changes
Nov 1, 2022
Member
|
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
Nov 1, 2022
# Objective * Add benchmarks for `Query::get_many`. * Speed up `Query::get_many`. ## Solution Previously, `get_many` and `get_many_mut` used the method `array::map`, which tends to optimize very poorly. This PR replaces uses of that method with loops. ## Benchmarks | Benchmark name | Execution time | Change from this PR | |--------------------------------------|----------------|---------------------| | query_get_many_2/50000_calls_table | 1.3732 ms | -24.967% | | query_get_many_2/50000_calls_sparse | 1.3826 ms | -24.572% | | query_get_many_5/50000_calls_table | 2.6833 ms | -30.681% | | query_get_many_5/50000_calls_sparse | 2.9936 ms | -30.672% | | query_get_many_10/50000_calls_table | 5.7771 ms | -36.950% | | query_get_many_10/50000_calls_sparse | 7.4345 ms | -36.987% |
Contributor
Query::get_many and add benchmarksQuery::get_many and add benchmarks
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this pull request
Feb 1, 2023
# Objective * Add benchmarks for `Query::get_many`. * Speed up `Query::get_many`. ## Solution Previously, `get_many` and `get_many_mut` used the method `array::map`, which tends to optimize very poorly. This PR replaces uses of that method with loops. ## Benchmarks | Benchmark name | Execution time | Change from this PR | |--------------------------------------|----------------|---------------------| | query_get_many_2/50000_calls_table | 1.3732 ms | -24.967% | | query_get_many_2/50000_calls_sparse | 1.3826 ms | -24.572% | | query_get_many_5/50000_calls_table | 2.6833 ms | -30.681% | | query_get_many_5/50000_calls_sparse | 2.9936 ms | -30.672% | | query_get_many_10/50000_calls_table | 5.7771 ms | -36.950% | | query_get_many_10/50000_calls_sparse | 7.4345 ms | -36.987% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Query::get_many.Query::get_many.Solution
Previously,
get_manyandget_many_mutused the methodarray::map, which tends to optimize very poorly. This PR replaces uses of that method with loops.Benchmarks