Repository navigation
Restore pooling of non-poolable serializations in DataTypesCache - #117655
Conversation
Follow-up to #115852, which merged before a last review comment was addressed: #115852 (comment) Making DataTypesCache::getCacheElement skip caching the serialization for types with supportsPooling() == false (e.g. SerializationJSON) reintroduced the exact performance regression the original PR fixed, but only for Dynamic(JSON): a fresh SerializationJSON was rebuilt on every row again in SerializationDynamic's text fast path. That restriction was more conservative than necessary. supportsPooling()'s contract, and SerializationJSON's own documented failure mode, are both specifically about reuse *across queries* (e.g. a cached DateTimeNode capturing the wrong session_timezone). The cache already prevents exactly that: it is thread-local and is cleared on every query-context change and on session_timezone mutation. Reuse *within* one query is an established, trusted pattern already relied on elsewhere for the same objects, via ColumnDynamic's own per-column serialization_cache. I considered instead routing SerializationDynamic's text path through that per-column cache directly, but a ColumnDynamic instance is not always exclusive to one query: StorageMemory and the query result cache can hand the very same column instance to concurrently-running queries, and it has no invalidation hook at all, so pooling from the read side there would both race and reintroduce cross-query staleness. The thread-local cache with query/timezone-scoped invalidation is the safe place for this. Extend the added perf test with a Dynamic column holding JSON values, and replace the gtest asserting non-pooling with one asserting pooling within a query and invalidation across queries.
|
Workflow [PR], commit [c4e6648] Summary: ❌
AI ReviewSummaryThis PR restores query-scoped reuse of non-simple serializations in Final Verdict
LLVM Coverage Report |
getSerialization() returns shared_ptr<const ISerialization>; .get() is const ISerialization*, not ISerialization*.
|
I audited the pooling change against every
|
…ce claim - gtest_data_types_cache.cpp: InvalidatesNonPoolableSerializationsAcrossQueries compared a raw pointer captured after its owning SerializationPtr could already have been destroyed (the query scope it was built in had ended), so an unrelated later allocation reusing the same address could make the test pass even if cache invalidation were broken. Keep the first SerializationPtr alive across both scopes and compare through it instead. - DataTypesCache.h: the comment claimed allow_simdjson only "selects between two semantically equivalent JSON parsers." rapidjson's default flags (RAPIDJSON_PARSE_DEFAULT_FLAGS) omit kParseFullPrecisionFlag, so its Float64 parsing isn't correctly rounded the way simdjson's is, and it enforces no nesting-depth cap - a real value-level gap, not just an implementation choice. It's moot today because no getDataTypesCache() consumer performs text deserialization through a cached instance (only type resolution, binary serialization, and text output do), so the extraction tree's mutable caches and the parser choice are never exercised. Spell out that invariant explicitly so a future caller (e.g. a symmetrical Dynamic text-input fast path) doesn't reintroduce the cross-query hazard this cache doesn't protect against for deserialization. Addresses #117655 (comment) and #117655 (comment)
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
Follow-up for ClickHouse#110081, which moved build artifacts under the normalized workflow name. The baseline `llvm_coverage.info` produced by master now lives at `REFs/master/<sha>/masterci/llvm_coverage/llvm_coverage.info`, but `generate_diff_coverage_report.sh` still probed the old path without the `masterci` segment, so `Generate LLVM Coverage Diff Report` exhausted all 30 candidate commits and failed the `LLVM Coverage` job on every pull request, for example https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117655&sha=c4e6648b2ccbbedf97a6d5bab32c8a8c9cf01c9d&name_0=PR&name_1=LLVM%20Coverage (ClickHouse#117655).
…ons in DataTypesCache
Backport #117655 to 26.8: Restore pooling of non-poolable serializations in DataTypesCache
…ons in DataTypesCache
Backport #117655 to 26.7: Restore pooling of non-poolable serializations in DataTypesCache
Backport #117655 to 26.6: Restore pooling of non-poolable serializations in DataTypesCache
…erializations in DataTypesCache
Related: #115852
Follow-up to #115852, which merged before a last review comment was addressed: #115852 (comment)
That PR's
DataTypesCachefix madegetCacheElementskip caching the serialization for types withsupportsPooling() == false(e.g.SerializationJSON), to avoid a correctness bug where a query-context-dependent serialization (likeDateTime's baked-insession_timezone) could leak across queries on the same long-lived server thread. That was more conservative than necessary, and it reintroduced the exact performance regression the original PR fixed, but narrowed toDynamic(JSON):SerializationDynamic's text fast path was rebuilding a freshSerializationJSONon every row again.supportsPooling()'s contract, andSerializationJSON's own documented failure mode, are specifically about reuse across queries (its documented example is exactly the timezone case).DataTypesCachealready prevents that: it's thread-local, and is cleared on every query-context change and onsession_timezonemutation (added by the same earlier PR). Reuse within one query is an already-established, trusted pattern for the very same objects, viaColumnDynamic's own per-columnserialization_cache.I considered instead routing the text-serialization path through that per-column cache directly (as one reviewer suggested), but a
ColumnDynamicinstance is not always exclusive to one query:StorageMemoryand the query result cache can hand the very same column instance to concurrently-running queries, and that cache has no invalidation hook at all, so pooling from the read side there would both race and reintroduce cross-query staleness. The thread-local cache with query/timezone-scoped invalidation is the safe place for this.Also extends the perf test added by the original PR with a
Dynamiccolumn holdingJSONvalues (the previously-unproven path), and replaces the gtest asserting non-pooling with one asserting pooling within a query plus invalidation across queries.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Internal follow-up correcting an implementation detail from an unreleased change; no user-visible behavior change beyond restoring the intended performance characteristics of #115852 for
Dynamic(JSON)text output.Workflow [PR]
Sync PR [sync-upstream/pr/117655]
Version info
26.9.1.560(included in26.9and later)26.8.3.17,26.7.7.13,26.6.5.94