Add BOLT optimization to PGO Ruff releases - #27571
Closed
charliermarsh wants to merge 4 commits into
Closed
Conversation
|
charliermarsh
force-pushed
the
charlie/ruff-pgo-prototype
branch
from
August 7, 2026 20:31
ff08211 to
a752a11
Compare
Member
Author
|
Closing this BOLT prototype so the release optimization stack remains focused on PGO. |
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.
Previous Linux x86-64 measurements
The earlier version of this PR compared matching PGO and PGO+BOLT binaries on five held-out projects using eight physical AMD EPYC cores, five warmup pairs, and 30 alternating baseline/candidate pairs per workload. Those measurements used the previous nine-project training corpus; this rebased version uses the current shared eight-project corpus and should be remeasured.
ruff checkruff formatAcross all ten workloads, BOLT improved wall time by 1.45% and CPU time by 2.04% beyond compiler PGO. The effect is smaller than compiler PGO because PGO and fat LTO already optimize the same workload: BOLT's dynamic statistics showed only 0.7% fewer executed instructions, while loads, stores, and function-call counts were unchanged. BOLT reduced taken conditional branches by 21.9%, but that mostly improves layout rather than eliminating work.
BOLT added approximately 45 seconds of post-link work. The earlier compact rewrite had 65 KB of remaining text-section capacity; the release 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%.