perf: Optimize lower, upper for ASCII inputs#21980
Open
neilconway wants to merge 1 commit intoapache:mainfrom
Open
perf: Optimize lower, upper for ASCII inputs#21980neilconway wants to merge 1 commit intoapache:mainfrom
lower, upper for ASCII inputs#21980neilconway wants to merge 1 commit intoapache:mainfrom
Conversation
comphead
reviewed
May 2, 2026
| continue; | ||
| } | ||
| let mut bytes = view.to_le_bytes(); | ||
| if len <= 12 { |
Contributor
There was a problem hiding this comment.
lets add some comments, I assume 12 len is the fast path for german strings?
comphead
reviewed
May 2, 2026
Contributor
comphead
left a comment
There was a problem hiding this comment.
Thanks @neilconway
I believe the optimization tightly connected to german strings specifics and it would be nice to comment the byte level work
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?
lower,uppercould be further optimized for ASCII-only inputs #21813.Rationale for this change
This PR implements two optimizations for
lowerandupperon ASCII strings:Utf8/LargeUtf8code path, we previously did the case conversion viastr::to_uppercaseorstr::to_lowercase. For ASCII inputs, it is a bit faster to usemap(u8::to_ascii_lowercase).collect()over the bytes of the string directly: although the stdlib functions are well-optimized, they need to check again on every string to see if it is ASCII. Since we know the input is all-ASCII, we can avoid that check.Utf8Viewcode path previously wasn't optimized for ASCII strings; add a new code path that is.Benchmarks (ARM64):
upper
lower — all-ASCII (the optimized paths)
lower — some non-ASCII string_views (mostly noise)
lower — first/middle non-ASCII (flat)
What changes are included in this PR?
Are these changes tested?
Covered by existing tests.
Are there any user-facing changes?
No.