Repository navigation
Enable BOLT for Linux x86-64 Ruff releases - #27588
Closed
charliermarsh wants to merge 3 commits into
Closed
charliermarsh wants to merge 3 commits into
charliermarsh wants to merge 3 commits into
Conversation
|
charliermarsh
force-pushed
the
charlie/ruff-bolt-prototype
branch
from
August 10, 2026 14:11
453e492 to
f83832c
Compare
charliermarsh
force-pushed
the
charlie/ruff-bolt-prototype
branch
from
August 10, 2026 14:52
f83832c to
ade5540
Compare
charliermarsh
force-pushed
the
charlie/ruff-bolt-prototype
branch
from
August 10, 2026 14:55
ade5540 to
3deb129
Compare
charliermarsh
added a commit
that referenced
this pull request
Aug 10, 2026
## Summary This PR enables PGO for Ruff releases, starting with Linux x86-64. ### Design The release pipeline is modified as follows: - We build an instrumented, stripped release binary. - We run `check` and `format` on a corpus of projects from our ecosystem reports -- specifically, eight of the pinned ecosystem projects that we use in the ty CI. (In total, it's 502 Python and stub files.) - We merge the profiles via `llvm-profdata`. - We feed the result back into the existing `maturin` build. ### Results We evaluate performance on a held-out corpus: Prefect, Django, Pandas, scikit-learn, SciPy, and SymPy. Results are as follows: | Held-out project | `ruff check` | `ruff format` | | --- | ---: | ---: | | Django | 10.9% faster | 6.6% faster | | pandas | 16.3% faster | 9.7% faster | | scikit-learn | 10.8% faster | 7.9% faster | | SciPy | 14.7% faster | 5.6% faster | | SymPy | 17.1% faster | 11.4% faster | | Geometric mean | **14.0% faster** | **8.3% faster** | Beyond runtime: - **Binary size decreased by 6.2%** (27.96 MB to 26.23 MB). - **Release pipeline gets about 2x longer** (non-PGO release build took 7m22s; PGO pipeline took 15m14s (8m35s instrumented training plus 6m39s optimized wheel). ### Stack Additional platforms are covered in subsequent PRs in the stacked; platforms that are lower-priority at at-all difficult to run on natively are omitted. In the end, I'm targeting Linux x86-64, Linux ARM, macOS ARM, and Windows x86-64. I also attempted BOLT in #27588, but I've decided against pursuing that for now; see the results in that PR which speak for themselves. ty and uv will follow the same approach; see the stacks here: - astral-sh/ty#4213 - astral-sh/uv#21001 See: #7055.
charliermarsh
force-pushed
the
charlie/ruff-bolt-prototype
branch
from
August 10, 2026 15:56
3deb129 to
01e18ea
Compare
George-Ogden
pushed a commit
to George-Ogden/ruff
that referenced
this pull request
Aug 16, 2026
## Summary This PR enables PGO for Ruff releases, starting with Linux x86-64. ### Design The release pipeline is modified as follows: - We build an instrumented, stripped release binary. - We run `check` and `format` on a corpus of projects from our ecosystem reports -- specifically, eight of the pinned ecosystem projects that we use in the ty CI. (In total, it's 502 Python and stub files.) - We merge the profiles via `llvm-profdata`. - We feed the result back into the existing `maturin` build. ### Results We evaluate performance on a held-out corpus: Prefect, Django, Pandas, scikit-learn, SciPy, and SymPy. Results are as follows: | Held-out project | `ruff check` | `ruff format` | | --- | ---: | ---: | | Django | 10.9% faster | 6.6% faster | | pandas | 16.3% faster | 9.7% faster | | scikit-learn | 10.8% faster | 7.9% faster | | SciPy | 14.7% faster | 5.6% faster | | SymPy | 17.1% faster | 11.4% faster | | Geometric mean | **14.0% faster** | **8.3% faster** | Beyond runtime: - **Binary size decreased by 6.2%** (27.96 MB to 26.23 MB). - **Release pipeline gets about 2x longer** (non-PGO release build took 7m22s; PGO pipeline took 15m14s (8m35s instrumented training plus 6m39s optimized wheel). ### Stack Additional platforms are covered in subsequent PRs in the stacked; platforms that are lower-priority at at-all difficult to run on natively are omitted. In the end, I'm targeting Linux x86-64, Linux ARM, macOS ARM, and Windows x86-64. I also attempted BOLT in astral-sh#27588, but I've decided against pursuing that for now; see the results in that PR which speak for themselves. ty and uv will follow the same approach; see the stacks here: - astral-sh/ty#4213 - astral-sh/uv#21001 See: astral-sh#7055.
4 tasks
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
Add post-link LLVM BOLT optimization to the existing Linux x86-64 Ruff release build after compiler PGO and fat LTO. This is stacked on #27574; macOS, Windows, Linux ARM64, and all other targets remain compiler-PGO-only or retain their existing release behavior.
The manylinux build preserves symbols and linker relocations, then instruments the linked executable and trains
ruff checkandruff formaton the same eight immutable ecosystem projects already used by Ruff and ty PGO. BOLT reorders hot functions and basic blocks using the collected binary profile.The optimized executable uses
--use-old-text --no-huge-pagesto reuse the original code section instead of publishing BOLT's much larger default duplicate-text layout. The helper requires in-place rewriting to succeed, preserves GNU stack and RELRO hardening, smoke-tests the result, strips with the Rust toolchain'sllvm-strip, and atomically rebuilds wheelRECORDentries. The wheel and standalone archive contain the same optimized binary.LLVM BOLT 22 and its instrumentation runtime are fetched from the official LLVM repository with pinned SHA-256 digests. The dependency-free helper follows the same PEP 723 script conventions as the compiler-PGO helper.
Linux x86-64 production-artifact measurements
Compared the actual standalone release binaries uploaded by this PR and its immediate PGO-only parent. Both contain identical Ruff 0.16.2 sources, the same Rust toolchain and manylinux build configuration, and the current shared eight-project PGO corpus. Benchmarks covered 5,396 held-out Python and stub files totaling 90.57 MB and used eight physical AMD EPYC cores, three warmup pairs, and 20 alternating baseline/candidate pairs per workload.
ruff checkruff formatAcross all ten workloads, BOLT improves wall time by 1.24% and CPU time by 1.91% beyond compiler PGO. Paired bootstrap confidence intervals are 0.36–1.75% for wall time and 1.59–2.03% for CPU time. The BOLT binary won 133 of 200 wall-time comparisons and 184 of 200 CPU-time comparisons.
The effect is smaller than compiler PGO because PGO and fat LTO already optimize the same workload: BOLT's production dynamic statistics show only 0.7% fewer executed instructions, while loads, stores, and function-call counts remain unchanged. BOLT reduces taken conditional branches by 22.5%, but that mostly improves layout rather than eliminating work.
Additional no-build BOLT strategy comparisons did not uncover a better compact layout:
hfsort+produced a byte-for-byte identical executable,profile2increased compressed size by another 4.10%, disabling function splitting increased executable size by 1.89%, and--litecould not satisfy the required in-place rewrite..tar.gzBOLT successfully rewrites executable code in-place but still appends regenerated exception/unwind metadata and jump-table data: the new
.gcc_except_table,.eh_frame_hdr, and relocated.rodataaccount for nearly all executable growth. The production rewrite has 73 KB of remaining text-section capacity and adds 45 seconds to the release job. It fails if a future binary cannot fit rather than silently using a much larger fallback layout.ARM64 BOLT remains intentionally disabled: the previous ARM experiment inserted 24,430 branch-range stubs, increased the executable by 11.2%, and improved wall time by only 0.08%.