feat(perf): v1.19.0 "Afterburner" - PGO/BOLT pipeline#109
Conversation
Adds scripts/pgo/run.sh (instrument -> train against the committed permissive ROM corpus via a new pgo_trainer binary -> optimized rebuild) and .github/workflows/pgo.yml (workflow_dispatch + release- tag push only; promotion requires both a >3% Criterion speedup and a byte-identical --features test-roms re-run under the PGO profile, an optional Linux-only BOLT post-link stage). Also fixes a real latent CI gap: rust-toolchain.toml was missing llvm-tools-preview, which dtolnay/rust-toolchain silently ignores as a composite-action input whenever the toolchain file exists (same class of bug already found and fixed for ios.yml in v1.16.0). Verified for real: the full instrument/train/optimized-rebuild pipeline produces a genuine running rustysnes binary, and the determinism oracle passes cleanly under the PGO-merged profile.
There was a problem hiding this comment.
Code Review
This pull request introduces a Profile-Guided Optimization (PGO) and BOLT pipeline for the shipping rustysnes binary, adding a new training-workload binary (pgo_trainer.rs), a runner script (scripts/pgo/run.sh), documentation updates, and adding llvm-tools-preview to rust-toolchain.toml. The review feedback correctly points out that on standard Rust setups, cargo build compiles binaries directly into target/release/ rather than target//release/, which would cause the runner script to fail with a 'No such file or directory' error. The reviewer provides robust fallback suggestions to dynamically resolve these paths.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds an opt-in Profile-Guided Optimization (PGO) + optional BOLT pipeline for the shipping rustysnes binary, including a dedicated CI workflow to build, benchmark (A/B), and enforce the project’s byte-identical determinism contract before any optimized artifact is considered promotable.
Changes:
- Introduces a local PGO driver script (
scripts/pgo/run.sh) and a committed-ROM training binary (pgo_trainer) to generate representative profiles deterministically from the permissive ROM corpus. - Adds a dedicated GitHub Actions workflow (
pgo.yml) that runs only on manual dispatch or release tags and gates promotion on both speedup (>3%) and a full--features test-romsbyte-identical oracle. - Updates toolchain/docs/changelog to document and support the pipeline (including adding
llvm-tools-previewto the pinned toolchain components).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/pgo/run.sh | Local instrument → train → optimized rebuild recipe for rustysnes using committed ROMs. |
| rust-toolchain.toml | Adds llvm-tools-preview to the pinned toolchain components for profiling tooling support. |
| docs/performance.md | Documents the new PGO/BOLT pipeline and the CI promotion criteria (speed + determinism). |
| crates/rustysnes-test-harness/src/bin/pgo_trainer.rs | Adds a training workload binary that runs multiple committed permissive ROMs for profile breadth. |
| CHANGELOG.md | Records the new pipeline and the CI/toolchain gap fix under Unreleased. |
| .github/workflows/pgo.yml | Adds the non-PR-gated CI workflow implementing the PGO promotion gate and optional BOLT stage. |
Real bug found in review: re-invoking scripts/pgo/run.sh between cargo pgo bolt build and cargo pgo bolt optimize ran a separate, non-BOLT PGO cycle that never fed BOLT's profile and could clobber the bolt-instrumented binary. Fixed per cargo-pgo's own documented BOLT+PGO workflow: --with-pgo on both calls, profile gathering skipped (cargo-pgo's own documented fallback) since driving the frontend's GUI binary for real workload coverage needs a display this project's frontend has no headless mode for.
Summary
scripts/pgo/run.sh: instrument → train against the committed permissive ROM corpus (viaa new
crates/rustysnes-test-harness/src/bin/pgo_trainer.rsbinary — thegilyonCPU-instruction suite plus a handful of
undisbelieverHDMA-glitch/INIDISP-hammer ROMs forcontrol-flow breadth beyond the single steady-state
headless_framebench ROM) → optimizedrebuild of the shipping
rustysnesbinary..github/workflows/pgo.yml:workflow_dispatch+ release-tag push only — never the PRgate, since an instrument+train+rebuild cycle is far too slow for that. Promotion requires
both: a measured
>3%Criterion speedup over the plain release build on the same runner,and a byte-identical re-run of the full
--features test-romsoracle under the PGO-mergedprofile (cites
docs/adr/0004's determinism contract — never promotes on speed alone). Anoptional Linux-only BOLT post-link stage chains onto an already-promoted PGO binary,
best-effort.
rust-toolchain.tomldidn'tlist
llvm-tools-preview, anddtolnay/rust-toolchainsilently ignores therust-setupcomposite action's own
components:input whenever arust-toolchain.tomlfile exists (thesame class of bug already found and fixed for
ios.ymlinv1.16.0) — without this fix,cargo-pgo's.profraw/.profdatamerging would have silently failed to find the componenton a fresh CI runner.
Test plan
cargo test --workspace --exclude rustysnes-android— all greencargo clippy --workspace --exclude rustysnes-android --all-targets -- -D warnings— cleancargo fmt --check— cleanRUSTDOCFLAGS="-D warnings" cargo doc --workspace --exclude rustysnes-android --no-deps— cleancargo build -p rustysnes-core --target thumbv7em-none-eabihf --no-default-features— no_std gate greencargo deny check/cargo audit— cleanactionlint .github/workflows/pgo.yml— cleanscripts/pgo/run.sh 60produces a genuine, runningPGO-optimized
rustysnesbinary (instrument build →pgo_trainerover all 5 committed ROMs →optimized rebuild).
cargo pgo optimize test -- -p rustysnes-test-harness --release --features test-romspasses cleanly under the PGO-merged profile (goldenframebuffers, SA-1/Super FX on-cart boots, save-state determinism/backward-compat, SPC700
oracle all pass).
headless_frame_steady_state— documentedhonestly in
docs/performance.md(short local training run did not clear the>3%bar; thisis expected, not a bug — CI's real
3600-frame sweep is what the promotion gate actuallydecides on).
🤖 Generated with Claude Code