-
Notifications
You must be signed in to change notification settings - Fork 63
remove inlined functions for faster compilation #92
remove inlined functions for faster compilation #92
Conversation
Wow those are some awesome wins you're seeing! Would you be willing to try to send this upstream to LLVM itself as well? Unfortunately I'm less familiar with their contribution process, but it'd be great to ensure that their experiences eyes also took a look at this! |
I'm waiting for a bugzilla account for LLVM so I can add a ticket upstream |
Thanks @andjo403! Let's wait a few days and see what happens upstream there. |
LLVM dev here [with a hidden passion for rust] :) I wonder whether it's better running GDCE after the inliner or having the inliner itself removing dead functions after they're inlined (admittedly, I haven't looked at whether the latter is feasible). FWIW, what's your benchmark? Can you try with big cases (like, building rust, building clang itself, maybe with LTO [this last one generaly should leave a bunch of unused function around]) |
@dcci hello again! FWIW on rust-lang/rust#44655 it mentions a 23% improvement for the racer project which I think is relatively large, and it also mentions a 15% improvement for rustc itself which I know for a fact is quite large! I haven't tried this out myself yet, though, to verify. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment.
@@ -478,6 +478,8 @@ void PassManagerBuilder::populateModulePassManager( | |||
if (Inliner) { | |||
MPM.add(Inliner); | |||
Inliner = nullptr; | |||
// Removes functions that is not used due to inlining |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: that "are" not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks will fix this
OK, thanks for your datapoints. Thanks! |
Sure yeah! @andjo403 if you want to poke around as well I can try to reproduce the rustc build times and also test some projects like Cargo and some simple-ish LTO cases. |
@alexcrichton sounds good. will try some more projects was thinking of running the https://github.com/rust-lang-nursery/rustc-benchmarks compare.py but will have to install a virtualbox or something due to it is using make and I'm on windows. |
Some stats: These numbers are for whole compilations, basically how long it took
Some other numbers
Definitely seems like some possible big improvements to be had! Apparently not helping LTO a whole lot though :( |
@dcci and @alexcrichton maybe I do not understand how LTO works but I do not see how functions can be removed from an other crate. the linkage must be not private for LTO to do something and it feels like GDCE only can remove private linkage functions. |
@andjo403 oh I think it's just with LTO that typically LLVM works with much larger LLVM modules (lots more code in memory all at once). In theory there's also tons of inlining and in theory greater wins to be had, but the one test I had didn't look too promising unfortunately :( |
@alexcrichton Alex, I'm a little surprised of these numbers as, FWIW, LTO should be the kinda best case but not always really. |
Aha indeed! Looks like there's a spot this PR as-is doesn't handle. I've updated that and will report back the LTO build for Cargo. |
Yes, that's exactly it. You were only getting the benefit from the per-TU pipeline. |
Ah unfortunately that ended up having no impact at all :( |
@alexcrichton there is already one GDCE pass added some lines below https://github.com/andjo403/llvm-1/blob/42e941e24e38c8225bad59632ce56d13949c7f38/lib/Transforms/IPO/PassManagerBuilder.cpp#L747 |
Ah that'd explain the lack of improvements! |
@alexcrichton @andjo403 |
@dcci sounds great, and thanks again for helping out with this! If you've got a patch I can run some tests for it for sure. And yeah we'll take care of backporting for our own "fork", no need to worry about that! |
@alexcrichton shall I close this PR then? |
FWIW, I'm working on this, but the patch exposes a series of misoptimizations in LLVM that need to be fixed. I'm working on these now and I hope to enable the patch once they're all addressed. |
OK, I think the patch was placed in a slightly incorrect point in the pipeline. Thanks!
|
after inlining remove functions that is not called any more reduces compile times due to the removed functions is not further optimized.
have update this PR with the patch from @dcci so it shall be easier to test for others |
@dcci I have only tested to compile race once with standard rustc and once with the patch and I get and for all crates in racer the total time go from 405.71 secs to 315.5 secs @alexcrichton can you also run some tests? |
OK, I think this is fine. |
Upstream rL314997 and rL314999. |
@dcci thanks for all the help |
@alexcrichton yes I want to send a PR to rust-lang/rust |
@alexcrichton looks like you only pushed 314997 -- did you intend to backport 314999 too? |
Oh oops, thanks @cuviper! Apparently when I fetched 314999 wasn't in the mirror yet... |
@alexcrichton I wanted to test the the commit rust-lang/rust@8fd3c8f
|
@andjo403 sounds suspicious! Mind gisting the full error you saw? |
Ah try doing |
yes solved it thanks |
after inlining remove functions that is not called any more
reduces compile times due to the removed functions is not further optimized.
part of solution for rust-lang/rust#44655