Skip to content

Cache resolved streams in wide part reader - #131011

Merged
CurtizJ merged 7 commits into
masterfrom
kshokhin/wide-reader-resolved-substreams
Nov 16, 2026
Merged

CurtizJ merged 7 commits into
masterfrom
kshokhin/wide-reader-resolved-substreams

Conversation

@kirillshokhin

@kirillshokhin kirillshokhin commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Resolve stream name and average value size hint once for known streams in MergeTreeReaderWide::addStreams.

This avoids stream name resolution per granule (e.g. in MergeTreeReaderWide::getStream and value size hint callbacks in readData).
Streams discovered while deserializing the prefix (such as those of Dynamic and JSON) are still resolved per call. Since the prefix is deserialized by multiple threads in parallel, we'd need some synchronization for the resolved streams collection, so, to keep this PR small, caching them can be implemented as a follow-up if necessary.

Also, some temporary copies are avoided in getNameForSubstreamPath and escapeForFileName gains a fast path for names that need no escaping.

This change improves reads of many short mark ranges from columns with many substreams, like the ones of the proposed native histograms implementation for the TimeSeries engine #122051.

On a c8g.8xlarge machine the new test shows a 1.3x to 1.75x speedup over master commit 039d5de4.

Related: #130784

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...


Workflow [PR]
Sync PR [sync-upstream/pr/131011]

Version info

  • Merged into: 26.11.1.2457-master (included in 26.11 and later)

Stream name and average value size hint are resolved once for every
stream known in `MergeTreeReaderWide::addStreams`. Substreams discovered
only by the prefix (such as those of `Dynamic` and `JSON`) are still
resolved per call.
Use less temporary strings in `getNameForSubstreamPath`.
`escapeForFileName` reserves the result upfront and returns the input as
is when nothing needs escaping.
@kirillshokhin kirillshokhin added pr-performance Pull request with some performance improvements pr-not-for-changelog This PR should not be mentioned in the changelog labels Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [da01bbf]

Summary: ✅


AI Review

Summary

Reviewed #131011 at da01bbfd641d29eac725090006ceaf72f232f764. The change caches known stream names and value-size hint slots in MergeTreeReaderWide, preserves resolution for streams discovered during prefix deserialization, and reduces temporary string construction. No actionable findings. The focused performance test and reported before/after measurements support the optimization.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing da01bbfd6 with master d89be9791 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

6 object files changed (+28.89 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeReaderWide.cpp.o 406.61 KiB 432.87 KiB +26.26 KiB (+6.46%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.63, programs/clickhouse-keeper ×0.64 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 13.9 s +10.2 s (+280%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.4 s +5.3 s (+250%)
Compile time of recompiled translation units

10 translation units recompiled, 29 s compile time in total, 10 of them have a recent master baseline.

Job report

@CurtizJ CurtizJ self-assigned this Nov 12, 2026

@CurtizJ CurtizJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CurtizJ

CurtizJ commented Nov 16, 2026

Copy link
Copy Markdown
Member

Perf test:
Screenshot 2026-11-16 at 14 22 30

@CurtizJ
CurtizJ enabled auto-merge November 16, 2026 13:23
@CurtizJ

CurtizJ commented Nov 16, 2026

Copy link
Copy Markdown
Member

@groeneai, please investigate the CI failures in this PR (commit da01bbf) and fix them, or link existing fixes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=131011&sha=da01bbfd641d29eac725090006ceaf72f232f764&name_0=PR

Also, 1 failure in the private sync PR.

@CurtizJ
CurtizJ added this pull request to the merge queue Nov 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

I checked the CI report for da01bbf: there are no public CI failures to fix. All 118 executed jobs are OK (81 skipped).

  • The Failed: 3 / Failed: 1 counters on Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) and Stateless tests (arm_binary, AsyncInsert, s3 storage, sequential) are NOT_FAILED notices, not failures: 01283_max_threads_simple_query_optimization, 03273_group_by_in_order_still_used_when_group_by_key_doesnt_match_order_by_key, 01414_push_predicate_when_contains_with_clause and 01168_mutations_isolation_3 passed while still listed in parallel_replicas_blacklist.txt / async_insert_blacklist.txt. The same notices show up on master (269 to 788 master runs each in the last 14 days), so they are not related to this PR.
  • The earlier Build (arm_tidy, 3/4) failures were on 73c9561 and 0f61f27 and are fixed by da01bbf itself; all four arm_tidy shards are green at this commit.
  • The failure in the private sync PR is not visible to me (CH Inc sync, private, not actionable by me).

Merged via the queue into master with commit 4553bee Nov 16, 2026
204 checks passed
@CurtizJ
CurtizJ deleted the kshokhin/wide-reader-resolved-substreams branch November 16, 2026 17:24
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-not-for-changelog This PR should not be mentioned in the changelog pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants