Enable PGO for Linux x86-64 Ruff releases - #27570
Draft
charliermarsh wants to merge 5 commits into
Draft
Conversation
|
chirizxc
reviewed
Aug 7, 2026
Comment on lines
+243
to
+254
| - name: "Install LLVM profiling tools" | ||
| if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }} | ||
| run: rustup component add llvm-tools-preview | ||
| - name: "Train PGO Ruff" | ||
| if: ${{ matrix.target == 'x86_64-unknown-linux-gnu' }} | ||
| run: | | ||
| python scripts/build_ruff_pgo.py \ | ||
| --target "${{ matrix.target }}" \ | ||
| --target-dir "${{ github.workspace }}/target/ruff-pgo" \ | ||
| --train-only | ||
|
|
||
| echo "RUSTFLAGS=${RUSTFLAGS:+${RUSTFLAGS} }-Cprofile-use=${{ github.workspace }}/target/ruff-pgo/ruff.profdata" >> "$GITHUB_ENV" |
Contributor
There was a problem hiding this comment.
As I understand it, we can also add i686-pc-windows-msvc, x86_64-pc-windows-msvc, aarch64-apple-darwin, x86_64-apple-darwin, aarch64-unknown-linux-gnu, and i686-unknown-linux-gnu
Contributor
Member
Author
There was a problem hiding this comment.
Thanks, yes they would all be covered. This is just experimental right now to gather data.
charliermarsh
force-pushed
the
charlie/ruff-pgo-prototype
branch
from
August 7, 2026 20:31
ff08211 to
a752a11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable LLVM instrumentation-based profile-guided optimization (PGO) for native Linux x86-64 Ruff release builds. This runs alongside the existing fat LTO; it does not use LLVM BOLT. We build an instrumented, stripped release binary, train
checkandformaton an immutable corpus of real Python ecosystem projects, merge the profiles with the active Rust toolchain'sllvm-profdata, and feed the result into the existing maturin build. The optimized executable is reused for both the wheel and standalone archive.The training corpus contains 502 tracked Python and stub files totaling 5.67 MB:
src/_pytesthttpxfastapisrc/anyiosrc/pip/_internalastropy/units, excluding testsasyncio,collections, andrequestsstubsEach project is pinned to a validated, full Git commit SHA and fetched over HTTPS using shallow, blob-filtered sparse checkouts. We disable Git hooks, avoid installing dependencies or executing project code, skip tests and vendored dependencies, retry transient Git failures, and include only clean tracked source files. Existing checkouts must retain their expected HTTPS origin and are restored to their pinned revisions before reuse.
The dependency-free helper declares its Python requirements with PEP 723 inline metadata. Lint and formatter workloads produce separately labeled profiles, and both must contain complete data before their profiles are atomically merged.
The training corpus matches ty's eight pinned ecosystem projects and excludes Prefect, which is reserved for ty's official benchmark suite. The projects do not overlap Ruff's Criterion benchmark fixtures or the held-out Django, pandas, scikit-learn, SciPy, and SymPy evaluation projects. The helper rejects cross-target execution, preserves existing Rust flags, and avoids mismatched Apple-clang profiling when run locally on macOS. Other release targets are unchanged.
Linux x86-64 performance
Compared production non-PGO and PGO release binaries with identical Ruff 0.16.2 source, all 32 runtime workspace crates,
Cargo.lock, Rust toolchain, and release configuration. Benchmarks covered 5,396 held-out Python and stub files totaling 90.57 MB and ran on eight distinct physical AMD EPYC cores with three warmups and twelve alternating baseline/PGO pairs per workload.ruff checkruff formatAcross all ten workloads, wall time improved by 11.2% and CPU time improved by 14.3%. PGO won 117 of 120 wall-time comparisons and all 120 CPU-time comparisons. The stripped Linux binary decreased from 27.96 MB to 26.23 MB, a 6.2% reduction. The non-PGO release build took 7m22s; the PGO pipeline took 15m14s (8m35s instrumented training plus 6m39s optimized wheel), an increase of 7m52s or 2.07×.
A follow-up comparison of the original nine-project corpus and the aligned eight-project corpus used production macOS ARM64 binaries, the same five held-out projects, and 12 alternating pairs. Performance was effectively unchanged: the eight-project corpus was 0.16% faster in wall time and used 0.12% less CPU; its standalone release archive was 0.10% larger.
Related to #7055.