What Is Link-Time Optimization (LTO) in Rust?

Link-Time Optimization (LTO) in Rust optimizes the entire program at the linking stage to improve performance and reduce binary size.

Link-Time Optimization (LTO) in Rust allows the compiler to optimize code across crate boundaries during the final linking stage, often resulting in smaller binaries and faster execution. Enable it in your Cargo.toml under the [profile.release] section:

[profile.release]
lto = true

Alternatively, enable it for a specific build using the RUSTFLAGS environment variable:

RUSTFLAGS="-C lto" cargo build --release