Repository navigation
Shard the clang-tidy build and lower the static analyzer budget for template-heavy directories - #123082
Conversation
The clang-tidy build uses dummy compiler and linker launchers, so every object file is an independent clang-tidy invocation and nothing is linked. Split the object files of our own code (everything outside `contrib`) into 4 shards by a stable hash of their path and run each shard as a separate job, `Build (arm_tidy, i/4)`. Ninja still builds what each object file needs (generated headers, `protoc`, `llvm-tblgen`). About 22% of `Build (arm_tidy)` runs in PRs miss the clang-tidy cache almost entirely (a widely included header changed) and take 35-50 minutes; the rest take under 20. A cold run is bound by throughput, not by one slow file: a sample of 160 files averaged 17 s each with a maximum of 88 s. So the cold runs should shrink roughly 4x, at the cost of repeating checkout, cmake and code generation (about 2 minutes) in every shard. `check_submodules.sh` runs in the first shard only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [2bdd4ef] Summary: ✅
AI ReviewSummaryThis PR usefully shortens cold Findings
Final Verdict
LLVM Coverage ReportMeasured on commit 2bdd4ef.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +140 lines in 45 files (-98 lines lost coverage) · Details |
|
@groeneai how much time clang-tidy takes now? does it make sense to run clang-tidy if the file was not changed? |
it shouldn't, but you need to somehow check all transitive dependencies to detect a change. and unchanged files should be served quickly from cache anyway |
|
Measured on CIDB,
A cold build stage takes about 40 minutes. A fully warm one takes about 3 minutes for ~5,140 files (example, 99.9% hits): the ctcache key ( Where I see avoidable cold runs, both from results that are never stored:
|
…tidy cache Upload the `.ninja_log` of the clang-tidy build to get the duration of every file's clang-tidy run in each shard. Also add a no-op `static_assert` to `src/Core/Types.h` and `src/Common/Exception.h`, which about 85% of our object files include, so that the clang-tidy cache misses and the shards run cold. The cache key is computed from preprocessed source without comments, so a comment change would not do. This is for measurement only and will be reverted. Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123082&sha=latest&name_0=PR PR: #123082 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
… and `src/Interpreters` In a cold clang-tidy run, `arrayElement.cpp` took 38 minutes and `Aggregator.cpp` 26, while the typical file takes about 10 seconds. The static analyzer causes it: without `clang-analyzer-*`, `arrayElement.cpp` takes 28 s instead of 32 minutes. Type dispatch creates hundreds of instantiations per function (e.g. `ArrayElementArrayNumImpl::vector`: 19 element types x 2 modes x 8 index types x 2 = 608; `Aggregator::executeImplBatch`: 934), and in the default (deep) mode the analyzer re-analyzes each with its callees inlined. Which checkers are enabled makes no difference. Shallow mode does not inline callees. It is passed via `ExtraArgs` because `clang-analyzer-mode` in `CheckOptions` has no effect on the analyzer mode. Locally, clang-tidy on `arrayElement.cpp` goes from 1921 s to 255 s. `ExtraArgs` is part of `--dump-config`, which the clang-tidy cache hashes, so the cache keys of these directories change too. PR: #123082 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shallow mode does not inline callees, so it produced 9 false positives in `src/Functions` and `src/Interpreters` (`core.CallAndMessage`, `core.NonNullParamChecker`): without inlining, the analyzer cannot see that e.g. `shared_ptr::get` returns a non-null pointer. Keep the default (deep) mode and lower `max-nodes`, the exploration budget per function, from 225000 to 25000. Locally, clang-tidy on `arrayElement.cpp` goes from 1921 s to 309 s (shallow mode: 255 s), and `arrayReduce.cpp`, `formatDateTime.cpp` and `validateNestedArraySizes.cpp`, which failed with shallow mode, have no findings. Also apply it to `src/AggregateFunctions` and `src/DataTypes`, where the next slowest files are (`AggregateFunctionAvgWeighted.cpp` 18 min, `DataTypesDecimal.cpp` 12 min in a cold run). PR: #123082 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units6 translation units recompiled, 5 s compile time in total, 6 of them have a recent master baseline. |
After the previous change, `MergingSortedAlgorithm.cpp` (9.1 min) and `SortingTransform.cpp` (6.4 min) were the slowest files in a cold clang-tidy run. Both are the same pattern: `MergingSortedAlgorithm::merge` and `initialize` are analyzed once per sort cursor variant (111 times each), and `MergeSorter`'s constructor and `read` 56 times each. With `max-nodes=25000`, clang-tidy on them goes from 446 s to 66 s and from 305 s to 45 s locally, with no findings. A codebase-wide scan at the default budget shows that 11.1% of all analyzed functions already reach the default limit (225000). A budget of 25000 newly cuts 5.0% of functions short; the five directories with the lower budget hold the slowest files and most of those functions, while the rest of the codebase keeps the full budget. PR: #123082 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The no-op `static_assert`s were only needed to measure cold clang-tidy runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shard's object files were expanded into the build command with `$(cat tidy_shard_targets.txt)`, which splits them on whitespace and expands glob characters. Run ninja via `subprocess` with an argument list instead, so every target name reaches ninja verbatim. A single shell command string is not an option: Linux limits one argument to 128 KiB, and a shard's target list is larger. Report: #123082 (comment) PR: #123082 Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus
left a comment
There was a problem hiding this comment.
Generally looks good. I wonder if we just remove clang-tidy from critical path and make it run in parallel, won't this be simpler?
`Result.from_commands_run` captures only what a Python callable prints, so the output of the `ninja` child process went to the job log but not to the info of the `Build ClickHouse` result, which shell commands get on failure. Read the child's combined stdout and stderr through a pipe and print it from Python. Report: #123082 (comment) PR: #123082 Co-Authored-By: Claude Opus 5.5 <[email protected]>
It'd be simpler for sure. I think the motivation to detect such problems as early as possible is still valid even though we lost the battle for the CI cost. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only CI and static analysis. It splits the arm clang-tidy build into 4 shards (workflow YAML, job_configs.py, build_clickhouse.py) and adds .clang-tidy files that lower the analyzer's exploration budget for clang-tidy runs only. The release binary used for benchmarks is not affected. The only flagged queries are ClickBench Q33 (+5.5%) and Q34 (+5.0%). Both are borderline: the two tests disagree, and CPU time rose by only 1-2%. They stay not_sure and are not attributable to this change. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
# Conflicts: # .github/workflows/master.yml # .github/workflows/pull_request.yml
| # It is passed as a compiler flag because analyzer options in `CheckOptions` have no effect. | ||
| InheritParentConfig: true | ||
|
|
||
| ExtraArgs: ['-Xclang', '-analyzer-config', '-Xclang', 'max-nodes=25000'] |
There was a problem hiding this comment.
These new per-directory .clang-tidy files now live under ./src, and the shared build_digest_config hashes the whole ./src tree for every ordinary build cache key and for the build-change filters (ci/defs/job_configs.py:109-131, ci/jobs/scripts/workflow_hooks/filter_job.py:74-84). The root .clang-tidy is intentionally outside that digest, but these files are not, so any future analyzer-budget-only tweak will invalidate the cache for all regular builds / Fast test-style digests and make the PR look like a product-code change even though only the tidy jobs observe these files.
Could we either move these configs out of ./src, or exclude the five new .clang-tidy files from the shared ./src digests and add them back only to the tidy-job digests?
A cold
Build (arm_tidy)run (one where a widely included header changed, so the clang-tidy cache misses) took 35–50 minutes, and the regular builds wait for this job. This PR brings a cold run down to about 17 minutes of job time:cmake/clang_tidy.cmake), so every object file is an independent clang-tidy run and nothing is linked. The object files of our own code (everything outsidecontrib) are split by a stable hash of their path, and each shard is a separate job,Build (arm_tidy, i/4). Ninja still builds what each object file needs (generated headers,protoc,llvm-tblgen).check_submodules.shruns in the first shard only.max-nodes, default 225000) to 25000 insrc/Functions,src/Interpreters,src/AggregateFunctions,src/DataTypesandsrc/Processors..ninja_logof each shard, which gives the duration of every file's clang-tidy run.Why the analyzer budget
Sharding alone was limited by a few files: in a cold run,
arrayElement.cpptook 38 minutes andAggregator.cpp26, while the typical file takes about 10 seconds. Nearly all of it is the static analyzer (withoutclang-analyzer-*,arrayElement.cpptakes 28 s instead of 32 minutes), and which checkers are enabled makes no difference. Type dispatch instantiates functions hundreds of times (ArrayElementArrayNumImpl::vector: 19 element types × 2 modes × 8 index types × 2 = 608;Aggregator::executeImplBatch: 934;MergingSortedAlgorithm::merge: 111), and the analyzer explores each instantiation with its callees inlined.Alternatives that did not work:
core.CallAndMessage,core.NonNullParamChecker), because the analyzer can no longer see that e.g.shared_ptr::getreturns a non-null pointer.clang-analyzer-mode/clang-analyzer-max-nodesinCheckOptionshave no effect on the analyzer, so the setting is passed as a compiler flag viaExtraArgs.ExtraArgsis part of--dump-config, which the clang-tidy cache hashes, so the cache keys of these directories change.How much analysis it costs, from running the analyzer over all 5,103 checked files at both budgets: 11.1% of the 139,090 analyzed functions already reach the default limit. A budget of 25000 newly cuts 5.0% of functions short (60% of them template instantiations), and the five directories above hold most of those functions and all of the slowest files. The rest of the codebase keeps the full budget. Applying 25000 globally would save about 74% of analyzer time but cut short functions in many more places, so it is left out.
Why this change should be safe (comparison of lower
max-nodesvsshallowmode):Results (cold runs, build step of each shard)
Each job adds about 5 minutes of checkout and cmake. The slowest files are now
arrayElement.cpp(7.0 min) andAggregator.cpp(6.6 min). Total clang-tidy CPU time of a cold run went from 27.6 to 21.7 hours. Runs where the cache hits pay the setup in each of the 4 jobs.Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123082]
Version info
26.10.1.1710-master(included in26.10and later)