4

Use unchecked_sub in str indexing by saethlin · Pull Request #123561 · rust-lang...

 2 weeks ago
source link: https://github.com/rust-lang/rust/pull/123561
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Conversation

Member

#108763 applied this logic to indexing for slices, but of course str has its own separate impl.

Found this by skimming over the codegen for https://github.com/oxidecomputer/hubris/; their dist builds enable overflow checks so the lack of unchecked_sub was producing an impossible-to-hit overflow check and also inhibiting some inlining.

r? scottmcm

rustbot

added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

labels

Apr 6, 2024

let len = self.end - self.start;

ptr::slice_from_raw_parts(ptr, len) as *const str

unsafe {

let new_len = unchecked_sub(self.end, self.start);

Does this get different codegen if you just use the public stdlib unchecked_sub?

It gets a boatload more MIR, or at least it will once #121571 lands.

(We really need a "look, nobody cares about the parameter debug info from this method" for things like that and i32:PartialOrd and …)

Ah okay! Cool then.

Member

Author

No, but it doubles up on the precondition check.

Member

Ah, good catch!
@bors r+ rollup=iffy (codegen tests aren't tested in CI, AFAIK)

Contributor

📌 Commit 712aab7 has been approved by scottmcm

It is now in the queue for this repository.

bors

added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

labels

Apr 6, 2024

Contributor

⌛ Testing commit 712aab7 with merge 4e431fa...

Contributor

☀️ Test successful - checks-actions
Approved by: scottmcm
Pushing 4e431fa to master...

bors

added the merged-by-bors This PR was explicitly merged by bors. label

Apr 7, 2024

bors

merged commit 4e431fa into

rust-lang:master

Apr 7, 2024

12 checks passed

rustbot

added this to the 1.79.0 milestone

Apr 7, 2024

saethlin

deleted the str-unchecked-sub-index branch

April 7, 2024 15:04

Collaborator

Finished benchmarking commit (4e431fa): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.9% [0.9%, 0.9%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.5% [-0.9%, -0.4%] 7
All ❌✅ (primary) 0.9% [0.9%, 0.9%] 1

Max RSS (memory usage)

Results

Cycles

Results

Binary size

Results

Bootstrap: 667.899s -> 667.449s (-0.07%)
Artifact size: 318.21 MiB -> 318.47 MiB (0.08%)

rustbot

added the perf-regression Performance regression. label

Apr 7, 2024

Member

  • this is an improvement to the code for str::get_unchecked when overflow checks are enabled; its calling a compiler-intrinsic directly now.
  • it really doesn't make any sense that it caused any regression at all. (Perhaps this change is causing a change to inlining decisions, at least for cargo?)
  • marking as triaged.

@rustbot label: +perf-regression-triaged

rustbot

added the perf-regression-triaged The performance regression has been triaged. label

Apr 9, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

scottmcm

scottmcm left review comments

workingjubilee

workingjubilee left review comments
Assignees

scottmcm

Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects

None yet

Milestone

1.79.0

Development

Successfully merging this pull request may close these issues.

None yet

7 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK