I’m just starting a Rust project and already it takes ~7.6s to build what I’d consider a simple binary.
I’m using async/await a lot and commenting out some awaits, like the await on my hyper server, can improve build performance by about 4s. But I’m not sure if that’s because building async/await is slow or by removing that await the Rust compiler no longer needs to build my HTTP response handling code.
// Removing the equivalent of this line (from https://hyper.rs) in
// my codebase improves build times by ~4s.
if let Err(e) = server.await {
eprintln!("server error: {}", e);
}
I’m not using Cargo which means I’m manually generating rustc commands. Here’s part of a command I’m using for one of these binaries:
rustc admin/dev/server/main.rs --edition=2018 --crate-name=dev_server --crate-type=bin --target=x86_64-apple-darwin --codegen=opt-level=0 --codegen=debuginfo=2 --cap-lints=allow --emit=link --color=always ...
I’ve also abstracted my code into smaller crates. I was hoping that would mean Rust could skip recompilation of smaller crates and third-party dependencies (like hyper), but my guess is that binary codegen is what’s taking all the time?
What are techniques I can use for profiling my Rust build and techniques I can use for improving it? Is there anyway I can reuse compilation for dependencies which haven’t changed when rebuilding the binary? In development could I use dynamic linking for my dependencies instead of static linking?