Skip to content
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

Avoid a cast in ptr::slice_from_raw_parts(_mut) #124795

Merged
merged 1 commit into from
May 8, 2024

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented May 6, 2024

Casting to *const () or *mut () is no longer needed after #123840 so let's make the MIR smaller (and more inline-able, as seen in the tests).

If ACP#362 goes through we can keep calling ptr::from_raw_parts(_mut) in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.

Casting to `*const ()` or `*mut ()` just bloats the MIR, so let's not.

If ACP#362 goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
@rustbot
Copy link
Collaborator

rustbot commented May 6, 2024

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot 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 May 6, 2024
@joboet
Copy link
Member

joboet commented May 7, 2024

Looks fine! Let's see what the performance improvements are...
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 7, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2024
…ts, r=<try>

Avoid a cast in `ptr::slice_from_raw_parts(_mut)`

Casting to `*const ()` or `*mut ()` is no longer needed after rust-lang#123840 so let's make the MIR smaller (and more inline-able, as seen in the tests).

If [ACP#362](rust-lang/libs-team#362) goes through we can keep calling `ptr::from_raw_parts(_mut)` in these also without the cast, but that hasn't had any libs-api attention yet, so I'm not waiting on it.
@bors
Copy link
Contributor

bors commented May 7, 2024

⌛ Trying commit 61517db with merge 8466125...

@bors
Copy link
Contributor

bors commented May 7, 2024

☀️ Try build successful - checks-actions
Build commit: 8466125 (8466125667d2a47a9fb56f64629d03a88eafa09e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8466125): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.3% [-0.5%, -0.2%] 7
Improvements ✅
(secondary)
-0.4% [-1.3%, -0.2%] 17
All ❌✅ (primary) -0.3% [-0.5%, -0.2%] 7

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
5.7% [2.8%, 8.0%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-4.4%, -0.5%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.0% [-4.4%, 8.0%] 6

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
17.0% [0.5%, 34.0%] 14
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.3%, -2.2%] 2
All ❌✅ (primary) 17.0% [0.5%, 34.0%] 14

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.1%, 0.2%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-1.3%, -0.0%] 85
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.1%] 18
All ❌✅ (primary) -0.4% [-1.3%, 0.2%] 87

Bootstrap: 675.387s -> 674.274s (-0.16%)
Artifact size: 315.97 MiB -> 315.94 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 7, 2024
@joboet
Copy link
Member

joboet commented May 8, 2024

Lovely!
@bors r+

@bors
Copy link
Contributor

bors commented May 8, 2024

📌 Commit 61517db has been approved by joboet

It is now in the queue for this repository.

@bors 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 May 8, 2024
@bors
Copy link
Contributor

bors commented May 8, 2024

⌛ Testing commit 61517db with merge ec1b698...

@bors
Copy link
Contributor

bors commented May 8, 2024

☀️ Test successful - checks-actions
Approved by: joboet
Pushing ec1b698 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 8, 2024
@bors bors merged commit ec1b698 into rust-lang:master May 8, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 8, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ec1b698): 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.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.6%, -0.3%] 6
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 16
All ❌✅ (primary) -0.3% [-0.6%, 0.3%] 7

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
4.8% [2.8%, 6.6%] 3
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
-2.1% [-4.0%, -0.5%] 3
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) 1.4% [-4.0%, 6.6%] 6

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-3.9%, -2.1%] 3
All ❌✅ (primary) - - 0

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.4% [0.1%, 0.9%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-1.3%, -0.0%] 83
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.1%] 21
All ❌✅ (primary) -0.4% [-1.3%, 0.9%] 86

Bootstrap: 675.214s -> 675.971s (0.11%)
Artifact size: 315.83 MiB -> 315.94 MiB (0.03%)

@rustbot rustbot added the perf-regression Performance regression. label May 8, 2024
@nnethercote
Copy link
Contributor

Nice binary size reductions here.

@scottmcm scottmcm deleted the simplify-slice-from-raw-parts branch May 9, 2024 16:46
@scottmcm
Copy link
Member Author

scottmcm commented May 9, 2024

Good to see that the 17.0% average cycle regression from the first perf run was fake.

@Kobzol
Copy link
Contributor

Kobzol commented May 14, 2024

The wins far outweigh the single regression.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label May 14, 2024
fmease added a commit to fmease/rust that referenced this pull request May 29, 2024
…=WaffleLapkin

[ACP 362] genericize `ptr::from_raw_parts`

This implements rust-lang/libs-team#362

As such, it can partially undo rust-lang#124795 , letting `slice_from_raw_parts` just call `from_raw_parts` again without re-introducing the unnecessary cast to MIR.

By doing this it also removes a spurious cast from `str::from_raw_parts`.  And I think it does a good job of showing the value of the ACP, since the only thing that needed new turbofishing because of this is inside `ptr::null(_mut)`, but only because `ptr::without_provenance(_mut)` doesn't support pointers to extern types, which it absolutely could (without even changing the implementation).
fmease added a commit to fmease/rust that referenced this pull request May 29, 2024
…=WaffleLapkin

[ACP 362] genericize `ptr::from_raw_parts`

This implements rust-lang/libs-team#362

As such, it can partially undo rust-lang#124795 , letting `slice_from_raw_parts` just call `from_raw_parts` again without re-introducing the unnecessary cast to MIR.

By doing this it also removes a spurious cast from `str::from_raw_parts`.  And I think it does a good job of showing the value of the ACP, since the only thing that needed new turbofishing because of this is inside `ptr::null(_mut)`, but only because `ptr::without_provenance(_mut)` doesn't support pointers to extern types, which it absolutely could (without even changing the implementation).
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 30, 2024
Rollup merge of rust-lang#125701 - scottmcm:generic-from-raw-parts, r=WaffleLapkin

[ACP 362] genericize `ptr::from_raw_parts`

This implements rust-lang/libs-team#362

As such, it can partially undo rust-lang#124795 , letting `slice_from_raw_parts` just call `from_raw_parts` again without re-introducing the unnecessary cast to MIR.

By doing this it also removes a spurious cast from `str::from_raw_parts`.  And I think it does a good job of showing the value of the ACP, since the only thing that needed new turbofishing because of this is inside `ptr::null(_mut)`, but only because `ptr::without_provenance(_mut)` doesn't support pointers to extern types, which it absolutely could (without even changing the implementation).
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Jun 28, 2024
…pkin

[ACP 362] genericize `ptr::from_raw_parts`

This implements rust-lang/libs-team#362

As such, it can partially undo rust-lang/rust#124795 , letting `slice_from_raw_parts` just call `from_raw_parts` again without re-introducing the unnecessary cast to MIR.

By doing this it also removes a spurious cast from `str::from_raw_parts`.  And I think it does a good job of showing the value of the ACP, since the only thing that needed new turbofishing because of this is inside `ptr::null(_mut)`, but only because `ptr::without_provenance(_mut)` doesn't support pointers to extern types, which it absolutely could (without even changing the implementation).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Development

Successfully merging this pull request may close these issues.

7 participants