-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
rustc generates a lot of llvm ir for small programs due to inline generated drops #38827
Comments
webrender marks a lot of functions as |
But shouldn't those inline functions only be emitted if they are used by main.rs? |
@jrmuizel I think you need to use |
I'm not really looking for cross-crate optimizations so lto seems inappropriate. Why do we need to re-emit the ir for unused inline functions? How could these functions ever be used? |
They are used by the functions used by main.rs. All inline-functions transitively used by your code will be included in the crate's LLVM module IIRC. This gives LLVM the ability to inline all of them (if it decides to do so) into your code. |
So it looks like the bulk of this code is from the drop function implementations. i.e. mem::forgetting the return values from renderer::Renderer::new(opts) and compiling with -C panic=abort drops the IR size to 1.3MB. Is there a reason the drop functions need to be inline? |
Well, you're looking for dead code elimination (not emitting functions from other crate that are unused), so you do want cross-crate optimization. |
One reason is that automatically generated drop (like for Renderer) can not be marked inline explicitly, so it would limit programs to not have them inlineable by default. |
It seems like we could avoid having inline generated drop functions in debug builds though. |
It looks like the majority of the code is being added because of monomorphization caused by the inline drop. |
running |
This codegen test suggests that drop glue is not marked for inlining by default: |
More specifically, for an example like: struct A(String);
fn a(_: A) {} becomes something like: a(x: A) {
core::ptr::drop_in_place::<A>(&x);
} which even though it's not being inlined gets codegened in place because of monomorphization. |
Building https://github.com/jrmuizel/webrender/blob/sample-min/sample-min/src/main.rs ends up generating 12MB of LLVM IR (25MB of LLVM IR with debug info turned on). This seems like an excessive amount and it has a big impact on build times.
The text was updated successfully, but these errors were encountered: