Repository navigation
Fix ARM performance regressions in indexOf, skipASCIIBlocks and computeWidth - #123377
Conversation
`NumericArrayIndex<IndexOfAction, T>::findInBlocks` returned the rescan of the matching block from inside the block loop. That kept clang from vectorizing the `found |=` reduction for 4- and 8-byte elements on ARM, so `indexOf` ran a scalar prefix, a scalar block reduction and a scalar rescan, which is slower than the scalar loop it replaced. `has` was not affected. Now the loop only breaks, and the block or the tail is rescanned after it. `NumericArrayIndex<IndexOfAction, T>::vector` for `Int32`, `UInt32`, `Int64`, `UInt64`, `Float32` and `Float64` now has the same NEON compares as `has`. The `has` code is unchanged on both x86 and ARM. On x86 the `indexOf` block loop stays the same, and the unrolled rescan becomes a short loop. `clickhouse local` on Neoverse-V2, `max_threads = 1`, best of 9, 4M rows: - `Array(UInt32)` of 24, hit in 8..15: 72 -> 52 ms - `Array(UInt32)` of 24, hit at 9: 48 -> 26 ms - `Array(Int64)` of 16, hit in 8..15: 58 -> 53 ms Add a short-array case to the `array_index_simd_numeric` performance test. Closes: ClickHouse#123338 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`WriteBufferValidUTF8::nextImpl` and `writeValidUTF8` call `skipASCIIBlocks` once per sequence they step over. In non-ASCII text the next such byte is usually within 64 bytes, so the 64-byte check failed and the 16-byte check ran after it: two vector checks per step where the old SSE2 and NEON loops did one. Now one 16-byte block is checked first, and the function returns at once if it has a byte of `0x80` or more. The result is the same. Long ASCII runs pay one extra 16-byte check. `clickhouse local` on Neoverse-V2, `max_threads = 1`, best of 9: - `FORMAT XML`, accented Latin, 300000 rows of 720 bytes: 1.14 -> 0.89 s - `FORMAT XML`, Cyrillic, 300000 rows of 1 KB: 0.96 -> 0.79 s - `JSONEachRow` with `output_format_json_validate_utf8 = 1`, Cyrillic: 1.05 -> 0.88 s - `toValidUTF8` of 63 `é` and an `a`, 2M rows: 0.57 -> 0.52 s - ASCII `FORMAT XML` and `toValidUTF8`: unchanged The x86 code of the two callers changes too: CI showed about +6% on `to_valid_utf8` there as well. Add a non-ASCII `XML` case to the `writing_valid_utf8` performance test. Closes: ClickHouse#123346 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The block skip in `computeWidthImpl` ran on every outer iteration outside an escape sequence. That includes every byte of every multi-byte character, because the decoder takes one byte per iteration, and there the skip cannot advance at all. Since the skip is enabled on every little-endian target, ARM builds the 32-byte mask for nothing at each such byte, and without `movemask` that mask takes several instructions. Now the skip runs only when the current byte is printable ASCII. The result is the same, since the skip stops at the first byte that is not. `clickhouse local` on Neoverse-V2, `max_threads = 1`, best of 9, 2M rows: - `visibleWidth` of 140 bytes of Cyrillic: 4.48 -> 3.42 s - `visibleWidth` of 90 bytes of CJK: 2.27 -> 1.50 s - `visibleWidth` of 80 bytes of accented Latin: 0.79 -> 0.68 s - `PrettyCompactNoEscapes` of 10000 rows of CJK: 41 -> 27 ms - ASCII and numbers: unchanged Add a `visible_width` performance test. Closes: ClickHouse#123351 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [fd6dd3c] Summary: ✅
AI ReviewSummaryThis PR reshapes three hot-path fast paths to recover ARM performance in Final Verdict
LLVM Coverage ReportMeasured on commit fd6dd3c.
Changed lines: Changed C/C++ lines covered: 15/16 (93.75%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units18 translation units recompiled, 73 s compile time in total, 18 of them have a recent master baseline. |
Skipping the first 16-byte block shifted the 64-byte blocks. For pure ASCII whose length is `64 * k` to `64 * k + 15` the loops then checked three extra 16-byte blocks: four checks instead of one for 64 bytes. Now the loops check the first block again, which costs one 16-byte check for every length. The gains on non-ASCII text stay the same. Related: ClickHouse#123377 (comment) Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: I marked both flagged improvements as not sure: tpch_adapted_1_official Q1 (-20.0%) and Q7 (-17.3%). This PR changes three things: the numeric has/indexOf block search, visibleWidth's ASCII fast path, and the ASCII block skip used when writing valid UTF-8 output. Q1 and Q7 are an aggregation and a join that return only a few rows, so they run none of that code. Both queries have a noisy history on master, so these shifts are most likely normal run-to-run variation. Nothing was suppressed by the master variance band, and the era-split refit only applied to clickbench Q29, which was not flagged. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (2 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
On x86, returning the rescan of the matching block from inside the block loop is unrolled into branchless code that reuses the comparisons of the block. Rescanning after the loop made it a loop whose exit is mispredicted when the match position varies: `array_index_simd_numeric` #2 got 36% slower on amd. Return from inside the loop on x86 again, so its code is the same as before this PR. Other targets keep the `break`, which ARM needs to vectorize the block loop for 4- and 8-byte elements (the same query got 25% faster on arm). Related: ClickHouse#123377 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Fix three ARM performance regressions from recent vectorization changes. Each fix is a separate commit, with no intrinsics, and adds a short performance test.
indexOfwith a constant needle:findInBlocksreturned the rescan from inside the block loop, which kept clang from vectorizing the reduction for 4- and 8-byte elements on ARM. Now the loop only breaks and the rescan happens after it, except on x86, where returning from the loop is unrolled into branchless code that reuses the comparisons. The x86 code ofindexOfandhasis identical to master.skipASCIIBlocks: in non-ASCII text the 64-byte check almost always failed and the 16-byte check ran after it. Now one 16-byte block is checked first.computeWidth: the block skip ran at every byte of every multi-byte character, where it cannot advance, and building the mask is expensive on ARM. Now it runs only at a printable ASCII byte.clickhouse localon Neoverse-V2,max_threads = 1, best of 9, master -> this PR:indexOf,Array(UInt32)of 24, hit in 8..15indexOf,Array(UInt32)of 24, hit at 9indexOf,Array(Int64)of 16, hit in 8..15FORMAT XML, accented Latin, 300000 rows of 810 bytesFORMAT XML, Cyrillic, 300000 rows of 1 KBJSONEachRowwithoutput_format_json_validate_utf8 = 1, CyrillictoValidUTF8of 63éand ana, 2M rowsvisibleWidth, 149 bytes of Cyrillic, 2M rowsvisibleWidth, 90 bytes of CJK, 2M rowsPrettyCompactNoEscapes, 10000 rows of CJKASCII inputs are unchanged. The x86 code of
skipASCIIBlocksandcomputeWidthcallers changes too (verified by diffing the assembly of the real translation units), but it was not benchmarked on x86. CI showed about +6% onto_valid_utf8on x86 as well.Closes: #123338
Closes: #123346
Closes: #123351
Changelog category (leave one):
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123377]
Version info
26.10.1.1339-master(included in26.10and later)