Repository navigation
Conversation
…hreads `SimpleDataTypesCache` and `DataTypesCache` are thread-local, but the serializations they store are pooled (`SerializationObjectPool`), so every thread's entry held a copy of the same `shared_ptr`: one control block per type for the whole process. Per-value callers copy the returned pointer for every value (`SerializationDynamic::serializeBinary`, reached per shared-data value of a `JSON` column), which is two atomic operations per value on a cache line written by every thread of the query. Store the pooled serialization through a `shared_ptr` with a control block of its own (aliasing constructor), so these copies write only the caching thread's counter. The pointee is unchanged: pooling, `getHash`, `getPtr` (`shared_from_this` stays bound to the pooled control block) and pointer comparisons are the same, and the holder keeps the pooled object alive. This is the arm slow mode of query 1 of `generate_random_json` (`JSON(max_dynamic_paths = 4)`) that reds `Performance Comparison (arm_release)` on unrelated PRs: in the CPU profiles of the slow runs all the extra time is self time of `SerializationDynamic::serializeBinary`, which contains the two atomic operations on that counter. https://s3.amazonaws.com/clickhouse-test-reports/PRs/122356/8f85022f252b47a25fe2d5b487c61b95f6fb9303/pr/performance_comparison_arm_release_master_head_3_6/report.html (ClickHouse#122356) https://s3.amazonaws.com/clickhouse-test-reports/REFs/master/aed775756f2aef4c5871dfb15eed8065c9bb177a/masterci/performance_comparison_arm_release_master_head_2_6/report.html Measured on x86_64 (release build, `clickhouse local`, 16 pinned cores, 10 interleaved runs), query 1 at `max_threads = 12`: CPU 11.54 s -> 6.88 s, wall 1.067 s -> 0.641 s; queries 0, 2, 3, 4 within 0.3%. With one thread query 1 takes 5.54 s of CPU on both builds; what remains at 12 threads is the per-lookup lock of the query context in `DataTypesCache::clearIfQueryContextChanged` (removed by ClickHouse#120403). Co-Authored-By: Claude Opus 5.5 <[email protected]>
`DataTypesCache.ThreadsDoNotShareSerializationReferenceCounter` took one serialization per thread, so an implementation that creates the owner at every lookup instead of once per cache entry passed it, although it copies the pooled `shared_ptr` per value again. Take a second serialization in the same thread and assert that it shares the owner of the first one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Narrow the helper comment in DataTypesCache.cpp to pooled serializations: SerializationJSON does not support pooling. 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; 2 rounds, 2 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260926-193400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260926-154200 |
|
Workflow [PR], commit [79d7a2d] Summary: ❌
AI ReviewSummaryThis PR changes Final Verdict✅ No new blocking or major findings. LLVM Coverage ReportMeasured on commit 79d7a2d.
Changed lines: Changed C/C++ lines covered: 10/11 (90.91%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR gives serializations cached in DataTypesCache a per-thread reference counter. That cache is reached from Dynamic, JSON and Object column code, not from the plain typed columns that ClickBench and TPC-H read. The Q18 regression (+22.7%) has been downgraded to not sure because the query never runs the changed code. Q28, Q32, Q33 and Q34 (+6.4% to +14.4%) fall inside master's normal range, and that deterministic call is consistent with the diff. All five are memory-heavy GROUP BY queries that slowed together while some source runs shared hosts, which points to benchmark host contention rather than this change. clickbenchFlagged queries (5 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
|
CI finish ledger - 79d7a2dEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 169 check runs completed (127 pass, 40 not selected, 2 red), Session id: cron:our-pr-ci-monitor:20260927-003314 |
|
Correction to the ledger above: the
This is the placement class of #122350 (comment). Option (A) there would not have prevented this row, because the two PR builds above already share one |
|
Fixing PR for the |
…g briefly has no live leader The test sends `rcfg` and assumes the receiving node sees a live leader at that moment. A leader heartbeat gap longer than the election timeout makes a follower clear its leader. The next heartbeat makes it a follower again without marking the leader alive (NuRaft's same-term candidate branch calls only become_follower(), and only update_target_priority() sets hb_alive_), so for about one more heartbeat interval KeeperDispatcher refuses the command with "Cannot reconfigure cluster because there is no active leader". Seen in Integration tests (amd_tsan, 4/6) on PR ClickHouse#122464. Both no-live-leader refusals (the entry check and the `leaders` precondition) are raised before any action is applied, so add a helper that resends the command on exactly these two messages, every 0.5 s for up to 30 s, and then fails with the last refusal instead of returning it. All five rcfg calls use it; the assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Queries 0 and 2 of `tests/performance/json_to_string.xml` are a level shift on amd: within one server the 7 runs agree (in-run CV median ~1%), but the two servers' medians are more than 10% apart in 25.5% / 23.6% of 286-288 amd master runs (2026-10-25 15:00 .. 2026-11-04 11:00 UTC), 29 / 35 runs over the report floors, and the learned max_diff is 0.40, so a regression below ~40% is invisible. Query 1 is quiet on amd (1.0%). The level is drawn per server process, not per binary: master runs chain the same official build as the candidate of run k and the reference of run k+1, and consecutive log-ratios are uncorrelated (lag-1 r -0.04 / +0.01 over 353 pairs). Both servers do the same work (1 part, 62 marks, 500000 rows every run), and the slow server burns proportionally more user CPU (r 0.96-0.97). Queries 0 and 2 move together (r 0.89), no other query of the same jobs above r 0.23. For every value of every JSON path, SerializationDynamic::serializeTextImpl copies a SerializationPtr from the thread-local DataTypesCache; those are copies of the pooled serialization, so all query threads write the same reference counter, 8 times per row. With one thread there is no cross-thread traffic on it. Locally (two servers of the same master build 989ecd8, each pinned to 8 physical cores of one NUMA node with max_threads = 8 as in the amd job, 24 restarts): - Before, the multi-threaded form burns ~1.9x the CPU for the same rows (query 0: 1.09-1.32 s user CPU per run on 5.3-6.6 busy cores, after: 0.60 s on one core). - The slower server's median over the faster one's, median over restarts: queries 0 / 2 3.4% / 2.4% before (max 12.3% / 21.2%), 0.3% / 1.0% after (max 4.7% / 2.5%); query 1, which is unchanged, 1.3% / 1.7% in the same two runs. Paired on the same two processes, the gap before exceeds the gap after in 20/24 (query 0, sign test p 0.0008) and 19/24 (query 2, p 0.003) restarts; query 1: 9/24 (p 0.92). - After: 0 of 48 query-restarts over the report floors (before: 1 of 48). Medians 0.618 s / 0.628 s per run. - The CI rate itself does not reproduce on that machine: before, 1 of 24 restarts had queries 0 or 2 more than 10% apart with a CPU burn gap. The test still catches what it was added for (ClickHouse#115852): at max_threads = 1, 26.8.2.7 is 4.38x / 4.32x slower than 26.8.3.105 on queries 0 / 2 (median of `clickhouse local --time`). Nothing else changes: same fixture, same per-value toString path, query 1 untouched, no product change. The product side of the shared counter is ClickHouse#122464. Related: ClickHouse#100759 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ate_random_json` on half and a third of their rows No existing query number or text changes: 2 queries are disabled and 2 copies appended as 5 and 6. Query 1 (`JSON(max_dynamic_paths = 4)`, 3M rows) and query 2 (`Dynamic`, 300M rows) take 1.30 / 1.99 s on MasterCI amd and 0.95 / 1.44 s on arm: generateRandom work on 8 / 12 threads, a third of query 1's CPU being the shared reference counter contention that ClickHouse#122464 removes. The copies are the same queries with LIMIT 1500000 and LIMIT 100000000: the same seeds, schema and block size (1003 / 27777 rows), so each stream generates fewer identical blocks and the work per row is unchanged. On the official master builds 2731aee and d076efd, per-row user time of the copies is 0.975-1.000 of the originals' (clickhouse local) and 0.999-1.008 under perf.py; query 1's copy keeps 0.951 / 0.987 of the original's per-row CPU growth from 1 to 8 threads (the contention), query 2's copy stays at 1.00-1.02 (none). Projected copy medians 0.65 / 0.67 s amd and 0.48 s arm: about 24 s (amd) and 17 s (arm) less query time per master perf job. Related: ClickHouse#129258 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #122356
Related: #120403
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Multi-threaded queries that serialize or deserialize
DynamicandJSONvalues one by one use less CPU: the serializations cached per thread no longer share one reference counter between all threads. For example,generateRandomover aJSON(max_dynamic_paths = 4)column uses 40% less CPU with 12 threads.Description
SimpleDataTypesCacheandDataTypesCacheare thread-local, but serializations are pooled, so every thread's cache entry holds a copy of the sameshared_ptr. Per-value callers such asSerializationDynamic::serializeBinarycopy the returned pointer for every value: two atomic operations per value on one control block that all threads of the query write.The caches now store the pooled serialization through a
shared_ptrwith a control block of its own (aliasing constructor), so these copies write only the caching thread's counter. The pointee, pooling andgetPtrare unchanged. Returning a reference instead would not be safe: a nested (de)serialization, e.g. ofArray(Dynamic), can clear theDataTypesCachemap while the caller still uses the entry.On arm, query 1 of
generate_random_jsonfailsPerformance Comparison (arm_release)on unrelated PRs, e.g. PR #122356, 3/6: 0.974 s -> 2.204 s. Master too: aed77575, 2/6 flags itslower, 0.963 s -> 2.028 s. In their CPU profiles all the extra time is self time ofSerializationDynamic::serializeBinary, which contains the two atomic operations on that counter.On x86_64 (release build,
clickhouse local, 16 pinned cores, 10 interleaved runs,max_threads = 12), query 1 takes 6.88 s of CPU instead of 11.54 s, and queries 0, 2, 3 and 4 stay within 0.3%. With one thread, query 1 takes 5.54 s of CPU on both builds. The main remaining cost at 12 threads is the per-lookup lock of the query context inDataTypesCache::clearIfQueryContextChanged, which the open #120403 removes.Not covered: query 1 of
json_to_string(JSON(max_dynamic_paths = 0)), whose per-value path does not use these caches.Workflow [PR]
Sync PR [sync-upstream/pr/122464]