Skip to content

perf: reduce preprocessing copies and add PGO replay tooling - #220

Merged
cruskell merged 3 commits into
mainfrom
codex/reduce-preprocessor-copies-pgo
Oct 24, 2026
Merged

cruskell merged 3 commits into
mainfrom
codex/reduce-preprocessor-copies-pgo

Conversation

@cruskell

@cruskell cruskell commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Native preprocessing copied cached directive tokens and repeatedly cloned macro argument and token-paste inputs. Borrow cached directives until line remapping requires a copy, record argument uses when defining macros, and move expanded tokens on their last use. Regression coverage preserves #line locations across shared headers, raw spelling for #/##, and single evaluation of repeated __COUNTER__ arguments.

Add tools/benchmarks/pgo.py to replay recorded C compilations, collect and merge profiles with the selected Rust toolchain, and produce an optional PGO compiler without replacing the normal release binary. Document the workflow and five reproducible benchmark experiments.

Validation on Linux x86_64 with Rust 1.86.0 and Clang 15:

  • cargo fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test: 52 library tests, 2,105 integration tests, one doctest passed; two integration tests ignored.
  • All 18 mixed-corpus evaluation builds passed application smoke checks, including verified HTTPS for curl, repository operations for Git, and commands/Lua for Redis.

The copy changes reduced batch dependency-scan allocation requests by 16% and median elapsed time by 6.4%. The additional PGO corpus experiment compared the preserved curl-only compiler (477 training compilations) with curl/Git/Redis training (1,229 compilations):

Application Curl-only PGO median Mixed PGO median
Curl 8.23.0 25.90 s 25.88 s
Git v2.56.0 49.44 s 49.36 s
Redis 8.10.2 19.15 s 19.02 s

Curl/Git differences are smaller than run-to-run variation; Redis shows a small improvement. Full conditions, raw samples and compiler hashes are included. Benchmark binaries use the same 7804347-based source plus copy changes and predate newer record-member changes on main; the rebased PR has been retested, but these timings do not measure its newer base. macOS/AArch64 were not measured locally. Profiles and binaries remain ignored local artifacts.

The saved mixed-corpus PGO compiler was also remeasured against installed Clang 15.0.7, with three clean builds per compiler/application at -O2 -g0, make -j4, using Dynamite's default external Clang IR backend. The earlier -O0/LLVM-tools-backend results are a separate configuration.

Application Mixed PGO median Clang median Build-time reduction
Curl 8.23.0 25.99 s 26.51 s 1.96%
Git v2.56.0 49.10 s 52.99 s 7.34%
Redis 8.10.2 19.06 s 23.10 s 17.52%

All 18 additional builds and application smoke checks passed. Conditions and raw samples and a JSON snapshot include commands, hashes and validation. This uses the same saved 7804347-based PGO binary as above; it does not measure the rebased head or executable runtime performance. Curl shares one Dynamite-generated configuration between compilers. Only reports changed in this follow-up; snapshot arithmetic, report links and git diff --check were verified.

A matching -O0 -g0 comparison keeps the saved compiler binaries, default Clang backend and make -j4 parallelism fixed:

Application Mixed PGO -O0 median Clang -O0 median Build-time reduction
Curl 8.23.0 18.42 s 19.90 s 7.44%
Git v2.56.0 31.63 s 34.82 s 9.16%
Redis 8.10.2 8.35 s 11.76 s 28.97%

All 18 additional builds and smoke checks passed. The -O0 report preserves every sample and compares -O0 with the previous -O2 session. The first Clang curl build (28.53 s) and first PGO Redis build (11.63 s) had substantial wall-time variation; those samples are retained and their cause was not isolated. The prior 10.73 s Redis result used a different Dynamite revision and LLVM tools backend, so it is not a direct PGO comparison. No compiler code changed; compiler hashes, build options, snapshot arithmetic, report links and diff formatting were checked.

@cruskell
cruskell merged commit 237ebe3 into main Oct 24, 2026
4 checks passed
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