-
Notifications
You must be signed in to change notification settings - Fork 13k
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
speed up String::push
and String::insert
#124810
base: master
Are you sure you want to change the base?
speed up String::push
and String::insert
#124810
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
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.
I had a variety of thoughts; let me know what you think.
Also, is there anything here for which it would make sense to have a codegen test to confirm what's happening? Or some other test to help confirm it's better?
A codegen check for the absence of |
Insufficient permissions to issue commands to rust-timer. |
@lincot: 🔑 Insufficient privileges: not in try users |
Insufficient permissions to issue commands to rust-timer. |
☔ The latest upstream changes (presumably #116113) made this pull request unmergeable. Please resolve the merge conflicts. |
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
9511918
to
89fa55e
Compare
☔ The latest upstream changes (presumably #127840) made this pull request unmergeable. Please resolve the merge conflicts. |
89fa55e
to
2cb20b3
Compare
☔ The latest upstream changes (presumably #130511) made this pull request unmergeable. Please resolve the merge conflicts. |
The proposed implementation uses |
2cb20b3
to
7a7cfb1
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #131460) made this pull request unmergeable. Please resolve the merge conflicts. |
b52db40
to
3a60212
Compare
This comment has been minimized.
This comment has been minimized.
(oops the review request was an accidental click) |
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.
It looks like your perf job never got run, could you rebase?
#[doc(hidden)] | ||
#[inline] | ||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))] | ||
pub const unsafe fn encode_utf8_raw_unchecked(code: u32, dst: *mut u8) { |
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.
dst
could probably still be a &mut [u8]
in this signature, call .as_mut_ptr()
within this function. Then you can add a debug_assert!(dst.len() >= len)
.
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.
I believe &mut [u8]
cannot point to uninitialized memory according to safety guidelines, which is why I used &mut [MaybeUninit<u8>]
first. If a slice is necessary, we can revert to using &mut [MaybeUninit<u8>]
and .as_mut_ptr()
.
@rustbot author |
9462d92
to
a2effde
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@rustbot review |
☔ The latest upstream changes (presumably #135947) made this pull request unmergeable. Please resolve the merge conflicts. |
49bd467
to
b7f3a92
Compare
Addresses the concerns described in #116235.
The performance gain comes mainly from avoiding temporary buffers.
Complex pattern matching in
encode_utf8
(introduced in #67569) has been simplified to a comparison and an exhaustivematch
in theencode_utf8_raw_unchecked
helper function. It takes a slice ofMaybeUninit<u8>
because otherwise we'd have to construct a normal slice to uninitialized data, which is not desirable, I guess.Several functions still have that unneeded zeroing, but a single instruction is not that important, I guess.
@rustbot label T-libs C-optimization A-str