]> git.lizzy.rs Git - rust.git/commit
rustc: Optimize reading metadata by 4x
authorAlex Crichton <alex@alexcrichton.com>
Tue, 17 Dec 2013 04:58:21 +0000 (20:58 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 20 Dec 2013 07:34:32 +0000 (23:34 -0800)
commit64faafba19621087b060d577c36bbcf6041cb4b6
tree7cd40bc723b19751bb213c0d8f345c1c07f7241f
parent5c24bfa8c3faef7bc28047cb233e914dfe5eee0d
rustc: Optimize reading metadata by 4x

We were previously reading metadata via `ar p`, but as learned from rustdoc
awhile back, spawning a process to do something is pretty slow. Turns out LLVM
has an Archive class to read archives, but it cannot write archives.

This commits adds bindings to the read-only version of the LLVM archive class
(with a new type that only has a read() method), and then it uses this class
when reading the metadata out of rlibs. When you put this in tandem of not
compressing the metadata, reading the metadata is 4x faster than it used to be
The timings I got for reading metadata from the respective libraries was:

    libstd-04ff901e-0.9-pre.dylib    => 100ms
    libstd-04ff901e-0.9-pre.rlib     => 23ms
    librustuv-7945354c-0.9-pre.dylib => 4ms
    librustuv-7945354c-0.9-pre.rlib  => 1ms
    librustc-5b94a16f-0.9-pre.dylib  => 87ms
    librustc-5b94a16f-0.9-pre.rlib   => 35ms
    libextra-a6ebb16f-0.9-pre.dylib  => 63ms
    libextra-a6ebb16f-0.9-pre.rlib   => 15ms
    libsyntax-2e4c0458-0.9-pre.dylib => 86ms
    libsyntax-2e4c0458-0.9-pre.rlib  => 22ms

In order to always take advantage of these faster metadata read-times, I sort
the files in filesearch based on whether they have an rlib extension or not
(prefer all rlib files first).

Overall, this halved the compile time for a `fn main() {}` crate from 0.185s to
0.095s on my system (when preferring dynamic linking). Reading metadata is still
the slowest pass of the compiler at 0.035s, but it's getting pretty close to
linking at 0.021s! The next best optimization is to just not copy the metadata
from LLVM because that's the most expensive part of reading metadata right now.
src/librustc/back/archive.rs
src/librustc/back/lto.rs
src/librustc/driver/driver.rs
src/librustc/lib/llvm.rs
src/librustc/metadata/cstore.rs
src/librustc/metadata/filesearch.rs
src/librustc/metadata/loader.rs
src/rustllvm/RustWrapper.cpp