Skip to content

Add BOLT optimization to PGO Ruff releases - #27571

Closed
charliermarsh wants to merge 4 commits into
charlie/ruff-pgo-prototypefrom
charlie/ruff-bolt-prototype
Closed

Add BOLT optimization to PGO Ruff releases#27571
charliermarsh wants to merge 4 commits into
charlie/ruff-pgo-prototypefrom
charlie/ruff-bolt-prototype

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Aug 7, 2026

Copy link
Copy Markdown
Member

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 check and ruff format on 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-pages to 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's llvm-strip, and atomically rebuilds wheel RECORD entries. 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.

Held-out project ruff check ruff format
Django 1.1% faster 1.8% faster
pandas 1.2% faster 2.4% faster
scikit-learn 1.3% faster 2.5% faster
SciPy 0.9% slower 1.8% faster
SymPy 0.6% faster 2.6% faster
Geometric mean 0.7% faster 2.2% faster

Across 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.

Artifact PGO PGO + BOLT Increase
Stripped executable 26.10 MB 26.62 MB 2.0%
Compressed release archive 10.54 MB 10.92 MB 3.6%

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%.

@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh

Copy link
Copy Markdown
Member Author

Closing this BOLT prototype so the release optimization stack remains focused on PGO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant