-
Notifications
You must be signed in to change notification settings - Fork 13.4k
optimize str::iter::Chars::advance_by #115331
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
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 41fc4b9 with merge 29c876884857a05f378862248faf8485bd98f05d... |
compiler/rustc_lexer/src/cursor.rs
Outdated
{ | ||
// SAFETY: we checked it's not EOF therefore there must be | ||
// at least 1 char present. | ||
unsafe { self.chars.advance_by(1).unwrap_unchecked() }; |
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.
YMMV: Given that we've seen unwrap_unchecked
not actually remove the branches on slice iterators, consider implementing https://stdrs.dev/nightly/x86_64-unknown-linux-gnu/core/iter/traits/unchecked_iterator/trait.UncheckedIterator.html and having this use that. (And maybe have next
call it too.)
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.
unwrap_unchecked
does appear to work here.
https://rust.godbolt.org/z/3eod9e6je
Edit: Well, it does help inside advance_by
. I have not yet tested whether it helps on advance_by 😅
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
41fc4b9
to
2ef2b65
Compare
r? libs |
This comment has been minimized.
This comment has been minimized.
this avoids part of the char decoding work by not looking at utf8 continuation bytes
2ef2b65
to
40cf1f9
Compare
FWIW, I couldn't reproduce such good results on 1000 until I set CGU=1, but that's how we ship std anyway. @bors r+ rollup |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#115331 (optimize str::iter::Chars::advance_by) - rust-lang#118236 (Update mod comment) - rust-lang#118299 (Update `OnceLock` documentation to give a concrete 'lazy static' example, and expand on the existing example.) - rust-lang#118314 (Rename `{collections=>alloc}{tests,benches}`) - rust-lang#118341 (Simplify indenting in THIR printing) - rust-lang#118366 (Detect and reject malformed `repr(Rust)` hints) - rust-lang#118397 (Fix comments for unsigned non-zero `checked_add`, `saturating_add`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#115331 - the8472:chars_advance, r=cuviper optimize str::iter::Chars::advance_by ``` OLD: str::iter::chars_advance_by_0001 0.00ns/iter +/- 0.00ns str::iter::chars_advance_by_0010 13.00ns/iter +/- 1.00ns str::iter::chars_advance_by_1000 1.20µs/iter +/- 15.00ns NEW: str::iter::chars_advance_by_0001 0.00ns/iter +/- 0.00ns str::iter::chars_advance_by_0010 6.00ns/iter +/- 0.00ns str::iter::chars_advance_by_1000 75.00ns/iter +/- 1.00ns ```
Uh oh!
There was an error while loading. Please reload this page.