Skip to content

Visit only updated inputs while IMergingTransformBase waits for first chunks - #131683

Merged
nihalzp merged 5 commits into
masterfrom
merging-transform-init-updated-ports
Nov 16, 2026
Merged

nihalzp merged 5 commits into
masterfrom
merging-transform-init-updated-ports

Conversation

@nickitat

@nickitat nickitat commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Performance Improvement

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

Faster pipeline startup for merging transforms with many inputs, e.g. reading in order from tables with many parts.


Until every input of a merging transform delivered its first chunk, IMergingTransformBase::prepare rescanned all inputs on each call, so starting a merge of N inputs cost O(N^2). The transform now overrides the prepare overload that receives the updated input ports. The first call still visits every input; later calls visit only the updated ones. A port is found by binary search in a vector of ports sorted by address, which costs one allocation per transform.

Time spent in the transform's prepare until the merge finishes, one-row inputs, single-threaded executor, master → patched:

N master patched
2 0.6 us 0.6 us
16 6.9 us 3.8 us
256 1.06 ms 64 us
10000 1.57 s 2.9 ms

In-order read of a 10k-part table:

  • max_threads = 1: 1.34 s → 0.48 s.
  • Parallel replicas, max_threads = 4: 0.95 s → 0.44 s.

Screenshot 2026-11-15 at 16 27 21

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

Version info

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

…st chunks

Until every input delivers its first chunk, `prepare` rescanned all inputs on
each call, so starting a merge of N inputs cost O(N^2). Override the `prepare`
overload that receives the updated input ports: the first call still visits
every input, later calls visit only the updated ones, found by binary search in
a vector of ports sorted by address (one allocation per transform).

Time spent in the transform's `prepare` until the merge finishes, one-row
inputs, master -> patched:
    N = 2:      0.6 us   -> 0.6 us
    N = 16:     6.9 us   -> 3.8 us
    N = 256:    1.06 ms  -> 64 us
    N = 10000:  1.57 s   -> 2.9 ms

In-order read of a 10k-part table, max_threads = 1: 1.34 s -> 0.48 s;
with parallel replicas and max_threads = 4: 0.95 s -> 0.44 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [438409b]

Summary: ✅


AI Review

Summary

The PR makes startup of IMergingTransformBase visit only updated inputs after its initial scan, tracks how many inputs still need their first chunk, and adds a performance test over 10,000 parts. Reviewed head 438409b3dc2bf8b62c8604961854be38bf490854, including executor notifications, delayed input registration, empty and finished inputs, and both prepare overloads. No actionable findings. The supplied before/after measurements and focused performance test support the performance claim.

Missing context / blind spots
  • ⚠️ The broader functional, sanitizer, and performance CI jobs have not completed at the reviewed head. The available fast test reports 14,818 passes and 4,378 skips. No local build or tests were run; completed CI results would close this validation gap.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 14, 2026
@nickitat nickitat added the ci-performance performance only label Nov 14, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Nov 14, 2026
nickitat and others added 2 commits November 14, 2026 23:46
The existing `read_in_order_many_parts` stops at 1000 parts, where the
quadratic startup of `IMergingTransformBase` is within the noise.

Idle 192-vCPU box, master -> patched: fill 1.3 s in both;
max_threads = 1: 1.26-1.33 s -> 0.45-0.48 s; max_threads = 4: 0.55 s -> 0.29-0.35 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…orts' into merging-transform-init-updated-ports
@nickitat nickitat removed the ci-performance performance only label Nov 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 438409b3d with master e78ca0f30 (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

24 object files changed (+24.76 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Merges/IMergingTransform.cpp.o 140.95 KiB 157.05 KiB +16.10 KiB (+11.42%)

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.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -42.1 s (-8%) in total before that adjustment.

Job report

@nickitat
nickitat marked this pull request as ready for review November 15, 2026 15:28
@nickitat
nickitat requested a review from nihalzp November 16, 2026 13:01
@nihalzp nihalzp self-assigned this Nov 16, 2026
@nihalzp
nihalzp added this pull request to the merge queue Nov 16, 2026
Merged via the queue into master with commit 7cf3add Nov 16, 2026
193 checks passed
@nihalzp
nihalzp deleted the merging-transform-init-updated-ports branch November 16, 2026 18:43
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. 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.

3 participants