Repository navigation
Conversation
…element `FunctionArray` built `Array(Array(T))` through `executeGeneric`, i.e. one virtual `ColumnArray::insertFrom` per (row, argument). That call makes a second virtual `insertRangeFrom` on the nested column (resize + out-of-line `memcpy`) and an `offsets.push_back`. In `complex_array_creation` (20M elements per query) this chain is 83-89% of the query in the arm CI CPU profiles, and it is the code that ran ~41% slower in a per-binary slow build on PR ClickHouse#128330. New `executeArray`, tried right before `executeGeneric`: - writes all element offsets in one pass; - fixed-width nested types (`isFixedAndContiguous`: ColumnVector of any T, ColumnDecimal, ColumnFixedString): one `insertRawUninitialized` for the whole result, then a raw copy per element. Copies of up to 64 bytes use `memcpySmallAllowReadWriteOverflow15`, longer ones `memcpy`: the 16-byte-step helper is slower than `memcpy` for long values (measured ~5% with 4 MB arrays in `ColumnArray::replicateNumber`, which uses the same split). The small copy's over-write lands on bytes the next copy rewrites or in the right padding; - other nested types: the same `insertRangeFrom` call `ColumnArray::insertFrom` made, after one `reserve`, so their results are identical by construction. x86 release, `max_threads = 1`, median of 75 runs (5 interleaved rounds): `[[zero], [zero]]` 0.090 -> 0.044 s, `[[], [zero]]` 0.092 -> 0.043 s, `[[toString(zero)], ...]` 1.12x, `[[toNullable(zero)], ...]` 1.08x, `[a, a]` with 8 KB / 4 MB elements 2.11x / 4.38x, 8-byte + 1-byte elements 1.64x. Results of the old and new binaries are byte-identical over 25 element types. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the summary comment above executeArray; the code states the same thing. 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) plus a separate cold review (0 findings). Session id: cron:clickhouse-review-slot-8:20261031-161800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261031-151400 |
|
cc @Ergus @rschu1ze, could you review this and add the |
|
Workflow [PR], commit [0a0bc46] Summary: ✅
AI ReviewSummaryThe PR optimizes Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
`ColumnArray::reserve(n)` reserves `n` elements of its own nested column too, so `out_nested.reserve(total)` in the generic branch of `executeArray` allocated room for one innermost element per inner array. With 200000 empty `Array(FixedString(256))` values that is a 51 MiB allocation for nothing, and `[a, a]` failed under a 20 MB memory limit that the previous `executeGeneric` loop stayed within. The same happens through `Tuple` and `Map` holding arrays. The previous loop did not reserve the nested column either, so drop the call. Measured on x86 release against the base, median of 75 runs: `[[toString(zero)], ...]` 1.12x, `[[toNullable(zero)], ...]` 1.05x (1.13x / 1.08x with the reserve); the fixed-width branch is unchanged. The test covers empty inner arrays of `Array`, `Tuple` and `Map` elements under a 20 MB limit; all three fail with the reserve. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 02a811fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261101-163005 |
… test Review asked for a performance test instead of the stateless test, so `05473_array_of_arrays_from_columns` is removed and the existing `complex_array_creation.xml` gets the shapes this change touches, after its two unchanged queries: - `Decimal64` and `FixedString(1)` inner elements (raw byte copy), - `String` and `Nullable(UInt8)` inner elements (`insertRangeFrom` path), - `[a, a]` with 8 KB inner arrays (the `memcpy` branch above 64 bytes). Official amd_release builds of master b1e2520 and of this PR, local `tests/performance/scripts/perf.py` run against two servers, median of 15 runs, master -> PR: 0.096 -> 0.052, 0.099 -> 0.050, 0.105 -> 0.056, 0.124 -> 0.072, 0.163 -> 0.147, 0.165 -> 0.157, 0.300 -> 0.170 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - 9e02bd1Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Performance Comparison jobs on this head have no red. Session id: cron:our-pr-ci-monitor:20261109-130005 |
Ergus
left a comment
There was a problem hiding this comment.
I don't see any tests to check the results of the new copy paths because performance test only measures time. It does not compare results against a reference.
Could you add back a small stateless .sql test that compares results. For example, compare [a, b] against arrayConcat([a], [b]) for range(number % 20)
Because 05473 seems to be removed.
Review asked for a stateless test that compares results, because the performance test only measures time. Each row counts the rows where `[a, b]` differs from `arrayConcat([a], [b])`; `[a]` with one argument copies its column with `insertRangeFrom` and does not reach the new code. Rows cover the raw byte copy (`UInt8`, `UInt64`, `Decimal128`, `FixedString(2)`, an always-empty argument, a constant argument, `Array` inside `Tuple`) and the `insertRangeFrom` path (`String`, `Nullable`, `Array(Array(UInt8))`). `complex_array_creation.xml` stays. Checked on a debug build: all rows 0, same output from the master snapshot binary, 50/50 randomized runs OK. Replacing every copy with zeros or defaults makes every row non-zero; zeroing only the `memcpy` branch above 64 bytes makes the `UInt64`, `Decimal128`, `Tuple` and `Const` rows non-zero. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, added back in 0a0bc46 as Checked locally: zeroing every copy makes every row non-zero, and zeroing only the |
Related: #128330
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Function
array(the[...]operator) builds arrays of arrays from non-constant arguments faster: about 2x when the inner arrays hold numbers, decimals orFixedStringvalues.Description
FunctionArraybuiltArray(Array(T))throughexecuteGeneric: one virtualColumnArray::insertFromper (row, argument), which makes a second virtualinsertRangeFromon the nested column, an out-of-linememcpyand anoffsets.push_back. Incomplex_array_creation([[zero], [zero]],[[], [zero]], 20M elements per query) this chain is 83-89% of the query in the CPU profiles of this arm run, where it was also the code that ran 41% slower in one PR build (a binary whose diff never reaches it).The new
executeArraywrites all element offsets in one pass, then copies the nested data. For fixed-width nested types (numbers, decimals,FixedString,UUID,IPv6, ...) it reserves the whole result once and copies raw bytes (memcpySmallAllowReadWriteOverflow15up to 64 bytes,memcpyabove, as inColumnArray::replicateNumber). Other nested types keep the sameinsertRangeFromcall thatColumnArray::insertFrommade. Results are unchanged. Other element types (Map,LowCardinality,Variant, top-levelUUID/IPv6) stay onexecuteGeneric.x86 release,
max_threads = 1, median of 75 runs, before -> after:[[zero], [zero]]: 0.091 -> 0.045 s (2.02x);[[], [zero]]: 0.093 -> 0.045 s (2.07x)[[toString(zero)], ...]: 1.12x,[[toNullable(zero)], ...]: 1.05x (generic path)[a, a]with 8 KB / 4 MB elements: 1.77x / 4.46x; 8-byte + 1-byte elements: 1.63xtests/performance/complex_array_creation.xmlgets queries forDecimal64,FixedString,StringandNullableinner elements and for 8 KB inner arrays;05838_array_of_arrays_from_columnschecks that[a, b]equalsarrayConcat([a], [b])on both paths.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128389]