The --timings
option gives some information about how long each compilation takes, and tracks concurrency information over time.
cargo build --timings
This writes an HTML report in target/cargo-timings/cargo-timing.html
. This also writes a copy of the report to the same directory with a timestamp in the filename, if you want to look at older runs.
There are two graphs in the output. The “unit” graph shows the duration of each unit over time. A “unit” is a single compiler invocation. There are lines that show which additional units are “unlocked” when a unit finishes. That is, it shows the new units that are now allowed to run because their dependencies are all finished. Hover the mouse over a unit to highlight the lines. This can help visualize the critical path of dependencies. This may change between runs because the units may finish in different orders.
The “codegen” times are highlighted in a lavender color. In some cases, build pipelining allows units to start when their dependencies are performing code generation. This information is not always displayed (for example, binary units do not show when code generation starts).
The “custom build” units are build.rs
scripts, which when run are highlighted in orange.
The second graph shows Cargo's concurrency over time. The background indicates CPU usage. The three lines are:
Note: This does not show the concurrency in the compiler itself. rustc
coordinates with Cargo via the “job server” to stay within the concurrency limit. This currently mostly applies to the code generation phase.
Tips for addressing compile times: