Repository navigation
Stabilize the two arrayLast filter queries of the array_first_last performance test - #122483
Conversation
The fixture rows are arrayResize([toUInt64(number)], N) = [number, 0, ..., 0], and `x -> x > 3` is true only for element 1. So arrayFirst (queries ClickHouse#8 and ClickHouse#10) stops at the first element it checks, while arrayLast (ClickHouse#9 on the 32-element table, ClickHouse#11 on the 128-element one) walks backward over 31 or 127 rejected elements per row before it reaches element 1. The lambda, the tables and the output reservation are the same for the twins; only the backward scan differs. Only the scanning queries are bimodal. Performance comparison runs between 2026-09-12 and 2026-09-26, client_time, runs moving more than 15% either way: arm: ClickHouse#8 4 of 3868, ClickHouse#9 336 of 3630 (37 of 384 on master), ClickHouse#10 4 of 3843, ClickHouse#11 178 of 3708 (17 of 398 on master) amd: ClickHouse#8 0 of 1107, ClickHouse#9 17 of 1053, ClickHouse#10 1 of 1086, ClickHouse#11 40 of 1051 The moves go both ways in about equal numbers (arm ClickHouse#9: 156 slower, 180 faster), so they do not come from the compared builds. On arm the slow level is extra user CPU time on identical work: over the 156 runs where the new server was slow, ClickHouse#9 user time was 54.1 -> 63.3 ms, with the same soft page faults (816 vs 815), system time (1.45 vs 1.49 ms) and memory usage. On PR ClickHouse#117153 (arm 1/6, job 107092288374) all 7 runs of ClickHouse#9 took 53.1-53.6 ms on one server and 63.1-64.4 ms on the other, where ClickHouse#11 stayed fast. The learned in-tree thresholds of ClickHouse#9 and ClickHouse#11 are 27% and 23%, and the performance dashboard scored that +19.2% as a confirmed regression. Change the predicate of ClickHouse#9 and ClickHouse#11 to `x -> x = 0`. It is true for the trailing zero, which is the element arrayLast checks first, so all four filter-path queries evaluate the lambda over every element and then stop at their first check, like the stable arrayFirst twins. The query order and count are unchanged, so the query indices keep their identity. The new query texts start without learned thresholds. Cost: no query times a backward scan over many rejected elements any more (the arrayFirst queries never timed a long forward one). The output reservation the test was added for is still measured. Local check on x86 with the official 26.10.1.761 master build, perf.py, 7 runs: old ClickHouse#9 108.0 ms vs ClickHouse#8 63.7 ms; new ClickHouse#9 74.3 ms vs ClickHouse#8 75.1 ms, new ClickHouse#11 56.9 ms vs ClickHouse#10 59.8 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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; its one nit (a wording overstatement in this description) was fixed before publication. Session id: cron:clickhouse-review-slot-48:20260926-222500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260926-215800 |
|
Workflow [PR], commit [14385fe] Summary: ✅
AI ReviewSummaryThis PR rewrites the two Findings
Missing context / blind spots
Final VerdictChanges requested: the benchmark rewrite needs arm perf evidence on this exact head before the stability claim is established. |
| <query>SELECT arrayLast(x -> x = 0, x) FROM array_first_last_32 FORMAT Null</query> | ||
| <query>SELECT arrayFirst(x -> x > 3, x) FROM array_first_last_128 FORMAT Null</query> | ||
| <query>SELECT arrayLast(x -> x > 3, x) FROM array_first_last_128 FORMAT Null</query> | ||
| <query>SELECT arrayLast(x -> x = 0, x) FROM array_first_last_128 FORMAT Null</query> |
There was a problem hiding this comment.
The contract of this change is "the replacement arrayLast filter queries are stable on the CI runners that were flagging array_first_last #9 and #11". We still do not have that proof on this head: all Performance Comparison shards are skipped because the PR is not labeled pr-performance, and the only after-change numbers in the description are local x86 runs. Since array_first_last.xml has 12 queries and perf CI normally samples 10, I would want an exact-head arm perf run that actually executes these two slots before we rewrite the benchmark around them.
0c64d50
Related: #117153
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: CI-only change.
Description
array_first_last #9and#11(arrayLast(x -> x > 3, x)on the 32- and 128-element tables) take one of two times on the same code. On #117153 the dashboard scored#9+19.2% as a confirmed regression (arm 1/6, report): 7 of 7 runs took 53.1-53.6 ms on the old server and 63.1-64.4 ms on the new one, where#11stayed fast. Master too: arm 1/6 @350963d1,#954.8 -> 65.0 ms,slower. In-tree,#9has already learned a 27% threshold.Every row is
[number, 0, ..., 0], sox > 3matches only element 1:arrayFirst(#8,#10) stops at its first check,arrayLastwalks back over 31 or 127 rejected elements per row. Only the scanning queries are bimodal (runs moving more than 15%, 14 days):The moves go both ways about equally often; on arm the slow level is extra user CPU time with the same page faults, system time and memory.
I changed the predicate of
#9and#11tox -> x = 0, which matches the trailing zero thatarrayLastchecks first, so all four filter queries do the per-row work of the stablearrayFirsttwins. Query order is unchanged. Cost: no query times a long scan over rejected elements any more; the output reservation this test was added for (#118188) is still measured.Locally (x86, official master build,
perf.py, 7 runs): old#9108.0 vs#863.7 ms; new#974.3 vs#875.1 ms, new#1156.9 vs#1059.8 ms.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122483]
Version info
26.10.1.789-master(included in26.10and later)