Repository navigation
Use cached serializations for Dynamic fields - #113344
alexey-milovidov merged 22 commits into
Conversation
|
Workflow [PR], commit [0f6fffd] Summary: ✅
AI ReviewSummaryThis PR switches Final Verdict
LLVM Coverage ReportMeasured on commit 0f6fffd.
Changed lines: Changed C/C++ lines covered: 28/28 (100.00%) · Uncovered code |
# Conflicts: # src/DataTypes/DataTypesCache.cpp
Build profile diff (arm_release)Commit See the job log for details. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only Dynamic and JSON (Object) value serialization: data-type serialization lookups now go through the types cache, with the type object passed along. It also adds gtests and a new performance test. The one flagged row is clickbench Q9, at +10.8% (432 ms vs 390 ms). That result falls inside master's recent 367–442 ms range, and the query runs over plain columns that never reach the changed Dynamic/JSON paths, so leaving it suppressed is the right call. Neither clickbench nor tpch_adapted_1_official shows an effect that can be traced to this change. clickbenchFlagged queries (1 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
|
|
🕵 The previous CI run had two unrelated failures. The docs-example width mismatch is fixed by #117827 and is now included via merge commit e8859ef. @groeneai, please investigate the targeted AST fuzzer failure in a separate PR: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=113344&sha=d4e8cd794e59e838df0be3197a7cdd5fc65a5927&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29. It fails on |
|
Acknowledged. I am investigating the |
|
Investigated. This is not caused by your PR and is unrelated to Attribution: it reproduces on pristine master ( Root cause is
SET enable_nullable_tuple_type = 1;
CREATE TABLE t_fz (key Date32, t Nullable(Tuple(m Map(LowCardinality(String), UInt64))))
ENGINE = MergeTree ORDER BY key;
INSERT INTO t_fz SELECT number, tuple(map('k1', number)) FROM numbers(3);
INSERT INTO t_fz SELECT 100, NULL;
SELECT sum(t.m['k1']) FROM t_fz; -- LOGICAL_ERROR, server abort in debug and sanitizer builds
SELECT t.m['k1'] FROM t_fz ORDER BY key; -- 0, 1, 2, \N under a UInt64 columnWith Fixing PR: #115777 (external, open). It replaces the pass's nullability check with a stricter guard that compares the hardcoded type against the resolved storage type and applies it to the map-key rewrite, so |
Pass the decoded type to the existing serialization cache so a cache miss does not reparse its name. Cover a deeply nested shared value with a cold cache in the existing binary-encoding tests. Review: ClickHouse#113344 (comment)
The 100,000-row performance test was 4.4% slower with the CI binaries, while one million rows showed a 46.5% lower latency. Use the data size that exposes the nested-path benefit. https://performance.ci.clickhouse.com/runs/pr-113344-9e20a1d407021c66e0d6157b21e7eb5d8bcb55e3/tests/dynamic_field_serialization_cache/queries/0?metrics=client_time
| hash.update(type_name); | ||
| auto tmp_column = value_type->createColumn(); | ||
| getDataTypesCache().getSerialization(type_name)->deserializeBinary(*tmp_column, buf, getFormatSettings()); | ||
| getDataTypesCache().getSerialization(type_name, value_type)->deserializeBinary(*tmp_column, buf, getFormatSettings()); |
There was a problem hiding this comment.
This only fixes the ColumnObject branch. The sibling Dynamic hash path in src/Columns/ColumnDynamic.cpp:906-914 still decodes the shared-variant type and then calls type->getDefaultSerialization()->deserializeBinary(...), so updateHashWithValue still pays the global serialization-pool lookup once per row for Dynamic values stored in the shared variant.
That method is on the hot path for ColumnsHashing::hash128, Block::updateHash, arrayDistinct, and other hash-based operators, so queries like DISTINCT / uniq* / hash joins over a Dynamic(max_types=0) key still miss the optimization this PR is introducing. Please switch that sibling branch to getDataTypesCache().getSerialization(type->getName(), type) as well, and add a cold-cache regression for it.
There was a problem hiding this comment.
🕵 Thanks — agreed that ColumnDynamic::updateHashWithValue has the same pattern for values stored in the shared variant. This PR is scoped to Field binary (de)serialization of Dynamic values (the nested JSON path read with map_with_buckets) plus passing already-decoded types to lookups that already went through the cache. Switching the ColumnDynamic hashing path to the cache changes a different hot path (DISTINCT/uniq*/hash joins over Dynamic) and deserves its own benchmark and test, so I'd prefer to keep it for a follow-up PR rather than extend this one.
Round-trip deeply nested values through `SerializationDynamic::serializeBinary` and `SerializationDynamic::deserializeBinary` for `Field`, so both changed call sites run on a cache miss with a type whose name cannot be reparsed. Review: ClickHouse#113344 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Query #0 (max_threads=16, 1M rows) was over the report floors in 32% of amd and 13% of arm master runs between 2026-10-25 and 2026-11-04, and the two servers' medians differed by more than 10% in 47% of amd and 22% of arm reports, with a within-run CV of about 1%. Both servers execute the same instructions (84.1-84.5 G per process on amd), but one of them can need up to 30% more cycles for the whole life of the process. Every reading thread copies the pooled serialization pointer per value, so the per-row cost and the per-process spread grow with the number of reading threads. 2 is the smallest thread count that still measures ClickHouse#113344: with one reading thread its merge is 1-8% slower than its parent. With the default merge_tree_min_rows_for_concurrent_read (163840 rows, 20 marks) and merge_tree_min_bytes_for_concurrent_read (240 MiB, 24 marks) a second thread gets its own share of a single part only from 48 granules on, so 32 granules were read by one thread. With both settings 0 each thread reads 16 granules. 262144 rows keep a run at about 1 s on amd; at the arm/amd ratio of other 2-thread queries (p90 1.45x) arm stays under the 2 s slow-query limit. Local validation, two official master servers pinned to the same 8 cores of one NUMA node, both with max_threads 8, as in the amd job: 12 A/A cycles with fresh server processes. The new query differed by at most 3.1% between the servers (stat_threshold median 0.016, max 0.032). User CPU per 1000 rows across the 24 processes was 7.43-7.98 ms (max/min 1.075). In the same process pairs the old query differed by up to 15.2% with non-overlapping runs (max/min 1.31). Parent 199f114 vs merge a606bff of ClickHouse#113344: the merge is 1.29-1.36x faster in 3 of 3 cycles. Every run used 2 reading threads (cpu/wall 1.95-1.98) and read 262144 rows. Median run 1.04 s. The rig differs from CI in two ways. It sets remap_executable=0, and it reads each server binary into the page cache of the pinned node right before each start, because the box has six NUMA nodes and CI runners have one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
SerializationDynamic::deserializeBinarydecodes the data type of eachFieldand then callsgetDefaultSerialization. This enters the globally lockedSerializationObjectPoolfor every value.This is particularly expensive when reading nested paths from
JSONcolumns stored usingmap_with_buckets. Reading a nested path from anArray(JSON)value reconstructs the complete path value and deserializes every innerDynamicfield, repeatedly acquiring the global serialization-pool lock.Use the existing thread-local cache returned by
getDataTypesCacheto obtain the serialization instead. Apply the same change symmetrically toSerializationDynamic::serializeBinary. Pass the already decoded type to the cache in bothDynamicserialization andColumnObjectshared-data hashing, avoiding type-name reparsing on a cache miss.The change was tested with one million rows from the JSONBench Bluesky dataset. The benchmark read
data.commit.record.facets[].features[].tagfrom aJSONcolumn usingmap_with_buckets.max_threads=1max_threads=16max_threads=4The
advancedshared-data format already reads requested substreams directly and normally bypasses this field-level deserialization path.A performance test in
tests/performance/dynamic_field_serialization_cache.xmlgenerates one million rows whose nestedvaluepath alternates between string, integer, array, and object values. With the 2026-09-23 CI AMD release binaries, seven local runs measured 1.751 s before and 0.936 s after (46.5% lower median latency). Reversing the server order measured 1.739 s before and 0.928 s after (46.7% lower latency). The previous 100,000-row version measured 4.4% slower locally with the same binaries.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve nested
JSONpath read performance withmap_with_bucketsby reusing thread-local serializations forDynamicvalues.Workflow [PR]
Sync PR [sync-upstream/pr/113344]
Version info
26.10.1.783-master(included in26.10and later)