8 Solutions for Troubleshooting Your Rust Build Times

  1. Take all crates and generate a DAG which is a convenient way to understand which crate depends on (or blocks the compilation of) another crate, and by that, for example — Rust will be able to understand which crates can run in parallel and use all machine cores
  2. If that’s not enough, divide each crate into codegen units to let LLVM process them in parallel as well
  3. And lastly, incremental compilation helps because Rust will save part of the compilation planning work from a previous build and reuse it in the next
logo of llvm

1. Create a Speedy Build Experience

2. Throw Hardware At It

picture of a broken bridge

3. Big Things Build Slowly

$ cargo install cargo-bloat
$ cargo bloat --release -n 10
$ cargo bloat --release --crates

4. Take a Deeper Look

$ RUSTFLAGS="-Z time-passes" cargo build

A magical view for your build

$ cargo build -Z timings

5. Replace Your Linker

What’s in a Faster Linker?

  • Using Swiss Tables instead of STL for hash maps and sets
  • Parallelizing in various places (the parsing of libraries, writing the output file, sorting, etc.)
  • Optimizations around the hashing of strings (caching the hashes, using a better hash function, etc.)

Linux

$ sudo apt-get install lld
[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
$ cargo build

macOS

$ brew install michaeleisel/zld/zld
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld", "-Zshare-generics=y"]
$ cargo build

Global Or Local Config?

6. Crate Shattering

crate shattered

7. Conditionally Compile a “Go Fast” Feature

8. Use Small New Projects on the Side

--

--

--

@jondot | Founder & CEO @ Spectral. Rust + FP + Hacking + Cracking + OSS. Previously CTO @ HiredScore, Como, Conduit.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Reset MySQL 8 Root Password in Ubuntu 20.04

VirusTotal Integration with DNIF

Benefits of Custom Software Development for Business

Hands-on Rust Bonus Content

AWS CDK : Structuring for re-use

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dotan Nahum

Dotan Nahum

@jondot | Founder & CEO @ Spectral. Rust + FP + Hacking + Cracking + OSS. Previously CTO @ HiredScore, Como, Conduit.

More from Medium

GoLang — Concurrency (goroutine, channel)

Installing or Updating Go(Golang) on Linux

Go(Golang) bood nabood…