Repository navigation
Build the Linux releases with PGO and ThinLTO - #8649
Conversation
f884c79 to
4913c55
Compare
4913c55 to
d4e0b3c
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
a28fb7d to
8f337a9
Compare
extra_rustc_flag can pass rustc a flag that names a file, such as
-Cprofile-use=<profile>, but nothing adds that file to the Rustc
action's inputs, so rustc can't read it in a sandbox or on a remote
executor. The extra_rustc_inputs label flag adds its files to every
target-configuration Rustc action, as extra_rustc_flag adds its
flags, and ${extra_rustc_inputs} in an extra flag stands for the
path of its file, so the flag needn't hardcode where Bazel puts it.
The PGO build uses it to give rustc the profile.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b8e227e to
8a12947
Compare
The tests only do what `workerd test` does: start a Worker and hand it a few events. A profile trained on them alone wouldn't see the HTTP server, or a Worker handling one request after another. This test runs `workerd serve` of a few Workers, a sync and an async hello world and one that uses a mix of the APIs real Workers use, and sends each many requests from concurrent clients, checking every response so that a broken Worker fails the test rather than training the profile on error paths. It starts workerd through WorkerdServerHarness, which gains options to leave out the inspector and --verbose, as production does. Normally it sends 50 requests per path. Under the PGO training wrapper, which sets WORKERD_PGO_TRAINING, it sends 10,000 to 40,000. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Callers find CapTableReader and CapTableBuilder with dynamic_cast, and neither had a virtual function defined out of line, so every library that used them emitted its own copy of their type info. A dynamically linked test built with ThinLTO keeps its executable's copy apart from the library's, and frankenvalue-test's dynamic_cast then failed. Their destructors, now defined in frankenvalue.c++, make the type info a single definition there. CapTableBuilder's base, jsg::Serializer::ExternalHandler, gets the virtual destructor that jsg::Deserializer::ExternalHandler already has, so that CapTableBuilder's destructor is virtual too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test's getter recurses until the stack runs out, catching the overflow at each level, so it returns arrays nested about as deep as the stack allows. Whether structuredClone() can then serialize them depends on how much stack each level of the serializer takes, which the PGO build changes: there it throws a RangeError. That isn't the crash the test guards against, so the test accepts it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8a12947 to
8a695db
Compare
#8649's branch was rebased onto a newer main. Its own versions of the PGO workload, server harness and README win; the README keeps this branch's Windows section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Superseded by the review of
a0e2211f.
This review, of 8a695db6
💬 Approved with comments — No blocking or warning-level issues. One INFO note: the x64 release CI job in cfsetup.yaml now builds with ThinLTO and PGO and needs the profile from GitHub.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 1 info
No correctness bugs. One note about another CI job that the new release_linux config now affects.
Recommendation: 💬 Optional Nits
- [INFO]
cfsetup.yaml:26(ci-bazel-x64-release) uses--config=release_linux, so it now gets ThinLTO, PGO and a profile download from GitHub. The pull request doesn't mention this job. (.bazelrc:509)
View full review
release_linux now expands to thin-lto, rust-lto and pgo-use (.bazelrc:509-510). The ci-bazel-x64-release job in cfsetup.yaml:26 runs bazel test --config=release_linux //.... That job now does a ThinLTO link for every test and has to download @workerd_pgo_profile from a GitHub release asset. It also installs clang-22/lld-22 from apt, while the rust-lto comment says rustc and lld must share an LLVM major version. The pull request doesn't mention this job. Either confirm it works with the new config, or switch it to release_linux-without-pgo the way the types fallback in test.yml was switched.
Other checks found no problems:
- The out-of-line destructors in
frankenvalueand the virtual destructor added toExternalHandler. - The option plumbing in
server-harness.mjs. - The
test_targetexpression inrelease.yml. - Argument handling in
train.sh.
✅ All other checks passed
🚀 Release: ✅ LGTM
Overall risk: Medium. The Linux release binaries are now built with ThinLTO and PGO, which changes how the shipped artifacts are optimized. The pull request description says the whole suite and the serving workload pass on the PGO build. macOS and Windows release builds are unchanged.
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 8a695db6
release_linux, which the x64 and arm64 release builds use, now adds ThinLTO and Clang's instrumentation-based PGO, for the C++ code, V8 included, and the Rust code, which it compiles to bitcode so that the ThinLTO link optimizes both together. release_linux-without-pgo is the old release build, for comparisons. The profile isn't checked in. build/pgo/profile.json names it, an asset of the pgo-profiles GitHub release, with its hash, and Bazel downloads it. rustc gets it through rules_rust's extra_rustc_inputs, which also names its path in -Cprofile-use. build/pgo/train.sh trains a profile: it builds pgo-instrument, runs every test that runs the workerd binary under a wrapper that sets KJ_CLEAN_SHUTDOWN, so that workerd writes its profile, and merges each test's profiles, then merges them all, weighting the serving workload's. build/pgo/upload.sh uploads it and updates profile.json. The pgo-train workflow does both and opens a pull request; it runs only when someone starts it. release.yml already builds the release configuration on every push to main, publishing only the first build of each release version, so a deleted profile or a change that breaks the PGO build fails the merge that follows it. Its Linux builds now also run the serving workload on the PGO binary. The arm64 build uses the profile trained on x64: Clang matches it to the code in its architecture-independent form, and the arm64-specific code gets no profile data. macOS and Windows keep their release builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8a695db to
a0e2211
Compare
There was a problem hiding this comment.
Superseded by the review of
c14431d8.
This review, of a0e2211f
✅ Approved — The earlier note is fixed: the x64 release CI job now builds with release_linux-without-pgo. There are no other findings.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Overall risk: Medium. The Linux release binaries are now built with ThinLTO and PGO, which changes how the shipped artifacts are optimized. The pull request reports that the full test suite and the serving workload pass on the PGO build. macOS and Windows release builds are unchanged, and no version or changelog files change.
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
ci-bazel-x64-release (cfsetup.yaml:26) now uses --config=release_linux-without-pgo. Per .bazelrc:507-508, that is the old release build, so the job builds as it did before this pull request, with no ThinLTO links and no profile download.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: a0e2211f
$ Conflicts: $ cfsetup.yaml
There was a problem hiding this comment.
✅ Approved — No findings. The last review's one note (the x64 release CI job) stays fixed, and the merge from main brought no new issues.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Overall risk: Medium. The Linux release binaries (x64 and arm64) are now built with ThinLTO and PGO, which changes how the shipped binaries are optimized. According to the pull request, the full test suite (2,951 passed, 4 skipped) and the serving workload pass on the PGO build. macOS and Windows release builds are unchanged. No version or changelog files change.
🔒 Security: ✅ LGTM
No security issues in the changed code.
- Profile download:
build/pgo/profile.bzlrequires anintegrityhash when it downloads the profile.upload.shcomputes that hash and writes it intoprofile.json, which can only change on main through a pull request. pgo-train.yml: it runs only when started by hand (workflow_dispatch). It doesn't insert untrusted input into commands, and its token permissions are limited.- Secrets: no hardcoded secrets.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
No issues in the changed files.
- Release workflow test targets: in
release.yml, the Linuxtest_targetpasses two space-separated targets, and_bazel.ymlexpands them unquoted intobazel test, so both run. - Training scripts:
train.shandprofile-env.shmerge the weighted profiles consistently. They accept Bazel exit status 3 (some tests failed) and fail the run if the dense profile is missing. - Destructors: the out-of-line virtual destructors in
frankenvalue.handser.harenoexcept(false), which matches the existingDeserializerconvention. structuredCloneErrortest: it now also accepts aRangeErrorwhen cloning runs out of stack.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: c14431d8
The Linux release builds, x64 and arm64, now use ThinLTO and PGO, end to end. The profile is trained by a workflow and kept as a GitHub release asset.
Note
The first profile is uploaded:
workerd-2026-11-20-d4e0b3cc39.profdata.zston thepgo-profilesprerelease, the weight-10 profile measured below.What changes
release_linux= ThinLTO + PGO + Rust bitcode LTO.-Clinker-plugin-lto), so the ThinLTO link inlines across the cxx bridge.bazelflare-release) and anyone building--config=release_linuxget it.release_linux-without-pgois the old release build. The fork-PR fallback that builds types now uses it, so that job doesn't pay for a ThinLTO link.build/pgo/profile.jsonholds the URL and hash of an asset on the singlepgo-profilesprerelease. A module extension downloads it as@workerd_pgo_profile.build/pgoismanual, sobazel build //...andbazel test //...never fetch the profile: a missing asset breaks only the release builds, whichrelease.ymlruns on every push to main.extra_rustc_inputslabel flag, andpgo-useputs the profile there.${extra_rustc_inputs}in an extra rustc flag with the file's path, so-Cprofile-use=${extra_rustc_inputs}needn't name where Bazel puts the profile.build/pgo/train.sh):--config=pgo-instrumentand runs all 1,693 tests that run the workerd binary, in every variant but@gc-stress.--run_underwrapper that setsKJ_CLEAN_SHUTDOWN=1. Without it, workerd exits through_exit()and writes no profile.src/workerd/server/tests/pgo-workload.WorkerdServerHarness,workerd serveof a sync and an async hello world, plus a Worker that uses a mix of APIs (JSON, headers, streams,TransformStream, subrequests,crypto.subtle, URL).pgo-train.ymlruns only when started by hand. It trains on bazelflare, uploads withbuild/pgo/upload.sh, and opens a PR that updatesprofile.json, like the deps updater.release.ymlalready runs the release builds on every push to main, and publishes only the first build of each release version. So a missing profile, or a change that breaks the PGO build, fails the merge right after it.The arm64 build uses the x64 profile: Clang matches it to the code in its architecture-independent form. arm64-only code gets no profile data.
Measurement
The setup:
ohasends 200k requests per round, and the rounds of every binary are interleaved.rewriter(HTMLRewriter) andrender(JSON to an HTML table) were left out of training.build/pgo/train.shon this branch.Requests per second (median of three rounds) and instructions per request, against today's release build (
release_linux-without-pgo). "ThinLTO" adds--config=thin-lto --config=rust-ltoto that, without the profile.render, not trained onrewriter, not trained onThe workload's weight against the tests' (
PGO_WORKLOAD_WEIGHT, default 10):renderrewriter100 is 2–4% faster than 10 on the hello worlds, within the spread between rounds, but runs
rewriter, which nothing in training resembles, in 3% more instructions. 10 is the safer bet for Workers unlike the workload.The tests-only profile was measured in a separate run, against weight 10 (+74%, +67%, +57%, +35% · 2,279k in that run). The workload is worth its code even for Workers it wasn't trained on: with it,
renderis 9.5% faster andrewriter3% faster than with the tests alone.Testing
--config=release_linuxwith this profile, through--override_repository) on bazelflare: 2,951 tests pass, 4 skipped.//build/tools/llvmwas left out: it holds only the arm64 coverage tools.frankenvalue-testfailed under ThinLTO alone. Itsdynamic_casttoFrankenvalue::CapTableBuilderandCapTableReaderfound a second copy of their type info, because neither class had a virtual function defined out of line, and a dynamically linked test built with ThinLTO keeps its executable's copy apart from the library's. The shipped binary links statically and never had the problem. Both classes now define their destructors infrankenvalue.c++, andjsg::Serializer::ExternalHandlergets the virtual destructor itsDeserializercounterpart has.global-scope-test:structuredCloneErrorfailed under PGO. Its getter builds arrays nested about as deep as the stack allows, and with PGO's inlining the serializer ran out of stack cloning them, throwing aRangeError. The test, which guards against a crash, now accepts that.pgo-workload-test, five times on the PGO build. It and every other test that usesWorkerdServerHarness, which gained options to turn off the inspector and--verbose, five times each on bazelflare.bazel aquery --config=pgo-useshows Rustc actions get-Cprofile-use=external/+pgo_profile+workerd_pgo_profile/workerd.profdatawith the profile among their inputs.build/pgo/train.shon bazelflare: all 1,693 tests it runs pass on the instrumented build, and it wrote the profile measured above.🤖 Generated with Claude Code