Skip to content

Commit 466e519

Browse files
committed
Add Troubleshoot Slow Incremental Builds section.
Thanks to @caspark for the tip
1 parent 74f8f6a commit 466e519

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

  • content/blog/tips-for-faster-rust-compile-times

content/blog/tips-for-faster-rust-compile-times/index.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
+++
22
title = "Tips For Faster Rust Compile Times"
33
date = 2024-01-12
4-
updated = 2025-09-11
4+
updated = 2026-01-14
55
draft = false
66
template = "article.html"
77
[extra]
@@ -43,6 +43,7 @@ Click here to expand the table of contents.
4343
- [Update Dependencies](#update-dependencies)
4444
- [Find the slow crate in your codebase](#find-the-slow-crate-in-your-codebase)
4545
- [Profile Compile Times](#profile-compile-times)
46+
- [Troubleshoot Slow Incremental Builds](#troubleshoot-slow-incremental-builds)
4647
- [Replace Heavy Dependencies](#replace-heavy-dependencies)
4748
- [Split Big Crates Into Smaller Ones Using Workspaces](#split-big-crates-into-smaller-ones-using-workspaces)
4849
- [Disable Unused Features Of Crate Dependencies](#disable-unused-features-of-crate-dependencies)
@@ -245,6 +246,28 @@ $ cargo llvm-lines | head -20
245246
284 (0.9%) 4 (0.4%) core::option::Option<T>::ok_or_else
246247
```
247248

249+
### Troubleshoot Slow Incremental Builds
250+
251+
If your incremental builds are slower than expected, you might be bottlenecked on a particular crate in the rustc backend.
252+
253+
To diagnose this, you can use [`samply`](https://github.com/mstange/samply) combined with the `-Zhuman_readable_cgu_names=yes` flag to profile the compiler and identify which codegen units are taking the longest to compile:
254+
255+
```bash
256+
samply record cargo build
257+
```
258+
259+
This will help you identify if a particular crate is the long pole in your build. Once you've identified the bottleneck, you may be able to improve compile times by refactoring or splitting the problematic crate.
260+
261+
For more details on back-end parallelism in the Rust compiler, see [Nicholas Nethercote's blog post](https://nnethercote.github.io/2023/07/11/back-end-parallelism-in-the-rust-compiler.html).
262+
263+
Another useful flag is `-Zprint-mono-items=yes`, which prints all [monomorphized items](https://rustc-dev-guide.rust-lang.org/backend/monomorph.html) during compilation. This can help you understand what's being generated in each CGU.
264+
265+
```sh
266+
RUSTFLAGS="-Zprint-mono-items=yes" cargo +nightly build ⏎
267+
```
268+
269+
_Thanks to [Caspar](https://slowrush.dev) (asparck on [Reddit](https://www.reddit.com/r/rust/comments/1q8x25s/debugging_a_slowcompiling_codegen_unit/)) for this tip!_
270+
248271
### Replace Heavy Dependencies
249272

250273
From time to time, it helps to shop around for more lightweight alternatives to

0 commit comments

Comments
 (0)