perf: use get_unchecked for TwoWaySearcher#155607
Open
KowalskiThomas wants to merge 1 commit intorust-lang:mainfrom
Open
perf: use get_unchecked for TwoWaySearcher#155607KowalskiThomas wants to merge 1 commit intorust-lang:mainfrom
get_unchecked for TwoWaySearcher#155607KowalskiThomas wants to merge 1 commit intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
6d37582 to
40692f5
Compare
Collaborator
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
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.
What is this PR?
This is related to #27721.
This PR is a proposal for a performance improvement in
std::pattern.Profiling of https://github.com/quickwit-oss/quickwit in production shows that
TwoWaySearcher::nextis one of the most CPU-time-consuming functions, so I thought I would give it a look.I read the contribution guide and this seems to be a fitting proposal.
It seems like
TwoWaySearcher::nextandTwoWaySearcher::next_backcould be made faster by usingget_uncheckedin the inner loop comparisons instead of regular indexing, which is safe in the conditions where it would be done (indices are within bounds by construction).I added some
SAFETYcomments in the code to explain why this is safe, as I believe is customary in those cases (and according to this page as well).Benchmarks
I ran the existing bencharmks before/after the changes (only on my laptop, I can run them in other places if that's necessary).
We seem to be getting a ~7.5-12% performance improvement at a very low cost, which sounds worthwhile to me.
But this is the first time I'm proposing a change in Rust, so I'm looking forward to feedback on this.
System info for the benchmarks run
Details