5

Remove the size of locals heuristic in MIR inlining by saethlin · Pull Request #...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/110705
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.
neoserver,ios ssh client

Remove the size of locals heuristic in MIR inlining #110705

Conversation

Contributor

This heuristic doesn't necessarily correlate to complexity of the MIR Body. In particular, a lot of straight-line code in MIR tends to never reuse a local, even though any optimizer would effectively reuse the storage or just put everything in registers. So it doesn't even necessarily make sense that this would be a stack size heuristic.

So... what happens if we just delete the heuristic? The benchmark suite improves significantly. Less heuristics better?

r? @cjgillot

scottmcm, Nilstrieb, cjgillot, and Virgiel reacted with heart emoji

rustbot

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

labels

Apr 22, 2023

saethlin

added A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining

labels

Apr 22, 2023

Contributor

Author

This comment has been minimized.

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

Apr 22, 2023

Contributor

hourglass Trying commit 173845c with merge cbbf803...

Contributor

sunny Try build successful - checks-actions
Build commit: cbbf803 (cbbf8037a859939483a183c7ce46714fda36d37d)

This comment has been minimized.

Collaborator

Finished benchmarking commit (cbbf803): comparison URL.

Overall result: xwhite_check_mark 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 x
(primary)
0.5% [0.2%, 0.8%] 6
Regressions x
(secondary)
0.8% [0.2%, 3.1%] 17
Improvements white_check_mark
(primary)
-0.7% [-1.6%, -0.2%] 61
Improvements white_check_mark
(secondary)
-0.9% [-2.3%, -0.2%] 51
All xwhite_check_mark (primary) -0.6% [-1.6%, 0.8%] 67

Max RSS (memory usage)

Results

Cycles

Results

scottmcm, Nilstrieb, cjgillot, and Kobzol reacted with rocket emoji

rustbot

added perf-regression Performance regressions

and removed S-waiting-on-perf Status: Waiting on a perf run to be completed.

labels

Apr 23, 2023

saethlin

marked this pull request as ready for review

April 23, 2023 04:13

Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Member

Wow, those results look great to me.

(I don't know why doc builds regressed on instructions -- maybe just that rlibs are bigger with more inlining? -- but overall they look ½-and-½ above and below for cycles, including the non-relevant ones, so my guess is that's fine since you didn't change anything about rustdoc directly.)

Spitballing in case someone objects: another possibility would be to count only the size of Abi::Aggregate temporaries, since the others frequently end up in registers anyway. That would avoid needlessly penalizing "look, it's a usize temporary that's used immediately", but still catch the "wait, that's a [u64; 25] keccak-p state; maybe that's worth counting".

Contributor

Thanks @saethlin!

Besides instruction count, we have a regression on metadata and binary size for optimized builds. I think those are tolerable (+0.4% on binary size, +2% on crate metadata on average). The regression in bootstrap timings is a unfortunate, but not a reason not to land this PR.

@scottmcm I'm not even convinced that the size of aggregates matters. Those aggregates would end up on the stack either way, through an inlined call or a regular call. Inlining gives the possibility to emit a copy, so that's good to take.

@bors r+

saethlin reacted with thumbs up emoji

Contributor

pushpin Commit 173845c has been approved by cjgillot

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 23, 2023

Contributor

hourglass Testing commit 173845c with merge 915aa06...

Contributor

sunny Test successful - checks-actions
Approved by: cjgillot
Pushing 915aa06 to master...

bors

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

Apr 23, 2023

bors

merged commit 915aa06 into

rust-lang:master

Apr 23, 2023

12 checks passed

saethlin

deleted the ignore-locals-cost branch

April 23, 2023 18:02

Contributor

Author

One of the biggest inlining changes due to this PR in the standard library is that fmt::Arguments::new_const is now inlined into every panic path. That seems undesirable to me, but it seems like just a symptom of the fact that panic!("oh no") expands to code that touches string formatting. I don't have any actual data to go on for what caused the max RSS and artifact size regressions, but this seems likely.

So MIR opts aside, I'm going to see what I can do about that. I don't know how to validate my guess without implementing a fix for it, so this may not be very quick.

Collaborator

Finished benchmarking commit (915aa06): comparison URL.

Overall result: xwhite_check_mark 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 x
(primary)
0.9% [0.3%, 2.7%] 9
Regressions x
(secondary)
1.9% [0.3%, 7.9%] 34
Improvements white_check_mark
(primary)
-0.6% [-1.8%, -0.2%] 59
Improvements white_check_mark
(secondary)
-0.8% [-2.5%, -0.2%] 46
All xwhite_check_mark (primary) -0.4% [-1.8%, 2.7%] 68

Max RSS (memory usage)

Results

Cycles

Results

Contributor

Author

keccak + cranelift-codegen upside_down_face

Contributor

Improvements outweigh regressions.

@rustbot label: +perf-regression-triaged

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

Reviewers

No reviews

Assignees

cjgillot

Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining merged-by-bors This PR was explicitly merged by bors perf-regression Performance regressions 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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects

None yet

Milestone

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