Repository navigation
Speed up -ForEach over arrays of Nullable values - #127846
valerypetrov wants to merge 7 commits into
Conversation
…`Nullable` `-ForEach` hands the elements of an array to its nested function with `addBatchConsecutivePlaces`. For `Nullable` elements the nested function is `AggregateFunctionNullUnary`, which did not override it, so the default implementation made one virtual call to the nested `add` per element. This is the outer aggregation of every PromQL `sum`, `avg`, `min` and `max`, whose grids are `Array(Nullable(Float64))`. Pass each run of non-NULL rows to the nested function in one call instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Splitting the rows into runs of non-NULL values made `-ForEach` slower when NULLs are frequent: with alternating NULLs every run is one row, and each still costs a virtual call. Add `addBatchConsecutivePlacesNotNull`, the counterpart of `addBatchSinglePlaceNotNull`, so `AggregateFunctionNullUnary` makes one call per array and the nested function skips the NULL rows in its own loop. Co-Authored-By: Claude Opus 5.5 <[email protected]>
dcb1241 to
43c90ef
Compare
|
Workflow [PR], commit [28e0153] Summary: ✅
AI ReviewSummaryThis PR speeds up Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
…onsecutive-places Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionsArgMinArgMax… |
16.09 MiB | 16.43 MiB | +346.55 KiB (+2.10%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionAvgWeighted.c… |
13.68 MiB | 13.93 MiB | +260.36 KiB (+1.86%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniq.cpp.o |
13.67 MiB | 13.88 MiB | +205.47 KiB (+1.47%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionRegr.cpp.o |
5.95 MiB | 6.09 MiB | +145.86 KiB (+2.39%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionCorr.cpp.o |
7.12 MiB | 7.25 MiB | +131.07 KiB (+1.80%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionQuantileExact… |
7.03 MiB | 7.16 MiB | +125.34 KiB (+1.74%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionCovar.cpp.o |
6.93 MiB | 7.06 MiB | +124.80 KiB (+1.76%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSparkbar.cpp.o |
5.35 MiB | 5.47 MiB | +120.66 KiB (+2.20%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupArrayMov… |
5.96 MiB | 6.07 MiB | +113.34 KiB (+1.86%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupArray.cp… |
4.55 MiB | 4.65 MiB | +103.33 KiB (+2.22%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionDeltaSumTimes… |
3.53 MiB | 3.63 MiB | +102.34 KiB (+2.83%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupNumericI… |
5.82 MiB | 5.89 MiB | +76.38 KiB (+1.28%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionQuantile.cpp.o |
3.69 MiB | 3.77 MiB | +75.03 KiB (+1.98%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupUniqArra… |
2.58 MiB | 2.65 MiB | +68.07 KiB (+2.58%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionQuantileDeter… |
2.91 MiB | 2.97 MiB | +65.66 KiB (+2.21%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionSum.cpp.o |
3.90 MiB | 3.96 MiB | +63.55 KiB (+1.59%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionQuantileInter… |
3.69 MiB | 3.74 MiB | +60.27 KiB (+1.60%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionQuantileGK.cp… |
3.41 MiB | 3.46 MiB | +59.84 KiB (+1.72%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.23 MiB | 3.28 MiB | +54.24 KiB (+1.64%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionUniqCombined1… |
3.23 MiB | 3.28 MiB | +54.24 KiB (+1.64%) |
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.
Slowest function optimization changes (ThinLTO)
Median per-function time ratio to the master baseline: programs/clickhouse ×0.63, programs/clickhouse-keeper ×0.69 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.
| Binary | Function | Master | PR | Δ vs median |
|---|---|---|---|---|
programs/clickhouse |
DB::registerFunctionConversion(DB::FunctionFactory&) |
5.7 s | 14.3 s | +10.7 s (+297%) |
programs/clickhouse |
_ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… |
3.4 s | 7.5 s | +5.3 s (+252%) |
Compile time of recompiled translation units
336 translation units recompiled, 2735 s compile time in total, 336 of them have a recent master baseline.
|
@groeneai , check why the CI is failing here. |
|
Neither failure is caused by this PR.
|
|
The fixing PR for the skipped performance reference build is #128453. |
The merge queue fast-forwards master over up to 5 merges in one push and
MasterCI runs once, for the push head. For a push, praktika read the changed
files of the head commit only (`gh api commits/{sha}`), so a job affected
only by an earlier commit of the same push was filtered as "Not affected by
the changed files and not required", and functional/integration shards
skipped themselves as "Only test files changed". At master c189bd9 (ClickHouse#128277
in `src/` + ClickHouse#128142 tests only) this skipped 95 jobs, including both
`Build (*_release_performance_reference)`, so PR performance runs based on it
fell back to the official build (`long_primary_key` +16% on amd, ClickHouse#127846).
At f760cbb all 32 builds were skipped.
Now a push event records its `before` (`_Environment.PUSH_BEFORE_SHA`), and
`GH.get_changed_file_statuses` walks first parents from the head down to it,
reading all pages of each commit's file list (`gh api --paginate`), and
unions them (the newest commit's status wins). If the files cannot all be
known - an all-zero or malformed `before` (created branch), a failed or
malformed read, a commit at GitHub's 3000-file listing limit, a walk that
does not reach `before` within 50 commits - the result is `None` with a
warning, never a partial list, and it is not cached. `store_data.py` keeps
`None` for push events, so no job is filtered by it (`Job.is_affected_by`);
before, a failed read stored `[]`, which filtered every non-required job.
Without `before` (local runs, the native orchestrator) the head-only read
is unchanged; PR, merge queue, schedule and dispatch are unchanged.
Validated locally against the real GitHub API by replaying the 404 batched
master pushes of October: the result equals the union of every pushed
commit's files (re-parsed independently, commit lists from git) on 402, and
is unknown on the 2 that contain a 3000-file commit (ClickHouse#126194, and the docs
translation ClickHouse#124860); the job filter keeps 14,871 more job-runs on 131
pushes, plus 952 test shards that self-skipped now run in full, ~+7.8% of
October's 203,420 master job-runs, including both reference builds on 106
pushes. 100 single-commit pushes give identical statuses, with one request
for heads of up to 100 files.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onsecutive-places Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ojection_where Master reverted the failing test in 6fd7777; this brings the branch up to date so CI runs against it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onsecutive-places Co-Authored-By: Claude Opus 5.5 <[email protected]>
-ForEachhands the elements of an array to its nested function withaddBatchConsecutivePlaces(#121137). ForNullableelements the nested function isAggregateFunctionNullUnary, which did not override it, so the default implementation made one virtual call to the nestedaddper element. This is the outer aggregation of every PromQLsum,avg,minandmax, whose grids areArray(Nullable(Float64)). NowAggregateFunctionNullUnarymakes one call per array to a newaddBatchConsecutivePlacesNotNullof the nested function, the counterpart ofaddBatchSinglePlaceNotNull, whose loop skips the NULL rows and callsadddirectly. (A first version that passed runs of non-NULL rows was slower when NULLs are frequent, because every one-row run still cost a virtual call.)Tests: a new functional test pins
sumForEach,avgForEach,minForEach,maxForEach,countForEach,groupArrayForEachanduniqExactForEachwith NULLs at the start, at the end, between values and at a position in every row, and compares many rows per key with the same aggregation over the elements. Theaggregate_function_for_eachperformance test getsArray(Nullable(Float64))queries.Measured with the same compiler and flags, only this change toggled, best of 4 runs of 5:
max_threads = 1)SELECT sumForEach(a) FROM tSELECT maxForEach(a) FROM tSELECT k, avgForEach(a) FROM t GROUP BY kSELECT sumForEach(a) FROM tSELECT maxForEach(a) FROM tSELECT k, avgForEach(a) FROM t GROUP BY kSELECT sumForEach(a) FROM tSELECT maxForEach(a) FROM tSELECT k, avgForEach(a) FROM t GROUP BY kSELECT sumForEach(a) FROM tSELECT maxForEach(a) FROM tSELECT k, avgForEach(a) FROM t GROUP BY kRelated: #121137
🤖 Generated with Claude Code
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up
-ForEachaggregate functions over arrays ofNullablevalues, such as the outersum,avg,minandmaxof PromQL queries.Workflow [PR]
Sync PR [sync-upstream/pr/127846]