]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #48163 - alexcrichton:persistent-linker, r=rkruppe
authorkennytm <kennytm@gmail.com>
Wed, 14 Feb 2018 08:14:44 +0000 (16:14 +0800)
committerkennytm <kennytm@gmail.com>
Wed, 14 Feb 2018 10:25:24 +0000 (18:25 +0800)
commit92c66b78c829afe1c0958c5e96ec3b18b67a4667
treef919076c68af2e54e2702ff6f90476384cfd177b
parentd38e11ee105bdf4eda7d7766330908019e2540fc
parent43e8ac27d9bf645b66a15f762be6969e9fe16285
Rollup merge of #48163 - alexcrichton:persistent-linker, r=rkruppe

rustc: Persist LLVM's `Linker` in Fat LTO

This commit updates our Fat LTO logic to tweak our custom wrapper around LLVM's
"link modules" functionality. Previously whenever the
`LLVMRustLinkInExternalBitcode` function was called it would call LLVM's
`Linker::linkModules` wrapper. Internally this would crate an instance of a
`Linker` which internally creates an instance of an `IRMover`. Unfortunately for
us the creation of `IRMover` is somewhat O(n) with the input module. This means
that every time we linked a module it was O(n) with respect to the entire module
we had built up!

Now the modules we build up during LTO are quite large, so this quickly started
creating an O(n^2) problem for us! Discovered in #48025 it turns out this has
always been a problem and we just haven't noticed it. It became particularly
worse recently though due to most libraries having 16x more object files than
they previously did (1 -> 16).

This commit fixes this performance issue by preserving the `Linker` instance
across all links into the main LLVM module. This means we only create one
`IRMover` and allows LTO to progress much speedier.

From the `cargo-cache` project in #48025 a **full build** locally went from
5m15s to 2m24s. Looking at the timing logs each object file was linked in in
single-digit millisecond rather than hundreds, clearly being a nice improvement!

Closes #48025