Repository navigation
Conversation
552bbf6 to
9ea4eb0
Compare
|
@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.
Mark functions nounwind when their body proves an unwind cannot escape
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a69e4b3): 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 2.4%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.3%, secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 487.539s -> 489.35s (0.37%) |
|
It appears that excluding generic functions results in negligible size gains, while also introducing numerous regressions. I am currently extending the analysis to include generic functions; once I have the results from another |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Mark functions nounwind when their body proves an unwind cannot escape
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (19464f8): 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 2.4%, secondary -1.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.3%, secondary -3.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.4%, secondary -0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 480.462s -> 480.233s (-0.05%) |
|
A few results on aarch64 are not quite as good as expected. I need to investigate whether certain call sites along the aarch64 code path are repeatedly querying the function ABI, or if the cache for |
|
In my local testing, I discovered an issue likely caused by the inlining threshold. The values shifted from 465 to 245 on aarch64, and from 475 to 255 on x86_64. Since the cutoff for inlining is 250, this 220-unit reduction resulted in one case falling below the threshold, while the other remained above it. For further details, please refer to the discussion on Zulip. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Mark functions nounwind when their body proves an unwind cannot escape
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (f1af851): 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 2.2%, secondary -0.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.2%, secondary -1.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.2%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 485.883s -> 481.907s (-0.82%) |
555704e to
0438e1b
Compare
|
|
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
View all comments
This draft adds a query that walksoptimized_mir. A call is judged by its callee, a drop by its glue, and the answer is a fixpoint over the call graph in which a cycle yields no proof; false means "no proof was found" rather than "this unwinds", so everything the analysis cannot resolve keeps today's behaviour. The result feedsfn_abi_of_instance, and the existing machinery does the rest: the unwind edges become unreachable and the call is emitted as a plain call carryingnounwindon both the definition and the call site. Answers reach downstream crates through the crate metadata as one bit perDefIndex, truncated after the last proven one, which bumps the metadata version; incremental builds write nothing and keep the current behaviour, as do builds without optimizations.This version of the analysis runs on optimized generics; consequently, it gives up in three scenarios: when the arguments to a call still contain type parameters, when a type being dropped contains type parameters, or when a trait method resolution fails to yield a unique implementation. For generic functions, at least one of these conditions is almost always met, meaning that, in practice, the analysis can currently only provide proofs for non-generic functions.I now need arust-perftool to assess the impact of my current changes on the performance and binary size of rustc.This PR makes rustc infer
nounwindat the MIR level, when a function's body proves that no unwind can escape it(no calls to potentially unwinding functions, no drop glue that can panic), it marks the function and its call sitesnounwind, and records the fact in crate metadata so that downstream crates can use it too. Everything is behind-Z nounwind-inferenceand currently only runs at opt-level 1 or above with the unwinding panic strategy.I compute this over MIR rather than leaning on LLVM because MIR is where the information is actually available. By the time LLVM sees a function it has already committed to
invokes and landing pads, and without LTO it never sees the bodies of functions in other crates at all. The analysis bails on indirect calls and virtual shims and only claims the attribute where the body genuinely cannot unwind, so what lands in the metadata is a fact, not a guess.The rust-perf's result is close to neutral and if anything slightly positive: the per-benchmark median is +0.03% on aarch64 and +0.08% on x86_64, primary benchmarks average −0.4% with more of them compiling faster than slower, and primary binary size is −0.2%. The exceptions are a few aarch64 derive-heavy benchmarks that regress hard: clap_derive and -nll are both around +23%, serde_derive +3.9%, syn +3.5%, while the same rows on x86_64 stay under +1%. I think the mechanism is the inline cost model, replacing an
invokeplus its landing pad with a plain call makes a callee about 220 cheaper to inline, and for something like theDropglue ofVec<syn::attr::Attribute>that is enough to cross the-Os/-Ozthreshold of 250(465 down to 245 on aarch64, but 475 down to 255 on x86_64), which is exactly why the two targets diverge.Below is a portion of the discussion from zulip thread: nounwind inference:
aarch64instruction delta 20xx86_64, along with my thoughts on it:In my opinion, I would not read the +23% rows as a reason to shelve this. I think it still counts as an improvement, since the regression comes from an inline-threshold interaction rather than from the fact we are propagating, and that interaction should be fixed in the inline cost model itself rather than by withholding information from LLVM. It also helps that this is behind
-Zfor now, so nobody pays for it until we have the cost model where we want it.I think where LLVM can see a function's body it does, and there I expect the attribute adds nothing; what it cannot recover without LTO is the bodies that live in another crate, and that is the part I think justifies the feature. So even when
cgu=1, the current PR can still retain some of the performance gains derived from cross-crate part.LLVM's view of a function is strictly richer than anything the MIR analysis can produce, but I think "more" is not the same as "earlier" or "everywhere". LLVM sees the body of the function being compiled and of whatever LTO hands it, not the crates it links against, and by the time it does see a body it has already chosen between
invokeandcall. So I see the two as complementary rather than competing, we supply a fact earlier and where LLVM cannot reach, and LLVM keeps doing all the refinement it already did.One possible future direction is to fix the inline cost model interaction, then possibly extending the analysis to more shim kinds.
r? @hanna-kruppe (everyone pls feel free to assign it or review it:>)
cc @panstromek @workingjubilee @programmerjake @saethlin @bjorn3 @hanna-kruppe @tmiasko
LLM disclosure: the code and text are written by hand. The LLM contributed by providing optimization suggestions for certain parts of the code. Three of these suggestions were adopted: 1. In my earlier implementation, the record of whether an item could
unwindrelied on a dense table withindefine_tables!, allocating one boolean byte perDefIndex. This meant the table spanned the entireDefIndexspace of the crate, consuming a byte for every definition, even those that had never been analyzed, which resulted in significant waste. I have replaced this with aLazyValue<DenseBitSet<u32>>, where eachDefIndexis represented by a single bit, and the bitset is truncated to the last active member after encoding. 2. LLM identified that a recursive routine I had written, intended to collect thedrop gluerequirements for a given type, was actually ineffective; furthermore, it repeatedly performed the same query, leading to a regression. This code has now been removed. 3. In previous commit, I mistakenly changedMETADATA_VERSIONto 13; in fact, adding aCrateRootfield does not require changing it. It is now reverted to 12.