Repository navigation
Share sccache entries between checkouts at different paths with SCCACHE_BASEDIRS - #134009
alexey-milovidov merged 3 commits into
Conversation
0.18.0 and 0.19.0 made `-ftime-trace` uncacheable (mozilla/sccache#2834), which 27 CI build types pass through -DENABLE_BUILD_PROFILING=1, so CI stayed on 0.17.0. 0.20.0 hashes the flag again and writes no trace on a cache hit (mozilla/sccache#2956). It also leaves CARGO_TARGET_DIR and CARGO_BUILD_* out of Rust keys (ClickHouse#3050) and hashes the C/C++ input file name (ClickHouse#2974). Measured locally with CI's cmake flags and a local disk cache, second build from a fresh build directory at the same path: - amd_binary clickhouse-bundle: 1562 s cold, 147 s warm; C/C++ 17715 of 17717 hits (the 2 misses are openldap's generated version files with __DATE__/__TIME__), Rust 603 of 603; no hit wrote a time trace. - amd_asan_ubsan dbms: 1934 s cold, 95 s warm; C/C++ 16237 of 16239, Rust 529 of 529. - PR-build environment (READ_ONLY, anonymous S3): the server starts, a miss compiles, the write is refused, warn_on_low_sccache_hit_rate parses the stats. 0.20.0 additionally counts an anonymous 403 on a missing key as a read error (ClickHouse#2967); it is still a miss. 0.20.0 treats `--embed-dir` as uncacheable, so the 4 _jieba sources (6.9 s of compile) are always compiled. 0.20.0 does not read 0.17.0 entries: every build type is cold once after this lands. Related: ClickHouse#127827 Co-Authored-By: Claude Opus 5.5 <[email protected]>
sccache keys contain absolute paths, so a checkout or git worktree at another path misses every entry of the cache that another checkout filled. sccache 0.20.0 strips SCCACHE_BASEDIRS from the preprocessed input and from the arguments, but it reads the variable only when the server starts: a running server ignores the value a client passes. Local builds (option ENABLE_SCCACHE_BASEDIRS, sccache >= 0.20.0, path mapping on, SCCACHE_BASEDIRS not set in the environment): the C, C++ and CUDA launchers become `env SCCACHE_BASEDIRS=<source dir> SCCACHE_DIRECT=false sccache`, and the cargo environment carries the same two variables, so whichever compile starts the server starts it with these options. Preprocessor cache mode is off because a direct-mode hit restores the dependency file of the compile that filled the entry, which names the other checkout's headers. CMake does not stop or restart a server that runs with other options: `sccache --stop-server` returns while the server still serves the requests in flight, so a build using it could start a second server on the same local cache, which sccache does not support. The configure prints a warning with the command to run when no build uses the server. The check reads `sccache --show-stats --stats-format=json`, which does not start a server. Only the source directory is a base directory, because path mapping maps only the source directory. The build-type default and the path-mapping option move before include(cmake/ccache.cmake) so that the launcher is set before the heavy-build check and the dummy launchers save it. Rust: SCCACHE_BASEDIRS_VERBATIM_ENV_DEPS=CARGO_MANIFEST_DIR, CARGO_MANIFEST_PATH for every cargo run, so a crate that bakes its manifest path into its code (protoc-bin-vendored, whose protoc the perfetto_protos build script runs) is cached per checkout. OUT_DIR is not listed: every use of it in the dependency graph is inside include!, which sccache hashes as a source. compiler-rt keeps -fdebug-compilation-dir= and -ffile-prefix-map=, so its objects do not embed the checkout path. CI exports SCCACHE_BASEDIRS=/ClickHouse before it starts the server, for every build type except Debug ones (no path mapping), and in the fast test; CMake leaves the launcher alone when the variable is set. Related: ClickHouse#127827 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without preprocessor cache mode a fully cached rebuild has to run the preprocessor for every hit. Measured with CI's amd_binary flags, sccache 0.20.0, a local disk cache and a fresh build directory at the same path, clickhouse-bundle with 17715 of 17717 C/C++ hits: 254 s with preprocessor cache mode, 258 s without it. Related: ClickHouse#127827 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings) plus my own review (1 nit); 1 full pass, no fix round needed.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261124-012800 |
|
cc @thevar1able, could you review this? With sccache 0.20.0 the C/C++ and CUDA launcher becomes |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261124-011259 |
|
Workflow [PR], commit [c9f3e8a] Summary: ✅
AI ReviewSummaryEnables sharing sccache entries across checkout paths with Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/StorageSystemChangelog.generated.cpp.o |
3.10 MiB | 4.00 MiB | +921.19 KiB (+29.02%) |
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
17336 translation units recompiled, 26079 s compile time in total, 17311 of them have a recent master baseline.
| Translation unit | Master | PR | Δ vs median |
|---|---|---|---|
contrib/rocksdb-cmake/__/rocksdb/db/version_set.cc |
8.3 s | 13.4 s | +5.2 s (+63%) |
Symbol sizes
| Binary | Symbol | Master | PR | Δ |
|---|---|---|---|---|
programs/clickhouse |
DB::auto_changelog |
292.03 KiB | 371.81 KiB | +79.78 KiB (+27.32%) |
|
Ok, now I get why Let me drive the PR to sccache to introduce client-side reading of I'd still merge this part and not wait for the upstream PR. The remainings could be fixed in the following-up PRs |
|
Once a sccache release has mozilla/sccache#3065, I'll send the follow-up: CI moves to that release; the launchers pass |
…se-across-checkouts Resolve the conflict in contrib/compiler-rt-cmake/CMakeLists.txt: master added -mbranch-protection= to the compiler-rt keep-list, this branch adds -fdebug-compilation-dir= / -ffile-prefix-map=. Keep both. The list comment now uses the same single line as ClickHouse#134009, which carries the same hunk, so whichever of the two merges first leaves the other without a conflict. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #127827
Related: #133753
Related: #130277
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Builds from checkouts at different paths now share sccache entries. With sccache 0.20.0 or newer, the build starts the sccache server with
SCCACHE_BASEDIRSset to the source directory (optionENABLE_SCCACHE_BASEDIRS, used whenENABLE_BUILD_PATH_MAPPINGis on), and CI sets it for its non-Debug builds.Description
Option B of #127827 (#127827 (comment)). The first commit is #133753 (sccache 0.20.0 in CI); merge that first.
cmake/ccache.cmake, new optionENABLE_SCCACHE_BASEDIRS(on): the C/C++ and CUDA launcher becomesenv SCCACHE_BASEDIRS=<source dir> SCCACHE_DIRECT=false sccache, so an auto-started server gets both. Only the source dir is a base directory, as only it is path-mapped; a build dir inside the checkout shares by its relative name. A server with other options is not restarted (--stop-serverreturns before it exits, so a concurrent build could start a second server on the same cache): the configure warns with the command. As chosen in Improvesccacheto reuse S3 artifacts as cold read-only cache #127827, Debug and CUDA compiles on such a server can get another checkout's paths..dfile.SCCACHE_BASEDIRS_VERBATIM_ENV_DEPS=CARGO_MANIFEST_DIR,CARGO_MANIFEST_PATH, asprotoc-bin-vendoredbakes its manifest path into code. No Rust path mapping.SCCACHE_BASEDIRS=/ClickHousefor non-Debug builds.Local validation, CI's
amd_binaryflags, disk cache: checkout A filled it and was moved away; checkout B at another path builtclickhouse-bundlein 428 s (cold: 1,599 s) with 17,712 of 17,717 C/C++ hits and 99 of 603 Rust hits (host units; target crates hash the absolute--sysroot). Without the verbatim line B fails inperfetto_protos's build script (protoc not found <A>/...). 20 sampled hits are byte-identical to local compiles. Exception (clang, also on master):-ffile-prefix-mapmisses a lambda location inside a pointer-to-member template argument, so 2 grpc TUs keep the filling checkout's path in DWARF type names.Where it loses: the local and CI caches are cold once (stripped arguments; locally also
-Ppreprocessing without preprocessor cache mode); an all-hit rebuild at-j32takes 258 s, not 254 s; two checkouts built within the idle timeout share nothing until the server restarts.Workflow [PR]
Sync PR [sync-upstream/pr/134009]
Version info
26.12.1.1042-master(included in26.12and later)