Repository navigation
Search long integer slices in 512-byte chunks on AArch64 in hasAll and hasAny - #122871
Conversation
|
Workflow [PR], commit [cf3b328] Summary: ✅
AI ReviewSummaryThis PR searches long 32- and 64-bit integer arrays in 512-byte chunks on AArch64 for Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or changes to existing threads. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes5 object files changed (+172.81 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units30 translation units recompiled, 149 s compile time in total, 30 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: The PR adds ARM SVE runtime detection and SVE-dispatched variants of findExtreme (min/max over numeric columns) and the hasAll integer array search. On x86 builds the new ARM guard is 0, so the only change there is a regrouping of preprocessor blocks that keeps the same behavior. The only flagged query, clickbench Q11 (-15.9%), runs neither code path. Its CPU time is essentially unchanged (1453.6 vs 1462.6 ms), and the PR median of 164 ms sits at the edge of master's current range of 165-212 ms, so it is downgraded to not_sure as run-to-run variance. This run shows no measurable performance effect from the PR. clickbenchFlagged queries (1 of 43)
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. tpch_adapted_1_official🟢 No significant changes Debug info
|
|
Note that the current goal is to remove intrinsics, not add them. See #123420 (comment) Let's wait until the code is simplified (and sped up) to decide if we really need dispatching please |
|
Extra note: After #123420, it's trivial to dispatch to SVE2 (SVE isn't enough) and speed up things. No intrinsics, just dynamic dispatch and letting the compiler do it |
|
It's not clear if SVE(2) would be faster than Neon. Let's check once we merge auto-vectorisation PR you linked and SVE infra #122860 |
|
Converting this to a draft until #122860 is merged. After that, I will benchmark this against #123420. We plan to add SVE2 dispatchers incrementally once #122860 is merged. For AArch64, Clang vector extensions compile to NEON by default, which may not be sufficient for some operations such as filtering (compaction). NEON has no direct equivalent of the SVE Non-intrinsics performance improvements are also in our internal pipeline and will be released after appropriate testing. |
|
Dear @rienath, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
🕵 Merged master into the branch (03b803a). #122860 is merged, and #123420 replaced the @chiranmoyf you planned to benchmark against #123420, so here are numbers. I ran a microbenchmark of the two kernels on a Neoverse-V2 (Graviton4, 128-bit SVE, the same CPU as
On this CPU the SVE kernel now loses to the portable code almost everywhere: it is 1.1x to 5x slower. The only win is very short Int8 arrays. The 1.18x-5.5x gains in the description were measured against the old scalar fallback, which no longer exists on AArch64. So in its current form this PR would make |
|
We should test SVE2 with dynamic dispatch and no custom code. When I tested it the compiler was good enough to produce code that was vectorized and faster by itself, no need to declare things manually |
|
@alexey-milovidov Yes, I tested internally, and the current SVE is slower than #123420. I am working on a more portable version and will push in a day. |
|
🕵 Pushed 6738d9e:
The open P1 review point still stands: the current SVE kernel is slower than the portable |
|
🕵 CI on 6738d9e confirms the open P1 review point. The only failure is |
6738d9e to
a9e96df
Compare
…and `hasAny` `sliceContains` searches a slice in blocks of 128 bytes, testing the combined mask of each block. On AArch64, for 4 and 8-byte integers, a slice of at least 136 (`Int32`) or 68 (`Int64`) elements is now searched in chunks of 512 bytes by a plain loop, which clang vectorizes to 8 or 16 NEON comparisons per iteration with one test per chunk. The first vector is still checked separately, so a value near the front is found as quickly as before. The last chunk overlaps the previous one. Shorter slices are unchanged. New test `05493_has_all_has_any_chunked_search` places a value at every position of arrays around the chunk boundaries. It covers 4 and 8-byte signed and unsigned types, with and without nulls, and compares the results with `has`.
a9e96df to
3fe3891
Compare
hasAll and hasAny
|
@alexey-milovidov Apologies for the delay. We have pushed the portable AArch64 code. In our testing, this improved the performance of 14 of the 46 queries in We accidentally force-pushed another branch on top of this one, which is why you see extra commits in the history. We’ll be careful not to force-push from now on. |
|
@alexey-milovidov @Algunenano We tried compiler-generated SVE/SVE2 code with dynamic dispatch (no hand-written intrinsics), but performance was worse than on master. SVE/SVE2 portable code data: Graviton3-m7g.8xlarge, Graviton4 c8g.4xlarge. I'll check the code generated. |
|
Repurposing this PR for the portable AArch64 code, which extends the current implementation. We’re also working on a platform-independent approach that switches to a set-based algorithm for longer arrays. |
The `arm_asan_ubsan` build failed with `loop not vectorized: the optimizer was unable to perform the requested transformation` (`-Wpass-failed`) for the loop in `chunk_contains`: the instrumented loads cannot be vectorized, and the `#pragma clang loop vectorize(enable)` turns that into an error. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122871&sha=3fe3891446e7d57fbeb5ab69b33500455af06836&name_0=PR&name_1=Build%20%28arm_asan_ubsan%29 ClickHouse#122871 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 The |
|
All tests have passed, and the gains are visible in the dashboard. Please review for any gaps, @alexey-milovidov. |
The `chunk_contains` loop in `sliceContains` requests
`vectorize(enable) vectorize_width(16) interleave_count(2)`. A forced
transformation that the loop vectorizer cannot perform is reported as
`-Wpass-failed=transform-warning`, which `-Werror` makes fatal.
Debug builds compile with `-Og`, which clang runs as its O1 pipeline.
There the vectorizer does not recognize `found |= ...` as a reduction
("value that could not be identified as reduction is used outside the
loop"), so `Build (arm_debug)` fails on `has_any.cpp` and `has_all.cpp`
since ClickHouse#122871. PR CI has no arm_debug build, so only master caught it.
Guard the pragma with `DEBUG_OR_SANITIZER_BUILD` instead of `SANITIZER`.
It is defined in every build without `NDEBUG` and in every sanitizer
build, so sanitizer builds still skip the pragma and release builds keep
it, including the loud failure if a compiler stops honouring it.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
hasAll(first, second)andhasAny(first, second)on integer arrays look up each value ofsecondinfirstwith a linear search,sliceContains.The search compares 128 bytes of
firstwith the value (i.e., 32Int32or 16Int64elements), then checks whether any of them matched, so it can stop as soon as the value is found. On AArch64, that check is relatively expensive. NEON has no single instruction that tests a vector for any set lane, likevpteston x86, so the comparison results have to be reduced to one flag first. With one check per 128 bytes, a large part of the time goes into these checks rather than into the comparisons.For long arrays, it is cheaper to compare more elements before each check. This change checks once per 512 bytes.
Change
On AArch64, an array of at least 136 4-byte or 68 8-byte integers is searched in chunks of 512 bytes by a plain loop, which Clang vectorizes to 8 or 16 NEON comparisons per iteration, with one check per chunk.
05493_has_all_has_any_chunked_searchplaces a value at every position of arrays with lengths around the chunk boundaries. It includes a last chunk that overlaps the previous one, a value that is missing, and a value at a null. It coversInt32,UInt32,Int64andUInt64, with and without nulls.Shorter arrays of 1 and 2-byte types, non-integer types, and x86 are unchanged. On x86, the chunk loop was slower than the current code.
Performance
hasAllandhasAnyare up to 2x faster on AArch64 for long arrays of 32 and 64-bit integers.tests/performance/has_all.xmlandtests/performance/has_any_has_all_nullable.xmlon Graviton 4 (c8g.4xlarge): pastilaChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
hasAllandhasAnyare up to 2x faster on AArch64 for long arrays of 32 and 64-bit integers.This PR is a joint contribution by:
Abhishek Jain (@abhijain1204fujitsu)
Workflow [PR]
Sync PR [sync-upstream/pr/122871]
Version info
26.11.1.1623-master(included in26.11and later)