Skip to content

Stabilize the nested-array queries of the array_first_last performance test - #122691

Merged
Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:stabilize-array-first-last-nested
Sep 28, 2026
Merged

Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:stabilize-array-first-last-nested

Conversation

@groeneai

@groeneai groeneai commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120510

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):

Not required: CI-only change.

Description

array_first_last #7 (arrayLast(x -> 1, nested_values)) takes a different time in each server process. On #120510 it was the only red of amd 6/6: 30 of 30 runs took 12.60-13.98 ms on the old server, 14.73-16.49 ms on the new one (dashboard: +15.5%, confirmed_regression), while #6 (arrayFirst, same column) went 14.40 -> 13.61 ms. Master too: amd 1/6 @ 66276279, 13.18 -> 15.67 ms.

Runs moving >15% between the servers (amd, 14 days, raw samples):

#4 #5 #6 #7
all 2/617 3/652 0/641 50/633
master 2/416 2/465 0/455 36/440

arm: at most 1 of ~1300 runs each. Over 524 runs measuring both, #6 and #7 move in opposite directions (r = -0.53; in 33 of 37 where #7 moved, #6 moved the other way), while the tuple twins #4/#5 move together (+0.42).

Each nested_values row holds 32 inner arrays, so rows are 256/512 bytes apart (inner offsets/data) and every row is read at the same few offsets of each memory page. Which offsets depends on the allocation: jemalloc (cache_oblivious) puts each large allocation at a random multiple of 64 bytes within its first page, once per server fill.

I changed the rows to 31 inner arrays: rows are 248/496 bytes apart, so one query walks through every page offset. Query texts and per-row work are unchanged; #4/#5 keep 32 elements.

Locally (x86, official master build, 16 separately filled copies per layout in one server, 20 rounds) no layout shows the spread, so this machine cannot confirm the mechanism: #7 across copies 14.14-14.68 ms (32, random offsets), 13.93-14.27 ms (32, page-aligned), 13.95-14.32 ms (31). The level of #7 stays (0.98x); #7/#6 goes from 1.11 to 1.03.

🤖 Generated with Claude Code


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

Version info

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

Query ClickHouse#7 of tests/performance/array_first_last.xml (arrayLast over
Array(Array(UInt64))) takes a different time in each server process of
the same build. In 14 days of Performance Comparison runs on amd it moved
by more than 15% between the two servers in 50 of 633 runs, 36 of them
master against master, while ClickHouse#6 (arrayFirst over the same column) moved
in 0 of 641 and the tuple queries ClickHouse#4/ClickHouse#5 in 2 and 3; arm is quiet. Per
run, ClickHouse#6 and ClickHouse#7 move in opposite directions (r = -0.53 over 524 amd runs;
in 33 of the 37 runs where ClickHouse#7 moved by more than 15%, ClickHouse#6 moved the other
way), while ClickHouse#4/ClickHouse#5 move together (r = +0.42).

Each nested_values row holds 32 inner arrays of 2 UInt64, so rows are 256
bytes apart in the inner offsets and 512 bytes apart in the data. ClickHouse#6 and
ClickHouse#7 read one inner array per row, so for the whole query every row is read
at the same position modulo 256/512 bytes, i.e. at the same few offsets
inside every memory page. Which offsets those are depends on where the
column is allocated: jemalloc is built with cache_oblivious, which puts
every large allocation at a random multiple of 64 bytes inside its first
page, and the table is filled once per server. So each server reads the
column at its own fixed page offsets.

Fill nested_values with 31 inner arrays per row. Rows are then 248/496
bytes apart and the read position walks through every offset of the page
within one query, so the timing no longer depends on the allocation. The
query texts and the per-row work (one copy of a 2-element array per row,
250000 rows) are unchanged.

Local check with the official master build 26.10.1.906 on a Xeon 6975P-C:
16 separately filled copies of the table per arm in one server, measured
round-robin for 20 rounds. This machine does not show the spread with
either layout (ClickHouse#7 across copies: 14.14-14.68 ms with 32 elements and
random allocation offsets, 13.93-14.27 ms page-aligned with
MALLOC_CONF=cache_oblivious:false, 13.95-14.32 ms with 31 elements), so
it cannot confirm the mechanism and the change rests on the CI data. The
level of ClickHouse#7 stays (31 vs 32 elements: 0.98x); ClickHouse#7/ClickHouse#6 goes from 1.11 to
1.03.

Related: ClickHouse#120510

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-human PR origin: human review feedback on a groeneai PR labels Sep 28, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex): 0 findings on this head. My own cold review of the diff, done before reading the implementation's evidence, found no blocker or major. I re-derived the table and the #6/#7 correlation from the raw run samples in CIDB (r = -0.525 over 526 amd runs) and checked the jemalloc placement in contrib/jemalloc (arena_cache_oblivious_randomize). Of its four nits, two (a wording slip and the unnamed data source of the table) were fixed in this description before publication; two are noted, not blocking: the XML comment explains the mechanism rather than the effect and could be read as covering tuple_values too, and only post-merge amd master runs can confirm the change.

