-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Rework MIR inlining costs #123179
base: master
Are you sure you want to change the base?
Rework MIR inlining costs #123179
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Rework MIR inlining costs A bunch of the current costs are surprising, probably accidentally from from not writing out the matches in full. For example, a runtime-length `memcpy` was treated as the same cost as an `Unreachable`. This reworks things around two main ideas: - Give everything a baseline cost, because even "free" things do take effort in the compiler (CPU & RAM) to MIR inline, and they're easy to calculate - Then just penalize those things that are materially more than the baseline, like how `[foo; 123]` is far more work than `BinOp::AddUnchecked` in an `Rvalue` By including costs for locals and vardebuginfo this makes some things overall more expensive, but because it also greatly reduces the cost for simple things like local variable addition, other things also become less expensive overall. r? ghost
} | ||
} | ||
TerminatorKind::Call { func: Operand::Constant(ref f), unwind, .. } => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an interesting example, Call
s to non-constants weren't given the CALL_PENALTY
before, because they were hidden down in the _ =>
arm.
| Rvalue::Len(..) | ||
| Rvalue::Cast(..) | ||
| Rvalue::BinaryOp(..) | ||
| Rvalue::NullaryOp(..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, _1 = sizeof(T)
is now just cost 1 (statement baseline) instead of the previous 5 (instr_cost).
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (8bbcded): 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.
Binary sizeResultsThis 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.
Bootstrap: 670.106s -> 665.367s (-0.71%) |
Ah, that looks way better than #123011 (comment) Since this is basically a replacement for #123011 |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
A bunch of the current costs are surprising, probably accidentally from from not writing out the matches in full. For example, a runtime-length `memcpy` was treated as the same cost as an `Unreachable`. This reworks things around two main ideas: - Give everything a baseline cost, because even "free" things do take effort to MIR inline, and that's easy to calculate - Then just penalize those things that are materially more than the baseline, like how `[foo; 123]` is far more work than `BinOp::AddUnchecked` in an `Rvalue` By including costs for locals and vardebuginfo this makes some things overall more expensive, but because it also greatly reduces the cost for simple things like local variable addition, other things also become less expensive overall.
47a5a7f
to
c02cff1
Compare
Since #122975 made a pretty big difference to how MIR ends up after inlining, rebased to re-check perf. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…<try> Rework MIR inlining costs A bunch of the current costs are surprising, probably accidentally from from not writing out the matches in full. For example, a runtime-length `memcpy` was treated as the same cost as an `Unreachable`. This reworks things around two main ideas: - Give everything a baseline cost, because even "free" things do take effort in the compiler (CPU & RAM) to MIR inline, and they're easy to calculate - Then just penalize those things that are materially more than the baseline, like how `[foo; 123]` is far more work than `BinOp::AddUnchecked` in an `Rvalue` By including costs for locals and vardebuginfo this makes some things overall more expensive, but because it also greatly reduces the cost for simple things like local variable addition, other things also become less expensive overall. r? ghost
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (c4f55ec): 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.
Binary sizeResultsThis 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.
Bootstrap: 667.603s -> 668.182s (0.09%) |
@scottmcm any updates on this? thanks |
A bunch of the current costs are surprising, probably accidentally from from not writing out the matches in full. For example, a runtime-length
memcpy
was treated as the same cost as anUnreachable
.This reworks things around two main ideas:
[foo; 123]
is far more work thanBinOp::AddUnchecked
in anRvalue
By including costs for locals and vardebuginfo this makes some things overall more expensive, but because it also greatly reduces the cost for simple things like local variable addition, other things also become less expensive overall.
r? ghost