-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slight perf improvement on char::to_ascii_lowercase #81837
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
c90d96a
to
f165f49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lgtm but from the last comment it sounds like you are still working on it. Let me know when ready for review.
@rustbot modify labels: -S-waiting-on-review +S-waiting-on-author |
@dtolnay I think the dust is setttled on this one and is ready for review. |
@bors r+ |
📌 Commit 33d8b04 has been approved by |
Slight perf improvement on char::to_ascii_lowercase `char::to_ascii_lowercase()` was checking if it was ascii and then if it was in the right range. Instead propose to check once (I think removing a compare and a shift in the process: [godbolt](https://godbolt.org/z/e5Tora) ). before: ``` test char::methods::bench_to_ascii_lowercase ... bench: 11,196 ns/iter (+/- 632) test char::methods::bench_to_ascii_uppercase ... bench: 11,656 ns/iter (+/- 671) ``` after: ``` test char::methods::bench_to_ascii_lowercase ... bench: 9,612 ns/iter (+/- 979) test char::methods::bench_to_ascii_uppercase ... bench: 8,241 ns/iter (+/- 701) ``` (calling u8::to_ascii_lowercase and letting that flip the 5th bit is also an option, but it's more instructions. I'm thinking for things around ascii and char we want to be as efficient as possible.)
Slight perf improvement on char::to_ascii_lowercase `char::to_ascii_lowercase()` was checking if it was ascii and then if it was in the right range. Instead propose to check once (I think removing a compare and a shift in the process: [godbolt](https://godbolt.org/z/e5Tora) ). before: ``` test char::methods::bench_to_ascii_lowercase ... bench: 11,196 ns/iter (+/- 632) test char::methods::bench_to_ascii_uppercase ... bench: 11,656 ns/iter (+/- 671) ``` after: ``` test char::methods::bench_to_ascii_lowercase ... bench: 9,612 ns/iter (+/- 979) test char::methods::bench_to_ascii_uppercase ... bench: 8,241 ns/iter (+/- 701) ``` (calling u8::to_ascii_lowercase and letting that flip the 5th bit is also an option, but it's more instructions. I'm thinking for things around ascii and char we want to be as efficient as possible.)
Rollup of 12 pull requests Successful merges: - rust-lang#79423 (Enable smart punctuation) - rust-lang#81154 (Improve design of `assert_len`) - rust-lang#81235 (Improve suggestion for tuple struct pattern matching errors.) - rust-lang#81769 (Suggest `return`ing tail expressions that match return type) - rust-lang#81837 (Slight perf improvement on char::to_ascii_lowercase) - rust-lang#81969 (Avoid `cfg_if` in `std::os`) - rust-lang#81984 (Make WASI's `hard_link` behavior match other platforms.) - rust-lang#82091 (use PlaceRef abstractions more consistently) - rust-lang#82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice) - rust-lang#82166 (add s390x-unknown-linux-musl target) - rust-lang#82234 (Remove query parameters when skipping search results) - rust-lang#82255 (Make `treat_err_as_bug` Option<NonZeroUsize>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Do we need not to do a perf run for this? |
char::to_ascii_lowercase()
was checking if it was ascii and then if it was in the right range. Instead propose to check once (I think removing a compare and a shift in the process: godbolt ).before:
after:
(calling u8::to_ascii_lowercase and letting that flip the 5th bit is also an option, but it's more instructions. I'm thinking for things around ascii and char we want to be as efficient as possible.)