Skip to content

Replace the arm-unstable arrayReduce('avg') query of the vectorize_aggregation_combinators performance test - #130757

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-perf-vectorize-aggregation-combinators-arrayreduce-avg
Nov 12, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-perf-vectorize-aggregation-combinators-arrayreduce-avg

Conversation

@groeneai

@groeneai groeneai commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #107436

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

vectorize_aggregation_combinators #4 (SELECT arrayReduce('avg', v) FROM array_data, 10M rows of 16-element arrays) is 12-20% slower in 23 of 1036 arm PR builds since 2026-11-07 and in 7 consecutive master builds (none is faster by more than 9%): 9 Performance Comparison (arm_release, ...) reds on PRs that do not touch it, as asked in #107436 (comment).

The slow builds execute the same instructions but take one extra branch miss per row (about 10M, 13-18 cycles each), all in addBatchArray of AggregateFunctionAvg<UInt64>, which is byte-identical in the fast and slow binaries and only placed elsewhere. A PR that is slow at one head is fast at another (1.19x, then 1.00x). No merged PR introduced it: the mode was +14% before #127206, which made the query 27% faster, so the same ~55 ms now crosses the threshold.

The query gets disabled="1" (number and text kept), and query 5 runs it over 312500 rows of 1024-element arrays, so a per-row mode costs at most about 2 ms (1%). max_block_size = 1024 keeps its Log blocks at 1M elements like query 4; at the default the blocks are 512 MiB, and perf.py purges jemalloc before each run, so half the time was page faults. Trade-off: the per-row state handling of arrayReduce is much less visible; the batch path the test was added for is 40% of the profile instead of 19%.

Validation (x86, perf-reference binary of the base): perf.py --print-queries keeps 0-4 unchanged; three A/A perf.py runs with the CI flags skip query 4 and time query 5 at 0.203-0.205 s, A/A within 1.3%; per run 7 ms system time, 2.6k page faults, 22 MiB. The arm jobs of this PR measure query 5 on arm.

🤖 Generated with Claude Code


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

Version info

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

groeneai and others added 2 commits November 11, 2026 10:29
…-array variant

Query 4 (`arrayReduce('avg')` over 10M rows of 16-element arrays) takes one
extra branch miss per row in some arm builds, depending on where unrelated
code places `addBatchArray`, so it fails the perf check of unrelated PRs.
Disable it (keeping its number) and append the same query over 1024-element
arrays with the same 160M elements, so a per-row mode is bounded.

WIP: implements fix-plan r0 exactly; IMPL measured that the new query
allocates 512 MiB blocks (replan pending).

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

`Log` reads `max_block_size` rows per block whatever the row width, so at
the default 65505 a block of 1024-element `UInt64` arrays is 512 MiB.
perf.py purges jemalloc before each run, so every run gave that memory back
and re-faulted it, and about half of the query's time was kernel page-fault
work instead of `arrayReduce`. `max_block_size = 1024` keeps the blocks at
1M elements (8 MiB), like query 4's 65505 x 16, and 312500 rows keep the
query near 0.2 s.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)

Second-model review (Gate B) of 20347e9c73cf: 0 findings. Own review: 2 nits, no blocker or major.

Finding Verdict
💡 PR description: one sentence had no referent ("the same PR is fast at its next head") AGREE, rewritten
💡 The first commit's message describes an intermediate state (160M elements, before max_block_size = 1024) AGREE, kept: the second commit corrects it, and commits are not amended

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this? It disables query 4 of vectorize_aggregation_combinators (arrayReduce avg over 16-element arrays), which is 12-20% slower in some arm builds from one extra branch miss per row in byte-identical code at another address, and adds the same query over 1024-element arrays with max_block_size = 1024, so a per-row mode costs about 1%.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The slow mode is arm-only and per build, so it cannot run on my x86 host; the CI data is the evidence (23 of 1036 arm PR builds 1.12-1.20x slower, one extra branch miss per row in addBatchArray, byte-identical code at another address). The property the fix relies on is measured locally: per-row leaves 23.4% of the profile for query 4, 1.5% for query 5.
b Root cause explained? One branch of addBatchArray<AggregateFunctionAvg<UInt64>> per row (the exit of its 4-iteration vector loop over 16 elements) is mispredicted in some arm code placements: ~10M misses, ~55 ms, +17-20% since #127206 made the query 27% faster, above the adaptive threshold. No merged PR introduced it.
c Fix matches root cause? The mode costs per row; query 5 does 2x the elements on 32x fewer rows (312500), so any per-row mode is bounded at about 2 ms (1%). No threshold change, no removed operation.
d Test intent preserved / new tests added? The batch path the test was added for is 40% of query 5's profile (19% in query 4). Query 4 stays, disabled, with its number and text. Trade-off: per-row state handling is much less visible.
e Both directions demonstrated? Per-row leaves 23.4% (query 4) vs 1.5% (query 5); at the default block size a 1024-element variant spent 174 of 343 ms in page faults (140k faults), with max_block_size = 1024 7 ms (2.6k). The arm side is measured by this PR's own arm perf jobs.
f Fix is general across code paths? Queries 2 and 3 read the same 16-element table through sumArray; they are clean on arm since 2026-11-07 (0 and 2 of 1036 builds over 1.10x, no recurring mode), so they are not changed.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A: performance test change, no product code. Query 5 keeps Array(UInt64) and max_threads = 1.
h Backward compatible? (maintainer-approved exception only) Yes: queries 0-4 keep their numbers and texts (perf.py --print-queries), so their history is unaffected; query 5 starts its own.
i Invariants and contracts preserved? A disabled query keeps its index and is not run (perf.py); three A/A runs timed query 4 zero times. array_data is still created and dropped for queries 2 and 3; array_data_long is dropped.

Session id: cron:clickhouse-impl-slot-5:20261111-104100

@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [20347e9]

Summary: ✅


AI Review

Summary

PR #130757 disables the ARM-sensitive, 16-element arrayReduce benchmark while preserving its history index, and adds a 1024-element replacement with a query-local max_block_size. No actionable code defects were found at 20347e9c73cf9a392077738d82c41d072c4197ca. Validation of the replacement on ARM remains outstanding.

Missing context / blind spots
  • ⚠️ All six ARM performance comparison shards are still PENDING in the current CI report. The reported local A/A measurements use x86, so there are no completed replacement-query measurements on the affected architecture.
Tests
  • ⚠️ Complete the ARM performance comparison and inspect query 5 timings and statistical noise to substantiate the stability claim before retiring query 4. No additional functional test is needed for this benchmark-only change.
Final Verdict

Status: ⚠️ Request changes — pending ARM performance evidence. Minimum action: provide completed ARM measurements for query 5; no code changes are currently requested. No new inline findings were posted.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Nov 11, 2026
@Algunenano Algunenano added the can be tested Allows running workflows for external contributors label Nov 11, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Nov 11, 2026

@alexey-milovidov alexey-milovidov 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.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Nov 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 12, 2026
Merged via the queue into ClickHouse:master with commit b5e3d10 Nov 12, 2026
551 of 553 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 12, 2026
@clickhouse-gh clickhouse-gh Bot added comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). pr-ci 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