Skip to content

Add utils/download-ci-toolchain.sh to compile ClickHouse with CI's PGO+BOLT Clang - #130239

Merged
Blargian merged 1 commit into
ClickHouse:masterfrom
groeneai:utils-download-ci-toolchain
Nov 9, 2026
Merged

Blargian merged 1 commit into
ClickHouse:masterfrom
groeneai:utils-download-ci-toolchain

Conversation

@groeneai

@groeneai groeneai commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #130064

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add utils/download-ci-toolchain.sh, which downloads the Clang that CI compiles with (the same release as apt.llvm.org, optimized with PGO and BOLT) for local builds; it compiles ClickHouse about 20% faster on x86_64.

Description

CI compiles ClickHouse with Clang 22.1.8 built with PGO and BOLT (#97031), from the same LLVM commit as the apt.llvm.org clang-22 that the build docs install, but only the CI build image has it. utils/download-ci-toolchain.sh reads the pin (TOOLCHAIN_COMMIT) from ci/docker/binary-builder/Dockerfile, downloads the archive that image installs, keeps only the compiler and its resource directory (about 350 MB of the 1.8 GB archive), and prints export CC=... CXX=... for eval. As in CI, only the compiler comes from the archive: the build keeps using the installed ld.lld-22 and llvm-*-22 tools (CI log: Using linker: /usr/bin/ld.lld-22). It prints the versioned names that ToolSet in ci/defs/defs.py gives (clang-22, clang++-22), because CMake takes the binutils version suffix from the compiler's file name; with plain clang it picks GNU objcopy and the Rust symbol-stripping step breaks the link. It refuses when the pinned archive has no ToolSet compiler (for example after a ToolSet bump before the pin moves), and it never deletes or replaces a directory it did not create. A <Tip> in the build docs points to it. The compiler needs glibc 2.38 or newer.

Measured on x86_64 (356 sampled translation units, apt vs CI clang, ABBA passes): 22.8% less compile CPU in Debug and 21.9% in RelWithDebInfo; the objects are identical except debug info and .comment. The issue comment that proposed this measured a 22.6% shorter clean build on a 16-vCPU ARM host: #130064 (comment)

Validated locally, as CI does not run developer tooling that downloads 1.8 GB: fresh, cached and foreign cache directories, interrupted downloads, both pin formats, compiler-name skew; a Debug build configured with the printed line links, CMake picks the same llvm-*-22 tools as with apt clang-22, and clickhouse local runs.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/130239]

Version info

  • Merged into: 26.11.1.1767-master (included in 26.11 and later)

The script reads the toolchain pin from `ci/docker/binary-builder/Dockerfile`,
downloads the archive that the CI build image installs, keeps only the compiler
and its resource directory, and prints the `CC` and `CXX` export line.

It prints the names that `ToolSet` in `ci/defs/defs.py` gives and CI compiles
with (`clang-22`, `clang++-22`). CMake's binutils detection takes the version
suffix from the compiler's file name: with the unversioned `clang` it finds GNU
`objcopy`, the Rust strip step run with it keeps the COMDAT group of the
localized `DW.ref.rust_eh_personality`, and the Debug build fails to link.

It never deletes or replaces anything it did not create: it downloads only when
nothing exists at `<cache>/<commit>-<arch>`, into a `mktemp` directory that an
`EXIT` trap removes, and publishes it with `mv -T`. It refuses when the archive
has no `bin/<ToolSet.COMPILER_C>` or `bin/<ToolSet.COMPILER_CPP>`, so it never
hands out a compiler that CI no longer compiles with.

Add a Tip about it to the build docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding).

# Sev Finding Verdict Evidence / action
1 ⚠️ eval "$(utils/download-ci-toolchain.sh)" returns 0 when the script fails DISAGREE Every failure path prints its reason to stderr and nothing to stdout, so eval leaves CC and CXX as they were and the build uses the compiler the same page installs; only the speed-up is lost. A caller that needs the exit code runs the script directly.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261109-021400

@mintlify

mintlify Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 34940a5.

Approve preview

@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @thevar1able, could you review this and add the can be tested label so CI runs? It adds a script that downloads the PGO+BOLT clang pinned in ci/docker/binary-builder/Dockerfile and prints the versioned CC/CXX names from ToolSet, so CMake keeps using the llvm-*-22 tools as in CI (22% less compile CPU measured on x86_64).

@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [34940a5]

Summary: ✅


AI Review

Summary

Reviewed #130239 at 34940a56c70b4c6762b212bb46ed1883f7b555ae. The PR adds utils/download-ci-toolchain.sh to retrieve CI's pinned PGO/BOLT compiler for local builds and documents its use. No actionable findings. Seven installer fixture checks passed, covering extraction and exports, cache reuse, foreign-directory preservation, interrupted-download cleanup, both pin formats, compiler-name mismatch rejection, and a disabled pin.

Missing context / blind spots
  • ⚠️ The installer checks used a synthetic archive. I could not independently repeat a real compiler/build run because this host has glibc 2.35, below the documented 2.38 minimum. A build on a supported host would close that verification gap; the PR already reports a successful Debug build and before/after performance measurements.
Final Verdict

✅ Approve. No new inline comments or changes to existing threads are needed.

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Nov 9, 2026
@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-build-system Build system (CMake, compilation, platform builds). labels Nov 9, 2026
@thevar1able thevar1able self-assigned this Nov 9, 2026
@thevar1able
thevar1able added this pull request to the merge queue Nov 9, 2026
@Blargian
Blargian removed this pull request from the merge queue due to a manual request Nov 9, 2026
@Blargian
Blargian added this pull request to the merge queue Nov 9, 2026
Merged via the queue into ClickHouse:master with commit f229367 Nov 9, 2026
375 of 376 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-build-system Build system (CMake, compilation, platform builds). pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants