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

Add #[inline] to small functions in core #116583

Closed
wants to merge 4 commits into from

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Oct 9, 2023

I'm adding a new case to the definition of cross-crate-inlinable; we know that making the definition too broad causes huge regressions in incremental builds. So implementing broader heuristics as a machine-applicable lint means that I can x fix --stage 1 library/core to apply the new heuristic just to the standard library. I expect that applying the broader heuristic just to the standard library will have a different effect than applying the change globally.

@saethlin saethlin added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Oct 9, 2023
@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 Oct 9, 2023
@saethlin saethlin removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2023
@saethlin
Copy link
Member Author

saethlin commented Oct 9, 2023

@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 Oct 9, 2023
@bors
Copy link
Contributor

bors commented Oct 9, 2023

⌛ Trying commit e50157c with merge fcd818f...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 9, 2023
Add #[inline] to small functions in core

Where "small" is strictly defined as optimized_mir with 5 or less statements and no calls. I've also applied that heuristic recursively; applying it once causes some functions to become eligible for MIR inlining bring other functions under the threshold.

r? `@ghost`
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Oct 9, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (fcd818f): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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)
3.7% [0.4%, 13.0%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.3% [-0.4%, -0.2%] 4
Improvements ✅
(secondary)
-13.7% [-39.2%, -0.8%] 3
All ❌✅ (primary) 1.9% [-0.4%, 13.0%] 9

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.1% [4.3%, 5.9%] 2
Regressions ❌
(secondary)
2.9% [2.9%, 2.9%] 1
Improvements ✅
(primary)
-3.7% [-8.4%, -1.3%] 6
Improvements ✅
(secondary)
-3.4% [-3.4%, -3.4%] 1
All ❌✅ (primary) -1.5% [-8.4%, 5.9%] 8

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)
5.5% [1.0%, 13.6%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.2% [-1.5%, -1.0%] 2
Improvements ✅
(secondary)
-9.4% [-34.8%, -0.7%] 4
All ❌✅ (primary) 2.8% [-1.5%, 13.6%] 5

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.1% [0.0%, 0.6%] 38
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 7
Improvements ✅
(primary)
-0.3% [-0.9%, -0.0%] 53
Improvements ✅
(secondary)
-0.5% [-1.4%, -0.0%] 76
All ❌✅ (primary) -0.1% [-0.9%, 0.6%] 91

Bootstrap: 627.383s -> 626.833s (-0.09%)
Artifact size: 270.83 MiB -> 270.65 MiB (-0.07%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 10, 2023
@saethlin
Copy link
Member Author

I'm going to try a slightly different approach just to see what happens- this time I'm adding #[inline] to non-generic functions that do not have a Call or Assert terminator.

@rust-log-analyzer

This comment has been minimized.

@saethlin
Copy link
Member Author

@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 Oct 10, 2023
@bors
Copy link
Contributor

bors commented Oct 10, 2023

⌛ Trying commit 69b3155 with merge b1ac082...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 10, 2023
Add #[inline] to small functions in core

Where "small" is strictly defined as optimized_mir with 5 or less statements and no calls. I've also applied that heuristic recursively; applying it once causes some functions to become eligible for MIR inlining which brings other functions under the threshold.

r? `@ghost`
@bors
Copy link
Contributor

bors commented Oct 10, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b1ac082): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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.3% [0.3%, 0.4%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-1.1%, -0.3%] 7
Improvements ✅
(secondary)
-1.0% [-1.3%, -0.3%] 23
All ❌✅ (primary) -0.6% [-1.1%, 0.4%] 9

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)
3.9% [1.6%, 5.7%] 6
Regressions ❌
(secondary)
0.9% [0.8%, 1.0%] 3
Improvements ✅
(primary)
-5.4% [-12.4%, -0.1%] 3
Improvements ✅
(secondary)
-0.8% [-1.1%, -0.5%] 2
All ❌✅ (primary) 0.8% [-12.4%, 5.7%] 9

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)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 2
Improvements ✅
(secondary)
-1.1% [-1.5%, -0.8%] 11
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 2

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.1% [0.0%, 0.4%] 44
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 7
Improvements ✅
(primary)
-0.2% [-0.6%, -0.0%] 34
Improvements ✅
(secondary)
-0.5% [-0.6%, -0.0%] 74
All ❌✅ (primary) -0.1% [-0.6%, 0.4%] 78

