Repository navigation
Alloc String::retain optimization - #150067
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Alloc `String::retain` optimization
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (2621d01): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -2.1%, secondary 0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 68.5%, secondary -2.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 479.038s -> 478.434s (-0.13%) |
|
r? joboet Probably makes sense to have the same reviewer for both. |
|
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bc23951 to
875c63d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
66f0f66 to
2af59e0
Compare
|
Thank you, looks great! |
…uwer Rollup of 4 pull requests Successful merges: - rust-lang/rust#150067 (Alloc `String::retain` optimization) - rust-lang/rust#153973 (std::process: fix UEFI ExitStatus::code() silent truncation of error …) - rust-lang/rust#161690 (Deny #[inline] on EII declarations) - rust-lang/rust#161701 (Rename dlltool helper function)
… r=Mark-Simulacrum String::retain: convert only the untouched UTF-8 tail During compaction, `String::retain` reads the next character with `g.s.get_unchecked(read..len)`. This invokes `String`’s `Deref`, constructing a `&str` over the entire `0..len` buffer before selecting the unread tail. For example, removing `'é'` from `"éab"` and moving `'a'` left changes the buffer from `C3 A9 61 62` to `61 A9 61 62`. The next iteration reads the valid `'b'` tail, but first converts the entire buffer, including the orphaned `A9` continuation byte, to `&str`. Constructing a non-UTF-8 `&str` is not immediate language-level UB under the [Reference’s validity requirements](https://doc.rust-lang.org/reference/behavior-considered-undefined.html). However, this conversion violates [`from_utf8_unchecked`’s documented safety precondition](https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html#safety). The libs discussion in rust-lang#134598 is discussing which operations accept invalid UTF-8; `str::get_unchecked` is absent from the tentative list. The fix slices `read..len` directly from the byte vector and converts only that untouched tail to `&str`. The original string was valid UTF-8, and `read` remains on a character boundary. rust-lang#154583 uses the same approach for `extract_if`. Related: rust-lang#150067, rust-lang#134598, rust-lang#154583.
Rollup merge of #163624 - Talha-Dmr:string-retain-tail-utf8, r=Mark-Simulacrum String::retain: convert only the untouched UTF-8 tail During compaction, `String::retain` reads the next character with `g.s.get_unchecked(read..len)`. This invokes `String`’s `Deref`, constructing a `&str` over the entire `0..len` buffer before selecting the unread tail. For example, removing `'é'` from `"éab"` and moving `'a'` left changes the buffer from `C3 A9 61 62` to `61 A9 61 62`. The next iteration reads the valid `'b'` tail, but first converts the entire buffer, including the orphaned `A9` continuation byte, to `&str`. Constructing a non-UTF-8 `&str` is not immediate language-level UB under the [Reference’s validity requirements](https://doc.rust-lang.org/reference/behavior-considered-undefined.html). However, this conversion violates [`from_utf8_unchecked`’s documented safety precondition](https://doc.rust-lang.org/std/str/fn.from_utf8_unchecked.html#safety). The libs discussion in #134598 is discussing which operations accept invalid UTF-8; `str::get_unchecked` is absent from the tentative list. The fix slices `read..len` directly from the byte vector and converts only that untouched tail to `&str`. The original string was valid UTF-8, and `read` remains on a character boundary. #154583 uses the same approach for `extract_if`. Related: #150067, #134598, #154583.
Reverts PR rust-lang#150067 This reverts commit 35df304, reversing changes made to e081d66.
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang#150067 by also rolling back rust-lang#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
Rollup merge of #166011 - workingjubilee:clean-revert-string-retain, r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in #150067 by also rolling back #163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in #165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
…r=hanna-kruppe Clean revert of recent `String::retain` changes Cleanly revert `String::retain` changes introduced in rust-lang/rust#150067 by also rolling back rust-lang/rust#163624's safety hygiene changes in order to address a performance regression in this function that was reported to us in rust-lang/rust#165988. While we desire the safety-improving code, that code does not affect the risk of "actual" undefined behavior in the library code. It merely reduces the amount of implementation details we internally rely on and thus whether that code is resilient to changes around it. r? @hanna-kruppe
View all comments
Hi again!
This uses the exact same algorithm as my other PR: #149784
Technically it should improve performance for
String::retaintoo, But let's see what bors thinks.