Automatically enable cross-crate inlining for small functions#116505
Automatically enable cross-crate inlining for small functions#116505bors merged 2 commits intorust-lang:masterfrom
Conversation
|
(rustbot has picked a reviewer for you, use r? to override) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Automatically enable cross-crate inlining for small functions This is a work-in-progress. For example I have not thought at all about the cost model and I am sure that the threshold is too high. But I'm curious to know how this looks in perf. It certainly has some unique effects on codegen.
This comment has been minimized.
This comment has been minimized.
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f1cbf12): 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: 625.502s -> 742.509s (18.71%) |
|
This should be less silly than the last one because now we don't do the per-CGU thing for incr builds. And I also halved the default threshold. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Automatically enable cross-crate inlining for small functions This is a work-in-progress. For example I have not thought at all about the cost model and I am sure that the threshold is too high. But I'm curious to know how this looks in perf. It certainly has some unique effects on codegen.
This comment has been minimized.
This comment has been minimized.
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (26bbeca): 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: 622.673s -> 704.606s (13.16%) |
|
With this change, is there any convenient way for a crate to indicate that it should be compiled with full optimizations but none of its public API should be inlined unless marked |
That attribute is documented as a hint, so no. I do not think we have a language feature that guarantees what you are asking for. It seems like a plausible thing to add but that's a bit outside my area. |
This is basically reviving #70550
The
#[inline]attribute can have a significant impact on code generation or runtime performance (because it enables inlining between CGUs where it would normally not happen) and also on compile-time performance (because it enables MIR inlining). But it has to be added manually, which is awkward.This PR factors whether a DefId is cross-crate inlinable into a query, and replaces all uses of
CodegenFnAttrs::requests_inlinewith this new query. The new query incorporates all the other logic that is used to determine whether a Def should be treated as cross-crate-inlinable, and as a last step inspects the function's optimized_mir to determine if it should be treated as cross-crate-inlinable.The heuristic implemented here is deliberately conservative; we only infer inlinability for functions whose optimized_mir does not contain any calls or asserts. I plan to study adjusting the cost model later, but for now the compile time implications of this change are so significant that I think this very crude heuristic is well worth landing.