Repository navigation
Conversation
The `amd_llvm_coverage` binary ran the same functional tests 2.5 times slower than `amd_debug`, and the parallel `INSERT INTO test.hits_s3` of the stateful data took 379 s instead of 8 s. With the default 64-bit counters every region entry is a read-modify-write of a counter shared by all threads, and `-runtime-counter-relocation` (needed for continuous mode) adds a load of the bias to every update, so threads running the same hot code fight for the cache lines. Build the regular coverage binary with `-enable-single-byte-coverage` and `-conditional-counter-update`: a counter is written only on the first execution of its region, afterwards it is only read. The per-test coverage build keeps 64-bit counters because `coverage.cpp` reads them in-process. Line, region and function coverage are unchanged; execution counts and branch coverage are no longer recorded, so the lcov summary tolerates missing branch data and the PR comment omits the branch row when there is none.
|
Workflow [PR], commit [ff3da0f] Summary: ✅
AI ReviewSummaryThis PR splits the LLVM coverage build so pull requests use single-byte counters while Findings
Final VerdictChanges requested. The PR workflow split itself is close, but the coverage-reporting path still needs to preserve the distinction between "metric unavailable" and LLVM Coverage ReportMeasured on commit ff3da0f.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +743 lines in 223 files (-2853 lines lost coverage) · Details |
| if no_data and metric == "branches": | ||
| # The coverage build uses single-byte counters (see `cmake/sanitize.cmake`), | ||
| # which record no branch counts, so there are no branches to report. | ||
| return 0.0, 0, 0 |
There was a problem hiding this comment.
The PR comment path can still tell "branch coverage is unavailable" from 0% because it keeps b_branch_total / c_branch_total, but the CI DB path cannot: coverage_ci.coverage_data only stores baseline_branch_cov / current_branch_cov (ci/jobs/scripts/job_hooks/llvm_coverage_hook.py:168-173), not the totals. The master-path comment in ci/jobs/llvm_coverage_job.py:819-821 says this table feeds later baselines and trends, so flattening missing branch data to 0.0 here will make the branch series look like it collapsed at this commit instead of showing that the metric was removed. Can we preserve an explicit "branch metric unavailable" state in the row (nullable fields, an availability flag, or persisted totals) before returning synthetic zeros?
…y in PRs Single-byte counters record no execution counts and no branch coverage, so they are now opt-in via `WITH_COVERAGE_SINGLE_BYTE`. Pull requests build the coverage binary as `Build (llvm_coverage_single_byte_build)`, which provides the same artifacts as `Build (llvm_coverage_build)`; `MasterCI` keeps the 64-bit counters and keeps publishing branch coverage and execution counts. The separate job name keeps the two builds apart in the CI cache.
| "Make sure you run lcov with --branch-coverage when you need branch stats." | ||
| ) | ||
| no_data = re.search(rf"^\s*{metric}\.*:\s*no data found", output, re.MULTILINE) | ||
| if no_data and metric == "branches": |
There was a problem hiding this comment.
get_lcov_summary is used on the MasterCI coverage path too, not just on the PR-only single-byte build. With this unconditional metric == "branches" fallback, any future regression that drops branch data on master (toolchain change, broken flags, corrupt tracefile) will stop failing here and will instead be reported as 0.0 / 0 of 0, even though the PR explicitly keeps promising that master still publishes branch coverage. Can we make the "no branch data is expected" path explicit for the PR single-byte build only, and keep the old fail-close behavior for master and for downloaded master baselines?
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, 4 s compile time in total, 6 of them have a recent master baseline. |
|
Closing in favour of a different approach: pull requests will stop running the LLVM coverage jobs by default (they become opt-in via the |
The LLVM coverage build is the most expensive part of PR CI: about $17k per week for the stateless
amd_llvm_coveragejobs and about $18k per week for the integration ones (CIDB, 2026-09-21 to 2026-09-27, on-demand prices). A large part of it is instrumentation overhead rather than tests:amd_llvm_coveragetakes 2.5 times the total time ofamd_debug(median 2.1 times per test).Start ClickHouse Servertakes 539-720 s in LLVM coverage jobs and 49 s inamd_debug. On the same commit, loadinghits/visits/TPC-DS/TPC-H takes 131 s vs 15 s, and the 16-threadINSERT INTO test.hits_s3takes 379 s vs 8 s.The cause is contention on the coverage counters. With the default 64-bit counters every region entry is a read-modify-write of a counter that all threads share, so threads running the same hot code keep stealing the cache line from each other.
-runtime-counter-relocation, which continuous mode (%c) needs so that a SIGKILLed server leaves a valid profile, adds a load of the bias to every update. A micro-benchmark with clang 21, 12 threads. "loop" is a function with a 64-iteration branchy loop; "calls" is a tiny branchy function called in a tight loop, which is closer to per-row code in ClickHouse:%c%c%c(current CI)%c%c(this PR)Dropping relocation and continuous mode alone does not help: in the "calls" case the 64-bit counters are about 200 times slower with 12 threads either way, because every call writes the same shared counters. Only the single-byte mode removes the contention.
This PR adds a
WITH_COVERAGE_SINGLE_BYTECMake option that builds the coverage binary with-mllvm -enable-single-byte-coverage -mllvm -conditional-counter-update. A counter is written only on the first execution of its region; afterwards it is only read, so the cache line stays shared between cores. Continuous mode keeps working, andllvm-profdata merge/llvm-cov exportproduce the same line, region and function coverage.Single-byte counters record no execution counts and no branch coverage (
llvm-covderives branch counts by subtracting counters), so they are used only in pull requests:Build (llvm_coverage_single_byte_build), a new build type that is the master coverage build plus-DWITH_COVERAGE_SINGLE_BYTE=ON. It provides the same artifacts (CH_AMD_LLVM_COVERAGE_BUILD,UNITTEST_LLVM_COVERAGE), so the test and merge jobs are unchanged.MasterCIkeepsBuild (llvm_coverage_build)with 64-bit counters, so master keeps publishing branch coverage and execution counts. The different job names keep the two builds apart in the CI cache; pull-request cache records are never reused by master anyway.get_lcov_summaryaccepts a summary without branch data, and the PR comment shows the branch row only when both sides have branch data, so pull requests no longer show a branch delta.WITH_COVERAGE_DEPTH) keeps 64-bit counters becausebase/base/coverage.cppreads them in-process; CMake rejects combining the two options.To verify in this PR's CI:
Start ClickHouse ServerandTestsdurations of theamd_llvm_coveragejobs compared with master, and the PR line coverage compared with the master baseline. If the speed-up holds, the number of LLVM coverage batches in pull requests can be reduced in a follow-up.Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/122754]