|
| 1 | +# Reporting build timings |
| 2 | +The `--timings` option gives some information about how long each compilation |
| 3 | +takes, and tracks concurrency information over time. |
| 4 | + |
| 5 | +```sh |
| 6 | +cargo build --timings |
| 7 | +``` |
| 8 | + |
| 9 | +This writes an HTML report in `target/cargo-timings/cargo-timings.html`. This |
| 10 | +also writes a copy of the report to the same directory with a timestamp in the |
| 11 | +filename, if you want to look at older runs. |
| 12 | + |
| 13 | +#### Reading the graphs |
| 14 | + |
| 15 | +There are two graphs in the output. The "unit" graph shows the duration of |
| 16 | +each unit over time. A "unit" is a single compiler invocation. There are lines |
| 17 | +that show which additional units are "unlocked" when a unit finishes. That is, |
| 18 | +it shows the new units that are now allowed to run because their dependencies |
| 19 | +are all finished. Hover the mouse over a unit to highlight the lines. This can |
| 20 | +help visualize the critical path of dependencies. This may change between runs |
| 21 | +because the units may finish in different orders. |
| 22 | + |
| 23 | +The "codegen" times are highlighted in a lavender color. In some cases, build |
| 24 | +pipelining allows units to start when their dependencies are performing code |
| 25 | +generation. This information is not always displayed (for example, binary |
| 26 | +units do not show when code generation starts). |
| 27 | + |
| 28 | +The "custom build" units are `build.rs` scripts, which when run are |
| 29 | +highlighted in orange. |
| 30 | + |
| 31 | +The second graph shows Cargo's concurrency over time. The background |
| 32 | +indicates CPU usage. The three lines are: |
| 33 | +- "Waiting" (red) — This is the number of units waiting for a CPU slot to |
| 34 | + open. |
| 35 | +- "Inactive" (blue) — This is the number of units that are waiting for their |
| 36 | + dependencies to finish. |
| 37 | +- "Active" (green) — This is the number of units currently running. |
| 38 | + |
| 39 | +Note: This does not show the concurrency in the compiler itself. `rustc` |
| 40 | +coordinates with Cargo via the "job server" to stay within the concurrency |
| 41 | +limit. This currently mostly applies to the code generation phase. |
| 42 | + |
| 43 | +Tips for addressing compile times: |
| 44 | +- Look for slow dependencies. |
| 45 | + - Check if they have features that you may wish to consider disabling. |
| 46 | + - Consider trying to remove the dependency completely. |
| 47 | +- Look for a crate being built multiple times with different versions. Try to |
| 48 | + remove the older versions from the dependency graph. |
| 49 | +- Split large crates into smaller pieces. |
| 50 | +- If there are a large number of crates bottlenecked on a single crate, focus |
| 51 | + your attention on improving that one crate to improve parallelism. |
0 commit comments