Bootstrap: 626.852s -> 625.243s (-0.26%)
Artifact size: 270.87 MiB -> 270.69 MiB (-0.07%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 11, 2023
@saethlin saethlin removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 11, 2023
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 4, 2023
@bors
Copy link
Contributor

bors commented Nov 4, 2023

⌛ Trying commit 9c3c8ef with merge d11ea83...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2023
Add #[inline] to small functions in core

I'm adding a new case to the definition of cross-crate-inlinable; we know that making the definition too broad causes huge regressions in incremental builds. So implementing broader heuristics as a machine-applicable lint means that I can `x fix --stage 1 library/core` to apply the new heuristic just to the standard library. I expect that applying the broader heuristic just to the standard library will have a different effect than applying the change globally.
@bors
Copy link
Contributor

bors commented Nov 4, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d11ea83): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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)
1.0% [0.2%, 3.7%] 41
Regressions ❌
(secondary)
3.6% [0.2%, 6.9%] 7
Improvements ✅
(primary)
-2.4% [-11.7%, -0.2%] 88
Improvements ✅
(secondary)
-3.4% [-25.6%, -0.1%] 179
All ❌✅ (primary) -1.3% [-11.7%, 3.7%] 129

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)
2.9% [0.4%, 7.6%] 16
Regressions ❌
(secondary)
2.9% [0.6%, 6.4%] 9
Improvements ✅
(primary)
-2.1% [-7.1%, -0.5%] 11
Improvements ✅
(secondary)
-3.3% [-7.8%, -1.1%] 12
All ❌✅ (primary) 0.8% [-7.1%, 7.6%] 27

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)
2.0% [0.7%, 4.5%] 18
Regressions ❌
(secondary)
6.0% [4.6%, 7.1%] 4
Improvements ✅
(primary)
-4.1% [-12.6%, -0.4%] 46
Improvements ✅
(secondary)
-6.0% [-24.6%, -1.3%] 90
All ❌✅ (primary) -2.4% [-12.6%, 4.5%] 64

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)
1.5% [0.1%, 8.8%] 53
Regressions ❌
(secondary)
5.7% [0.5%, 8.8%] 6
Improvements ✅
(primary)
-2.6% [-6.5%, -0.1%] 89
Improvements ✅
(secondary)
-4.2% [-11.9%, -0.5%] 93
All ❌✅ (primary) -1.1% [-6.5%, 8.8%] 142

Bootstrap: 635.521s -> 654.274s (2.95%)
Artifact size: 304.34 MiB -> 304.99 MiB (0.21%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 5, 2023
@saethlin
Copy link
Member Author

saethlin commented Nov 5, 2023

That looks like it might be moving in a good direction? Notably the big improvements are all in helloworld so I think the report looks better than the real-world impact would be.
@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 Nov 5, 2023
@bors
Copy link
Contributor

bors commented Nov 5, 2023

⌛ Trying commit 4edca85 with merge 79d9fa0...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 5, 2023
Add #[inline] to small functions in core

I'm adding a new case to the definition of cross-crate-inlinable; we know that making the definition too broad causes huge regressions in incremental builds. So implementing broader heuristics as a machine-applicable lint means that I can `x fix --stage 1 library/core` to apply the new heuristic just to the standard library. I expect that applying the broader heuristic just to the standard library will have a different effect than applying the change globally.
@bors
Copy link
Contributor

bors commented Nov 6, 2023

☀️ Try build successful - checks-actions
Build commit: 79d9fa0 (79d9fa061f39758953a7eb7a805ce2aeaf88f7da)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (79d9fa0): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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)
1.4% [0.2%, 8.3%] 88
Regressions ❌
(secondary)
1.9% [0.4%, 3.6%] 14
Improvements ✅
(primary)
-2.0% [-5.1%, -0.5%] 11
Improvements ✅
(secondary)
-1.1% [-2.0%, -0.2%] 44
All ❌✅ (primary) 1.0% [-5.1%, 8.3%] 99

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)
2.7% [0.4%, 5.7%] 21
Regressions ❌
(secondary)
2.4% [1.2%, 3.8%] 11
Improvements ✅
(primary)
-1.8% [-3.7%, -0.5%] 6
Improvements ✅
(secondary)
-3.3% [-8.3%, -0.7%] 5
All ❌✅ (primary) 1.7% [-3.7%, 5.7%] 27

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)
2.5% [0.4%, 9.5%] 43
Regressions ❌
(secondary)
2.3% [0.7%, 3.4%] 11
Improvements ✅
(primary)
-2.1% [-3.7%, -0.6%] 10
Improvements ✅
(secondary)
-1.8% [-2.4%, -1.3%] 21
All ❌✅ (primary) 1.7% [-3.7%, 9.5%] 53

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)
2.0% [0.1%, 19.0%] 103
Regressions ❌
(secondary)
1.3% [0.0%, 2.8%] 19
Improvements ✅
(primary)
-1.1% [-3.7%, -0.1%] 25
Improvements ✅
(secondary)
-1.4% [-2.9%, -0.0%] 11
All ❌✅ (primary) 1.4% [-3.7%, 19.0%] 128

Bootstrap: 637.169s -> 642.023s (0.76%)
Artifact size: 304.52 MiB -> 304.70 MiB (0.06%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 6, 2023
@saethlin
Copy link
Member Author

saethlin commented Nov 6, 2023

Wow that is not the direction I expected.

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 8, 2023
Emit #[inline] on derive(Debug)

Breaking out part of rust-lang#116583 (comment)

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 8, 2023
Emit #[inline] on derive(Debug)

Breaking out part of rust-lang#116583 (comment)

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 9, 2023
…ercote

Emit #[inline] on derive(Debug)

While working on rust-lang#116583 I noticed that the `cross_crate_inlinable` query identifies a lot of derived `Debug` impls as a MIR body that's little more than a call, which suggests they may be a good candidate for `#[inline]`. So here I've implemented that change specifically.

It seems to provide a nice improvement to build times.
@saethlin
Copy link
Member Author

I'm not actually planning to move this PR forward; this was an experiment that resulted in adding #[inline] to derived Debug impls. I don't think there's much else to be gained here.

A lint that suggests #[inline] is a decent idea, but if I could figure out how to write that lint well I would also be able to improve cross_crate_inlinable and obviate the lint.

@saethlin saethlin closed this Jan 21, 2024
@saethlin saethlin deleted the inline-small-core-fns branch January 21, 2024 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

9 participants