Skip to content

Don't allocate memory in the pipeline executor after every executed task - #124818

Merged
alexey-milovidov merged 10 commits into
masterfrom
executor-update-node-allocations
Oct 15, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
executor-update-node-allocations

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

After executing every task, PipelineExecutor::executeStepImpl created two queues of processors, and ExecutingGraph::updateNode created its two work stacks (boost::container::devector) and a vector. The first push into each of them allocated memory, freed at the end of the call. With small blocks this is done for every block of every processor: ExecutingGraph::updateNode was 9-21% of the time of ClickBench queries with max_block_size = 1, and the allocations (devector::insert_range_slow_path and the matching operator delete) were a noticeable part of it.

Now the queues and the work stacks are kept by executeStepImpl between the tasks and passed to updateNode (ExecutingGraph::UpdateNodeBuffers). They are cleared before use, in case a previous call stopped early or threw.

Measured on ClickBench hits (a 1% subset, 1M rows), single-threaded, together with the other PRs for the same issue (#124791): with max_block_size = 16, queries Q3, Q10, Q19, Q30, Q34 are 13-25% faster; with the default max_block_size the times are unchanged.

Related: #124795
Related: #124791

Changelog category (leave one):

  • Performance Improvement

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

The pipeline executor no longer allocates memory for its work queues after executing every task, which reduces the overhead of processing a block.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2511-master (included in 26.10 and later)

`ExecutingGraph::updateNode` allocated its two work stacks and `PipelineExecutor::executeStepImpl`
allocated two queues of processors for every executed task. Now they are kept between the tasks.

With small blocks this was a noticeable part of the time of `ExecutingGraph::updateNode`.

Related: #124795

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Oct 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [034e9f2]

Summary: ✅


AI Review

Summary

PR #124818 reuses the pipeline executor's task queues and ExecutingGraph::updateNode scratch buffers across tasks, reducing allocation overhead while releasing oversized buffers promptly. Reviewed head: 034e9f2102461fee2c7ead5a09c0cd516309f6ae. No actionable findings remain. The previous buffer-retention finding is addressed in the current code, and the previously reported ARM order_by_read_in_order slowdown does not reproduce in the latest available performance comparison: 20.2 ms → 18.4 ms.

Final Verdict

Status: ✅ Approve. No required changes or new inline comments.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 034e9f2102461fee2c7ead5a09c0cd516309f6ae was not compared: the CI logs cluster did not answer (exception 241, code 500: { "meta": [ { "name": "file", "type": "LowCardinality(String)" …).

See the job log for details.

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 1 query(s) improved out of 31 analysed

This PR keeps the updateNode working buffers and task queues alive across tasks in the pipeline executor, so it no longer allocates memory-tracked containers after every processor run. Every query runs this code. The clearest effect is on the short, highly parallel clickbench Q20: -41.4% faster (220 ms to 129 ms), with CPU time nearly halved. That change is large and consistent and stands as an improvement. Clickbench Q33 shows -6.1%, but that falls inside master's normal range for this noisy, aggregation-heavy query, so it stays at no change. tpch_adapted_1_official has no flagged queries.

clickbench

🟢 1 improved

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
🟢 20 improvement 220 129 -41.4% <0.0001 memory: Q20 is -41.4% faster and its CPU time fell from 2898 to 1527 ms. The PR stops allocating memory-tracked buffers and queues after every executed task, which removes shared tracker work on a short, many-thread query.

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
  • StressHouse run: a0134e74-1d8d-4f4a-b5fa-44309936f07e
  • MIRAI run: 8981e113-98af-4b9b-918e-bf39c1097e4b
  • PR check IDs:
    • clickbench_124972_1791951076
    • clickbench_124993_1791951076
    • clickbench_125001_1791951076
    • tpch_adapted_1_official_125018_1791951076
    • tpch_adapted_1_official_125062_1791951076
    • tpch_adapted_1_official_125084_1791951076

alexey-milovidov and others added 3 commits October 11, 2026 17:48
…e-allocations

Resolve the conflict in `ExecutingGraph.cpp`: master switched the scratch containers
of `updateNode` to the `-WithMemoryTracking` aliases; use them for the members of
`UpdateNodeBuffers`.
…utor

The executor keeps `Queue` and `UpdateNodeBuffers` between executed tasks to avoid
allocations. A single wide wave of ready processors could make them grow and hold that
memory until the end of `executeStepImpl`. Release a buffer instead of reusing it when it
has grown past `UpdateNodeBuffers::max_kept_capacity` elements.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e call

Previously oversized `UpdateNodeBuffers` were released only at the beginning of
the next `updateNode` call, so a worker thread waiting for the next task could
keep the memory of a wide wave of updates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124818&sha=2ecc3eafad1ce0b9dc68d5bfff6c3ed9177521ae&name_0=PR&name_1=Performance%20Comparison%20%28arm_release%2C%20master_head%2C%201%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. (iceberg_suite_local_tpch #8 / iceberg_suite_s3_tpch #8 were flagged as slower on ARM in 11 different PRs, including master, over the last 14 days, so this looks like a flaky perf test unrelated to this PR.)

@groeneai

Copy link
Copy Markdown
Collaborator

I measured it in CIDB (arm_release, master_head, last 14 days). It is not run-to-run noise, and since #125094 was merged, master itself runs these queries in the slow state.

#125094 makes the targets created in cmake/linux/default_libs.cmake (libunwind, libcxx, libcxxabi, glibc-compatibility, harmful) compile with -fPIC instead of the CI compiler's default -fPIE. I'll find which part of that causes the slow state and send the fix as a separate PR that keeps the Fedora build working, with its arm perf run as the A/B. I'll follow up here.

@groeneai

Copy link
Copy Markdown
Collaborator

I opened #125488 as the fix. It compiles libcxx, libcxxabi and libunwind with -fPIE again (the CI compiler's default). That restores their pre-#125094 aarch64 objects and ThinLTO bitcode byte for byte (83 of 83), and every other compile command stays as on master. #125094's Fedora fix is kept: with a clang that defaults to -fno-pic, the PIE still links.

A slow #125094 arm binary and a fast one on the same base differ only in 122 functions of these three libraries (TLS descriptor sequences and GOT loads instead of direct accesses). I have not found how that slows the hash-join build on Graviton, so the arm performance run of #125488 is the A/B: since master is now in the slow state, iceberg_suite_{local,s3}_tpch #7/#8 should come out at about 0.8x there.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai for the analysis: the iceberg_suite_{local,s3}_tpch slowdown on ARM is unrelated to this PR and is tracked by #125488. I merged master to pick up #125456, which fixes the test_storage_delta failures (test_writes_timestamp_ntz_annotation_nested, test_write_to_table_with_unsupported_writer_feature_is_rejected) seen in the last run.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only failure on 164328fd66f1, Upgrade check (amd_release) (UNKNOWN_IDENTIFIER from MutatePlainMergeTreeTask retrying a mutation on a revived DETACH PART tombstone), is unrelated to this PR. It is tracked in #120975, and the fix is in progress in #125293. The ARM order_by_read_in_order review point is answered in its thread: it does not reproduce on the current head.

# Conflicts:
#	src/Processors/Executors/Runtime/V1/PipelineExecutor.cpp
@alexey-milovidov alexey-milovidov self-assigned this Oct 15, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 15, 2026
Merged via the queue into master with commit 64cd742 Oct 15, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the executor-update-node-allocations branch October 15, 2026 19:27
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 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