perf: Optimize strpos for scalar needle, plus optimize UTF-8 codepath#20754
Open
neilconway wants to merge 5 commits intoapache:mainfrom
Open
perf: Optimize strpos for scalar needle, plus optimize UTF-8 codepath#20754neilconway wants to merge 5 commits intoapache:mainfrom
strpos for scalar needle, plus optimize UTF-8 codepath#20754neilconway wants to merge 5 commits intoapache:mainfrom
Conversation
Contributor
Author
|
Benchmarks: |
Contributor
Author
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.
Which issue does this PR close?
strpos: (1) scalar needle, and (2) Unicode input #20753.Rationale for this change
This PR implements two mostly unrelated optimizations for
strpos:memmem::Finderand use it to search each row of the haystack. It turns out that this is significantly faster than usingmemchr, and the cost of constructing the finder is cheap because it is amortized over the batch.memchrto search for matches for any combination of ASCII and UTF-8 needle and haystack.The performance improvement depends on a bunch of factors (ASCII vs. UTF-8, scalar vs array needle, length of haystack strings), but ranges from 5% for short ASCII strings with a scalar needle to 15x for long UTF-8 strings with a scalar needle.
What changes are included in this PR?
strposstrposbenchmarks to cover the scalar casestrposimplementationAre these changes tested?
Yes; new test cases and benchmarks added.
Are there any user-facing changes?
No.