Session id: cron:clickhouse-review-slot-49:20260928-142200

@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-review-human PR origin: human review feedback on a groeneai PR labels Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5ae9ce9]

Summary: ❌

job_name test_name status info comment
Performance Comparison (amd_release, master_head, 2/6) FAIL Performance dashboard
qbit_l2_distance_bfloat16_memory #0 FAIL dashboard IGNORED
qbit_l2_distance_bfloat16_memory #1 FAIL dashboard IGNORED
Performance Comparison (arm_release, master_head, 2/6) FAIL Performance dashboard
lower_upper_utf8_mixed_ascii #4 FAIL dashboard IGNORED
vectorize_aggregation_combinators #0 unstable query history IGNORED

AI Review

Summary

This PR changes tests/performance/array_first_last.xml so the nested_values rows contain 31 inner arrays instead of 32, with the goal of removing allocator-dependent page-offset noise from the nested-array arrayFirst/arrayLast benchmarks. The fixture edit itself is small, but the branch still does not contain the measurement needed to prove that the new layout is actually more stable on the amd CI runner that exposed the problem.

Findings

⚠️ Majors

  • [tests/performance/array_first_last.xml:55] The PR's contract is to stabilize the nested-array queries of array_first_last, but the current branch still does not provide evidence that range(31) achieves that. The current PR workflow ran only the lightweight checks and skipped the Performance Comparison shards, so we only know that the old 32-element layout was noisy; we do not yet know that this replacement fixes the variance instead of just changing the workload. Please attach a focused before/after perf run for this exact fixture or rerun the PR with perf CI enabled.
Final Verdict

Changes requested: the benchmark update still needs a before/after measurement on the new 31-element layout before it is safe to merge as a stabilization fix.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 28, 2026
SELECT
arrayMap(x -&gt; (x, x), range(32)),
arrayMap(x -&gt; [x, x], range(32))
arrayMap(x -&gt; [x, x], range(31))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes the benchmark workload to claim better stability, but this PR is not labeled pr-performance, so all six Performance Comparison shards are skipped and the new 31-element layout never gets measured on the amd runner that showed the inter-server variance. The existing evidence proves the old 32-element layout is noisy; it does not yet prove that this replacement is stable. Please attach a focused before/after run for this layout or rerun with perf CI enabled.

@groeneai
groeneai requested a review from egor-click September 28, 2026 15:20
@Algunenano Algunenano self-assigned this Sep 28, 2026
@Algunenano Algunenano added the pr-performance Pull request with some performance improvements label Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 5ae9ce9

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (amd_release, master_head, 2/6) / qbit_l2_distance_bfloat16_memory #0, #1 dashboard confirmed_regression, client_time 0.204 -> 0.416 s (+104.4%) and 0.119 -> 0.198 s (+65.6%), also slower in the shard's own report, and both reproduced after the harness restart (the other 7 flagged queries did not). This PR changes only tests/performance/array_first_last.xml, so both servers run the same source and the slowdown belongs to this build of the new server. No other amd run of the last 14 days slowed either query by more than 15% (796 runs, 549 of them master-vs-master) a fix task is created (its fix direction awaits a maintainer decision; fixing-PR link to follow on this PR)
Performance Comparison (arm_release, master_head, 2/6) / lower_upper_utf8_mixed_ascii #4 dashboard confirmed_regression, client_time 0.0118 -> 0.0143 s (+20.6%), while the shard's own report does not flag the query (3 too long only; the unstable verdict on vectorize_aggregation_combinators #0 does not red a shard). It is a Memory-table query of another fixture #122728 (mine, open): it stabilizes exactly this query
Mergeable Check, PR rollups, red only because of the two shards above a fix task is created for the amd 2/6 row, and #122728 (mine, open) owns the arm 2/6 row

This PR's own queries ran on the amd 2/6 shard and were not flagged: array_first_last #6 and #7
measured 0.0132 -> 0.0124 s and 0.0133 -> 0.0127 s.

All 146 check runs completed (16 passed, 128 not selected, 2 red), Finish Workflow is green and
CH Inc sync passed. CIDB has no FAIL or ERROR test row on this head.

Session id: cron:our-pr-ci-monitor:20260928-200457

@Algunenano
Algunenano added this pull request to the merge queue Sep 28, 2026
Merged via the queue into ClickHouse:master with commit ce7f8c1 Sep 28, 2026
146 of 149 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... 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-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... groeneai-origin-review-human PR origin: human review feedback on a groeneai PR pr-ci 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