-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Disable top down MIR inlining #105119
Disable top down MIR inlining #105119
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
acbb7c3
to
cfd5bf1
Compare
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
r? @cjgillot |
Going to run perf on this just because, but we should merge it regardless, since it's basically an I-hang fix. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit cfd5bf1404c89422ae78e43b7d67eb917b3438e3 with merge cb981251cfe10f6776a0ae1a831c476651314b24... |
cfd5bf1
to
f4f7777
Compare
@bors try |
⌛ Trying commit f4f7777 with merge 986a5e14efc8b034defaa7a2f9099cc48b44bd73... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (986a5e14efc8b034defaa7a2f9099cc48b44bd73): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking 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 @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
As a lighter hammer, should we gate this recursion in a call to |
|
@bors r+ |
Agreed. To be clear, it is definitely possible to do this better. The problem is just that based on my understanding, top-down inlining is not easy to get right, and I don't think we should be attempting it while our inlining logic is as naive as it is today |
☀️ Test successful - checks-actions |
Finished benchmarking commit (226202d): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
For instruction counts, there's a roughly even mix of wins and losses. For cycles, the wins outweigh the losses. All of that seems fine. @rustbot label: +perf-regression-triaged |
…llot Reenable limited top-down MIR inlining Reverts most of rust-lang#105119 and uses an alternative strategy to prevent exponential blowup. Specifically, we allow doing top-down inlining up to depth at most five, and for at most one call site per nested body. r? `@cjgillot`
…illot Disable top down MIR inlining The current MIR inliner has exponential behavior in some cases: <https://godbolt.org/z/7jnWah4fE>. The cause of this is top-down inlining, where we repeatedly do inlining like `call_a() => { call_b(); call_b(); }`. Each decision on its own seems to make sense, but the result is exponential. Disabling top-down inlining fundamentally prevents this. Each call site in the original, unoptimized source code is now considered for inlining exactly one time, which means that the total growth in MIR size is limited to number of call sites * inlining threshold. Top down inlining may be worth re-introducing at some point, but it needs to be accompanied with a principled way to prevent this kind of behavior.
Only check inlining counter after recursing. This PR aims to reduce the strength of rust-lang#105119 even more. In the current implementation, we check the inline count before recursing. This means that we never actually reach inlining depth 3. This PR checks the counter after recursion, to give a chance to inline at depth >= 3. r? `@scottmcm` cc `@JakobDegen`
Only check inlining counter after recursing. This PR aims to reduce the strength of rust-lang/rust#105119 even more. In the current implementation, we check the inline count before recursing. This means that we never actually reach inlining depth 3. This PR checks the counter after recursion, to give a chance to inline at depth >= 3. r? `@scottmcm` cc `@JakobDegen`
The current MIR inliner has exponential behavior in some cases: https://godbolt.org/z/7jnWah4fE. The cause of this is top-down inlining, where we repeatedly do inlining like
call_a() => { call_b(); call_b(); }
. Each decision on its own seems to make sense, but the result is exponential.Disabling top-down inlining fundamentally prevents this. Each call site in the original, unoptimized source code is now considered for inlining exactly one time, which means that the total growth in MIR size is limited to number of call sites * inlining threshold.
Top down inlining may be worth re-introducing at some point, but it needs to be accompanied with a principled way to prevent this kind of behavior.