3 ms·
I have been tinkering with Rust lately and compile times have been an issue since almost the beginning. After searching around for a bit, I discovered that a si
by jiripospisil 6y ago
I have been tinkering with Rust lately and compile times have been an issue since almost the beginning. After searching around for a bit, I discovered that a significant amount of time is spent in the linker, not in the actual compiler.
By switching from the default GNU gold linker to LLVM LLD, I have managed to shave off a few seconds on every build. There's an open issue [0] about switching to LLD. It still has some compatibility issues but it works fine on my machine and albeit tiny project.
I would be curious to see how compile times improve for other people just by linking with LLD. You of course need to install LLD first and then you can tell the chain to use it:
time RUSTFLAGS="-C link-arg=-fuse-ld=lld" cargo build
[0] https://github.com/rust-lang/rust/issues/39915 https://github.com/rust-lang/rust/issues/39915
- giovannibajo1 6y agoIt doesn’t work on MacOS though
- jiripospisil 6y agoYeah, unfortunately it does not. From the linked thread: > The macOS (Mach-O) backend for lld is broken and abandoned a rewrite from scratch has begun, but it's early days
- jfkebwjsbx 6y agoWhat is the problem? On macOS they can keep using the bundled linker.
- est31 6y agoMost of the stuff your linker has to churn through is actually debug info. If you turn it off, you'll speed up linking whether it's with LLD, gold, or ld.bfd. Do this in Cargo.toml: [profile.dev] debug = false
- jiripospisil 6y agoThanks, I will test it out when I get home.
- jfkebwjsbx 6y agoNote that disabling debug info means way, way harder debugging!
- jiripospisil 6y agoOh sure, usually I want to build/run it way more often than debug it though. And if I do need to debug it, I could just turn it back on and rebuild.
- est31 6y agoAs the sibling comment says, you can always turn it back on when you want to do debugging. Personally, I mainly do printf debugging so I don't miss it much. Also there is the option of only turning it off for dependencies like: [profile.dev.package."*"] debug = false I haven't tested how big the impact of that is, but it should be pretty large for projects with a larger number of dependencies. Edit: I've tested it now on cargo-udeps [1], which has a large crate graph but only little code of its own and there is only a small difference between turning off debuginfo for all crates vs only for dependencies, but a sizeable improvement over compiling in debuginfo of dependencies. [1]: https://gist.github.com/est31/1bb6e7d6f4be2a23701b8c7c1c678b6e#file-comparison-md https://gist.github.com/est31/1bb6e7d6f4be2a23701b8c7c1c678b...
- vanderZwan 6y agoWhat if you don't really program in Rust yourself but still cargo install the cool CLI tools that people have produced in it? Is there something I can tweak in my global settings for speeding that up?