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

Introduce MIR summary to avoid loading large bodies without inlining them #89708

Closed
wants to merge 3 commits into from

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Oct 9, 2021

MIR inlining loads the bodies of all callees in order to assess whether to inline them. This implies useless decoding of large MIR bodies, which may incur a significant cost (#80536).

In order to avoid loading such large MIR, this PR introduces a MIR summary structure with pre-computed statistics. Those statistics are used as a fast-reject path for inlining.

r? @wesleywiser

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 9, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
if callee_summary.diverges {
threshold = 0;
}
let threshold = threshold;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: seems like we can remove this line 🙂


fn optimized_mir_summary<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> Summary {
let body = tcx.optimized_mir(did);
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
let param_env = tcx.param_env_reveal_all_normalized(did);

@wesleywiser
Copy link
Member

@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 Oct 18, 2021
@bors
Copy link
Contributor

bors commented Oct 18, 2021

⌛ Trying commit a24590a517c6d5572a907a2e1a116c2e4cc02c13 with merge a1873ce951ce1a384c423d5b4ff6fae61d723370...

@bors
Copy link
Contributor

bors commented Oct 18, 2021

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

@rust-timer
Copy link
Collaborator

Queued a1873ce951ce1a384c423d5b4ff6fae61d723370 with parent 5dab47d, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a1873ce951ce1a384c423d5b4ff6fae61d723370): comparison url.

Summary: This change led to very large relevant regressions 😿 in compiler performance.

  • Very large regression in instruction counts (up to 7.7% on full builds of deeply-nested-async)

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 18, 2021
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2021
@cjgillot
Copy link
Contributor Author

Marking as blocked on #82280

@cjgillot cjgillot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 10, 2021
@bors
Copy link
Contributor

bors commented Feb 24, 2022

☔ The latest upstream changes (presumably #94129) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2022

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@cjgillot
Copy link
Contributor 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 Jul 30, 2022
@bors
Copy link
Contributor

bors commented Jul 30, 2022

⌛ Trying commit 3f4afce with merge 92b8e388fcdff0238f30b942398546107fc237fb...

@bors
Copy link
Contributor

bors commented Jul 30, 2022

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

@rust-timer
Copy link
Collaborator

Queued 92b8e388fcdff0238f30b942398546107fc237fb with parent c907b6f, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (92b8e388fcdff0238f30b942398546107fc237fb): comparison url.

Instruction count

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
0.4% 0.7% 10
Regressions 😿
(secondary)
0.5% 1.0% 9
Improvements 🎉
(primary)
-0.2% -0.3% 2
Improvements 🎉
(secondary)
-0.5% -0.7% 2
All 😿🎉 (primary) 0.3% 0.7% 12

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 🎉 relevant improvement found
mean1 max count2
Regressions 😿
(primary)
3.0% 7.5% 3
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-3.9% -3.9% 1
All 😿🎉 (primary) 3.0% 7.5% 3

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 😿 relevant regression found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
3.8% 3.8% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
N/A N/A 0
All 😿🎉 (primary) N/A N/A 0

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.

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-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 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 30, 2022
@cjgillot cjgillot closed this Jul 30, 2022
@cjgillot cjgillot deleted the mir-summary branch July 30, 2022 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-blocked Status: Blocked on something else such as an RFC or other implementation work. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants