Profile Guided Optimization (PGO) in Rust is enabled by building a profile, running your application to collect data, and then rebuilding with that profile. First, build your binary in profile mode to generate instrumentation:
rustup default nightly
cargo build --profile=perf
Next, run your application to generate profiling data in the target directory:
./target/perf/your_binary
Finally, rebuild your binary using the collected profile data for optimized code generation:
cargo build --profile=perf --release
Ensure your Cargo.toml defines the perf profile with codegen-backend and profile settings if not using the default nightly PGO support.