Reduce MIR cost penalty for asserts and diverging calls to improve inlining of safety-checked functions#159611
Reduce MIR cost penalty for asserts and diverging calls to improve inlining of safety-checked functions#159611stephenduong1004 wants to merge 2 commits into
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
@stephenduong1004: 🔑 Insufficient privileges: not in try users |
This comment has been minimized.
This comment has been minimized.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Reduce MIR cost penalty for asserts and diverging calls to improve inlining of safety-checked functions
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (ac10c6b): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.7%, secondary -2.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.3%, secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 486.168s -> 486.162s (-0.00%) |
|
Hi @JonathanBrouwer, The perf results align with what I had in mind. It seems the previous MIR inliner cost model was too conservative. While the more aggressive inlining causes compile time to increase, both the reduction in runtime and compiler/binary sizes show that the additional inlining is still beneficial. I am very new to the Rust compiler community, so I would love to get your feedback and ideas on a few things:
Thanks in advance for your guidance! |
|
Note that some of the regressed builds are check and debug builds, which don't run MIR inliner. This means that this is also a runtime regression in some cases, when applied to the compiler itself. This doesn't preclude us from landing it, but it would be nice to know why that happens and whether we can do something about it. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Reduce MIR cost penalty for asserts and diverging calls to improve inlining of safety-checked functions
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (b66603c): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -4.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 486.983s -> 487.999s (0.21%) |
View all comments
Implicit Rust safety checks (arithmetic overflow, bounds checks) generate
Assertterminators and divergingCalls(panics) in MIR. Currently, the MIR inliner penalizes these as expensive function calls.This creates a Catch-22: the compiler blocks inlining because the safety checks make the function look too large, but inlining is what is required to prove those checks are unreachable and optimize them away. This penalizes small, hot functions containing safety checks.
This PR modify
CostCheckerincost_checker.rsto:Charge
TerminatorKind::Assertas a standard instruction instead of a full call.Charge diverging
TerminatorKind::Calls (panic paths) asINSTR_COST = 5.