Skip to content

Inline <T as From<T>>::from #100733

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

Merged
merged 1 commit into from
Sep 6, 2022
Merged

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Aug 18, 2022

I noticed (in #100693 (comment)) that the MIR for https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=67097e0494363ee27421a4e3bdfaf513 has inlined most stuff

scope 5 (inlined <Result<i32, u32> as Try>::branch)
scope 8 (inlined <Result<i32, u32> as Try>::from_output)

But yet the do-nothing from call was still there:

_17 = <u32 as From<u32>>::from(move _18) -> bb9;

So let's give this a try and see what perf has to say.

I noticed in the MIR for <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=67097e0494363ee27421a4e3bdfaf513> that it's inlined most stuff
```
scope 5 (inlined <Result<i32, u32> as Try>::branch)
```
```
scope 8 (inlined <Result<i32, u32> as Try>::from_output)
```

But yet the do-nothing `from` call was still there:
```
_17 = <u32 as From<u32>>::from(move _18) -> bb9;
```

So let's give this a try and see what perf has to say.
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Aug 18, 2022
@rustbot

This comment was marked as resolved.

@rust-highfive
Copy link
Contributor

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 18, 2022
@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 18, 2022
@bors
Copy link
Collaborator

bors commented Aug 18, 2022

⌛ Trying commit 8118a31 with merge a4685669c45ee36d41b7e6902366cbbee52120c4...

@bors
Copy link
Collaborator

bors commented Aug 19, 2022

☀️ Try build successful - checks-actions
Build commit: a4685669c45ee36d41b7e6902366cbbee52120c4 (a4685669c45ee36d41b7e6902366cbbee52120c4)

@rust-timer
Copy link
Collaborator

Queued a4685669c45ee36d41b7e6902366cbbee52120c4 with parent 8064a49, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a4685669c45ee36d41b7e6902366cbbee52120c4): comparison url.

Instruction count

  • Primary benchmarks: ✅ relevant improvements found
  • Secondary benchmarks: ✅ relevant improvements found
mean1 max count2
Regressions ❌
(primary)
0.7% 1.0% 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% -2.4% 24
Improvements ✅
(secondary)
-1.2% -2.3% 19
All ❌✅ (primary) -0.6% -2.4% 26

Max RSS (memory usage)

Results
  • Primary benchmarks: ✅ relevant improvement found
  • Secondary benchmarks: ❌ relevant regressions found
mean1 max count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.1% 2.2% 2
Improvements ✅
(primary)
-8.4% -8.4% 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -8.4% -8.4% 1

Cycles

Results
  • Primary benchmarks: ✅ relevant improvement found
  • Secondary benchmarks: ✅ relevant improvements found
mean1 max count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.9% -2.9% 1
Improvements ✅
(secondary)
-2.9% -3.5% 3
All ❌✅ (primary) -2.9% -2.9% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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-review -S-waiting-on-perf -perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 19, 2022
@scottmcm
Copy link
Member Author

Oh! Well that's more obviously-good than I was expecting.

@c410-f3r
Copy link
Contributor

Looking forward to see the day where I won't have to worry about placing #[inline] annotations in trivial methods/functions.

@m-ou-se
Copy link
Member

m-ou-se commented Sep 6, 2022

@bors r+

This change looks fine by itself, but I'm worried about #[inline] and #[inline(always)] in general. In general we try to avoid #[inline(always)], and #[inline] is "mostly" "meaningless" on generic functions. (For some unclear definition of "mostly" and "meaningless".)

Do we have some plan forward, other than just expecting people to apply these attributes manually and benchmarking at every step?

@bors
Copy link
Collaborator

bors commented Sep 6, 2022

📌 Commit 8118a31 has been approved by m-ou-se

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 Sep 6, 2022
@bors
Copy link
Collaborator

bors commented Sep 6, 2022

⌛ Testing commit 8118a31 with merge 380addd...

@bors
Copy link
Collaborator

bors commented Sep 6, 2022

☀️ Test successful - checks-actions
Approved by: m-ou-se
Pushing 380addd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 6, 2022
@bors bors merged commit 380addd into rust-lang:master Sep 6, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 6, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (380addd): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

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

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-2.2%, -0.2%] 25
Improvements ✅
(secondary)
-1.4% [-2.2%, -0.5%] 22
All ❌✅ (primary) -0.8% [-2.2%, -0.2%] 25

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.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.4% [7.3%, 7.6%] 2
Improvements ✅
(primary)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
-2.3% [-2.7%, -1.9%] 3
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

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.

mean1 range count2
Regressions ❌
(primary)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-1.8% [-2.2%, -1.4%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.2% [-2.2%, 2.9%] 3

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@scottmcm scottmcm deleted the inline-from-from-identity branch September 21, 2022 19:26
@Kobzol
Copy link
Contributor

Kobzol commented Sep 27, 2022

@m-ou-se I think (hope) that using (inter-crate) LTO when compiling rustc could reduce the need to sprinkle these inline annotations manually. We're currently trying to push that forward with @bjorn3.

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. 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.

8 participants