PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutecodegen-units and link-time optimization (LTO) control different parts of Rust’s build pipeline, so neither is a universal replacement for the other. For release builds, compare the settings that fit your goal: more codegen units can help compile time through parallelism, while ThinLTO is a practical first LTO option to benchmark for runtime gains. Choose based on measured build, link, and workload results—not a general rule.
What each setting changes
Codegen units control parallel code generation
The rustc option -C codegen-units, configured in Cargo with codegen-units, sets the maximum number of code-generation units into which a crate is split. LLVM can process multiple units in parallel. That may shorten compilation, but can reduce optimization opportunities and produce slower code. Setting the value to 1 removes that code-generation parallelism and may improve generated-code performance, at the cost of potentially slower compilation. Neither outcome is guaranteed for every project or machine. The Rust Project’s Codegen Options documentation summarizes the tradeoff: “Increasing parallelism may speed up compile times, but may also produce slower code.”
LTO optimizes at link time
LTO lets LLVM optimize code with broader program information during linking. Rust supports fat and thin LTO modes, as well as disabled LTO. Fat LTO attempts optimization across crates in the dependency graph and can add link time. The Rust Project describes ThinLTO as substantially faster than fat LTO while providing similar performance gains. For large projects such as the Rust compiler, its documentation notes ThinLTO can even perform better than fat LTO; that is a documented observation, not a promise for your application. See the rustc LTO documentation.
Understand what “LTO off” means in Cargo
Rust’s defaults make this terminology easy to misread. If rustc’s -C lto is unspecified, it can perform thin local LTO across codegen units within the local crate. That is not cross-crate LTO, and it is disabled when codegen-units is 1 or opt-level=0. Cargo’s lto = false likewise allows thin local LTO; use lto = "off" to disable LTO. The Cargo Book documents these profile behaviors and defaults in Profiles.
#1 Best Overall
Profile context matters too. Cargo documents defaults of 16 codegen units for non-incremental builds and 256 for incremental builds. Its development profile enables incremental compilation by default and uses 256 codegen units. Do not assume a build is using the same settings as another just because neither command line mentions them: compare the effective Cargo profile, including optimization level, incremental compilation, codegen units, and LTO.
Which settings should you benchmark?
| Goal or situation | A sensible starting point | What to measure |
|---|---|---|
| Faster edit/build iteration | Keep the normal development profile and its parallel code generation unless measurements show that another setting addresses your bottleneck. | Incremental rebuild time and clean build time. |
| Release runtime performance | Benchmark ThinLTO against your existing release profile first. Try fat LTO only if it gives a measurable benefit worth its extra link cost. | Link time and runtime on the target workload. |
Considering codegen-units = 1 |
Test it separately, then in combination with the LTO mode you intend to ship. | Compile and link time, plus the runtime metric that matters to the application. |
| Rust linked with C or C++ | Check whether linker-plugin LTO is appropriate and whether every participating toolchain and the linker meet its requirements. | Compatibility and whether the native dependencies are actually included in the optimization. |
These are starting points, not measured results for your program. Change one setting at a time where possible and benchmark combinations that could ship. Hold the Rust toolchain, target, dependencies, hardware, optimization level, and workload constant. Record clean compile time separately from link time; then measure runtime or binary size if that is the reason for changing the build. The official documentation describes the tradeoffs but does not establish a universal application-independent winner.
Rank #2
When Rust and C/C++ share a build
Ordinary Rust LTO settings do not automatically mean that C or C++ dependencies participate in whole-program optimization. Rust’s linker-plugin LTO can support Rust static libraries used from C/C++, or C/C++ dependencies linked into Rust, but it adds compatibility requirements: participating objects must come from LLVM-based toolchains, use matching thin or fat LTO modes, and be linked with a linker that supports the LLVM plugin. Consult the Rust Project’s linker-plugin LTO documentation before configuring a mixed-language build.
Compatibility detail: embedded bitcode
LLVM bitcode is required when rustc performs LTO. The rustc documentation states that combining -C embed-bitcode=no with -C lto is invalid and causes compilation to abort. Cargo manages the related rustc options through the profile’s lto setting; see Codegen Options and Cargo Profiles.
Rank #3
Keep rustc-specific LTO results in context
The Rust Compiler Development Guide reports speed-ups of up to 10% from enabling LTO when building rustc on Linux. That figure concerns the Rust compiler itself, not arbitrary Rust applications. The guide says this configuration is currently supported and tested only on x86_64-unknown-linux-gnu, makes no guarantees for other targets, and warns that LTO-optimized rustc produces miscompilations on Windows. Read the scoped guidance in Optimized build of the compiler rather than treating the reported figure as an expected application gain.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




