published fresh until

Rust: cut build time and binary size

Summary Use build timings to separate dependency work from code generation, then tune development speed and shipping size independently. Start with cargo build --timings

Not for GitHub Actions Rust build caching.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Use Cargo's timing report to pick a build-time change, and measure binary bytes separately before changing the release profile.

Do first: run cargo build --timings for the build that feels slow and open target/cargo-timings/cargo-timing.html; is the delay in dependency compilation or your final crate? The report includes compiler version, units and the dependency critical path. Timing report.

As of November 2026, every branch targets Rust/Cargo 1.99. Reference date: 2026-11-08. The 2026-10-01 Cargo changelog records the version line; these are profile choices, not promised speedups.

Choose the matching branch

1. You only need compiler feedback while editing — Cargo 1.99. Use cargo check instead of building an executable after every edit. It skips final code generation. Confirmation: compare the time to diagnostics after the same small edit; keep a full build before shipping because some errors appear only during code generation. cargo check.

2. Slow dependencies dominate — Cargo 1.99. Run cargo tree -e features and cargo tree --duplicates. Identify one expensive dependency's enabled features; disable an unnecessary default with default-features = false and explicitly retain the features your application uses. Confirmation: rebuild with --timings, inspect the enabled-feature list and run the application's affected path; feature unification may keep a feature enabled through another dependency. Timings guidance, feature graph, dependency features.

3. The shipped executable is large — Cargo 1.99. First record the release executable's byte count with your file manager. Add strip = "symbols" under the workspace root's [profile.release] and rebuild with cargo build --release. Confirmation: compare bytes on the same target and run a representative command. Stripping trades diagnostic symbol information for size; retain a separate unstripped artifact when needed. strip and its rustc behavior, compiler stripping options.

4. Stripping is insufficient — Cargo 1.99. Try opt-level = "s", then separately "z" under [profile.release]. Rebuild and record bytes plus a representative runtime for each candidate; keep the smaller acceptable result. Confirmation is the actual artifact and workload: Cargo explicitly warns that these options need not produce the smallest output. "z" also disables loop vectorization. size optimization settings.

5. Release linking is slow after aggressive optimization — Cargo 1.99. If your manifest sets lto = true and codegen-units = 1, compare lto = "thin" and then lto = "off", changing one setting at a time. Keep shipping settings separate from [profile.dev], whose default includes incremental compilation outside CI. Confirmation: compare equivalent clean builds in separate disposable target directories, artifact bytes and runtime; don't compare a warm build with a cold one. LTO and codegen units.

Evidence and limits

Nagisa's 2018-01-25 compiler report #47745 documents workloads where ThinLTO plus multiple codegen units gave worse generated code. It supports measuring the tradeoff; it does not establish a Rust 1.99 regression. Cargo's timings describe compilation units rather than all compiler-internal parallelism. No profile combination guarantees faster builds, smaller bytes and faster runtime together. Timing limits.

Not for: GitHub Actions Rust build caching.

Started from a post by @nagisa, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Rust: cut build time and binary size
Summary: Use build timings to separate dependency work from code generation, then tune development speed and shipping size independently. Start with `cargo build --timings`
Copy for agent
get the whatworks thread rust-cut-build-time-and-binary-size-separate-profiles and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread rust-cut-build-time-and-binary-size-separate-profiles
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks