cargo-binstall
cargo-binstall copied to clipboard
Consider adding -Zcross-crate-inline-threshold=always
This project is already using -Zmir-opt-level=4
because it seems to decrease the size of compiled artifacts. In my own limited experimentation, -Zcross-crate-inline-threshold=always
also seems to have that effect. You might find it worthwhile to enable this flag if your own testing indicates your binaries get smaller.
I implemented this flag so I know how it works but I can't really explain why it seems so effective. It basically automatically adds #[inline]
to all functions which do not already have an inline
attribute. The effect of that attribute is to actually lower the MIR for the function only in CGUs where it is actually referenced, and in all CGUs that reference it (CGUs in Rust tend to be crates, and thus lowering the function in all crates that reference it permits cross-crate-inlining). I think in some cases this results in dramatically improved dead code elimination, not just a more-optimized build.
This project is already using
-Zmir-opt-level=4
because it seems to decrease the size of compiled artifacts.
I believe we have already disabled that due to mis-compilation and right now we use the stable toolchain for most of the release compilation, except for x86_64h-apple-darwin
which needs -Zbuild-std
It basically automatically adds
#[inline]
to all functions which do not already have aninline
attribute. The effect of that attribute is to actually lower the MIR for the function only in CGUs where it is actually referenced, and in all CGUs that reference it (CGUs in Rust tend to be crates, and thus lowering the function in all crates that reference it permits cross-crate-inlining).
Interesting, I was actually wondering if it makes sense to do MIR-level link-time-optimization, by generating MIR (or the new LIR proposed in zulip) when compiling crates, then link them together, optimize them before doing codegen.
It seems that it might be beneficial, though I don't have enough knowledge about compiler to do this.
due to mis-compilation
Was this reported? Any unsound MIR opt should be gated behind -Zunsound-mir-opts. If one has escaped that's a serious bug.
IIRC I have reported, but we rollback to stable because there were quite a few mis-compilation from time to time which is annoying, sometimes blocking PR merges and releases.
I do think it's actually a good thing to enable them, that will help with rustc a lot.
Maybe we can re-enable it if mis-compilation doesn't happen often?