Repository navigation
Conversation
The four vectorised set-intersection specialisations in src/Functions/GatherUtils/sliceHasImplAnyAll.h all sit inside a single "#if defined(__AVX2__)" block, and the dispatcher's if-constexpr selection chain sits inside a second one. There is no #elif and no #else, so on AArch64, and on any other non-AVX2 target, every hasAll call falls through to sliceHasImplAnyAllGenericImpl: a linear scan of the haystack per needle. Measured over 5524 CI (test, queryIndex) pairs, comparing ARM and AMD test_duration_ms medians on master across a 10-day window, the fleet-wide median ratio is 0.87, i.e. the ARM runner is normally about 13% faster. Against that baseline has_all query 5 (test_table_medium_Int16) is 13.4x slower on ARM, which is rank 1 of all 5524 pairs, and has_all holds five more places in the top twelve. All twelve queries of that test are affected. This adds an "#elif defined(__aarch64__)" arm with neonEqualMask and sliceHasImplAnyAllImplNeon, plus the matching dispatcher arm guarded the same way as the AVX2 one. NEON is unconditionally available at ClickHouse's AArch64 baseline (cmake/cpu_features.cmake passes -march=armv8.2-a+simd+...), so no runtime dispatch or feature detection is required. x86 is unaffected by construction: with __AVX2__ defined the preprocessor takes the AVX2 branch and the added text never reaches the compiler. This was verified by comparing the disassembly of all three translation units that include the header, before and after, and the same comparison reports 234 differing instructions when a change is deliberately made inside the AVX2 block. The patch was written and measured on AArch64 hardware by Egor Romanov (egor-click), who reported the problem in ClickHouse#116069 and asked for it to be opened as a pull request. On a 32-core Neoverse-class machine, with 11 interleaved runs per side and both binaries from the same checkout, the ten affected queries go from 10.72 s to 3.81 s, a 2.82x improvement, with medium_Int16 at 5.20x; hasAny and arraySum controls, which cannot enter the changed code, did not move in the same session. A known trade-off is documented in the issue and kept as it is: a long haystack whose needles are found within the first two to four elements still takes the vector path and pays one horizontal reduction where the scalar loop needs a single compare, up to 1.76x slower at match depth 0. In absolute terms that is 0.48 us on a call the scalar loop finished in 0.63 us, against 40 to 100 us saved per call at the depths these queries actually see. A scalar prefix of 0, 2, 4 and 8 elements was swept as a possible remedy and none was adopted: at the depth that is worst for a given prefix length P the kernel does P compares plus one reduction while the scalar scan does P+1 compares, so the absolute penalty is independent of P and a prefix relocates the peak to depth P rather than removing it, while charging P compares per needle at every greater depth. Correctness was checked by cross-compiling the kernel for AArch64 and running it under qemu, for correctness only and never for timing, against an independent reference implementation: 76,408 cases per build covering all eight integer widths, every hit index across the loop boundaries, 14 match depths, all four null-map shapes with and without a NULL present, type extremes, duplicates, and 4000 randomised cases per type. Results agree in every case, and instrumentation counters confirm the NEON path was entered rather than skipped. Null maps and haystacks shorter than max(32, 4 * lanes) are diverted to hasAllIntegralLoopRemainder, the same scalar loop the x86 specialisations use for their own remainders, before any vector load; a bounds oracle over 1,223,598 vector loads found none outside the slice. Co-authored-by: Egor Romanov <[email protected]>
The three new preprocessor guards now test __ARM_NEON alongside __aarch64__, matching every other NEON site in the tree (src/Columns/ColumnsCommon.h, src/Common/StringSearcher.h, src/Common/UTF8Helpers.h, src/Common/memcpySmall.h, src/Compression/LZ4_decompress_faster.cpp). __ARM_NEON is defined under both -march profiles ClickHouse passes on AArch64, so no build ClickHouse produces changes behaviour; a target built with +nosimd now falls back to the generic scan instead of failing to compile on the missing intrinsics. The threshold comment no longer names a pull request. The property it needs to state is that a horizontal reduction only pays for itself once the haystack is long enough to amortise it, which stands on its own; the number that was there pointed at a closed, never-merged PR rather than at the merged change that caused the regression it described, so it sent a reader looking for history that does not exist.
The long-Nullable block asserted that it proves NULL slots are diverted before any vector load and that its two sides exercise different code. Neither holds: hasAll receives no null map from arrayAllAny, because Source::getWhole() returns by value and the null-map-carrying sliceHas overloads take non-const lvalue references, so the plain overload is the only viable candidate and passes nullptr for both maps. arrayFilter also preserves Nullable, so both sides of the comparison are routed identically. The assertion still pins the answer, which is worth keeping, so only the comment changes.
…y type Two comments in 04946_has_all_integer_arrays.sql claimed coverage the entry threshold refutes. The short Nullable block said Nullable arrays take the scalar path as a class; nullability is not the reason those calls are diverted (their haystacks are 3 and 4 elements, under the 32-element threshold), and the long Nullable block 15 lines below runs the same type above the threshold, so the claim is also false as stated. The boundary-values block said a kernel mishandling the sign bit fails there; its haystacks are 2 to 3 elements, below the threshold for every width, so no kernel defect can redden it - it pins the pre-existing scalar remainder loop, and the block after it repeats the extremes at a length that does reach the kernel. Comments only. No assertion, row or reference output changes.
Internal second-model review - four rounds, 8 findings adjudicated (5 agreed, 3 disagreed)Four review rounds over this diff (a cold read plus a second model each round), ❌ Agreed and fixed in this PRA stale citation in the new block comment. The comment credited a regression The NEON guards now also test Two test comments claimed detection the entry threshold refutes. One said Two attribution errors in this description. It linked "asked for a PR" to my This description said
|
Pre-PR validation gate (click to expand)
|
|
Workflow [PR], commit [bb72fcd] Summary: ❌
AI ReviewSummaryThis PR adds an Missing context / blind spots
Final Verdict✅ No new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 2/3 (66.67%) · Uncovered code |
|
cc @rschu1ze @antaljanosbenjamin, could you review this? The four vectorised set-intersection kernels in |
The 8-bit columns of the main matrix remapped values through x % 100. With the longest haystack at 200 elements that made every value repeat after 100 slots, so the "absent" needle was present after all and every hit landed in the first 100 elements. The 8-bit arms therefore could not observe a miss or a deep hit, which is exactly what the file header claims the length matrix covers. The remapping was never needed: toInt8 and toUInt8 truncate modulo 2^8 rather than throwing, and the longest length here is 200, which is below 256, so a plain cast stays injective at 8 bits too. Measured on cross-compiled aarch64 (qemu-aarch64), replaying this matrix against the shipped kernel. With the kernel deliberately returning "found" for 1-byte widths only, the 8-bit arms went from 4 reddened cases to 12, and with a fencepost that drops the last element of the scalar tail, from 6 to 24. The deepest observed hit index for the 8-bit widths went from 99 to 199, and the number of genuinely-absent oracle cases per 8-bit width from 14 to 18.
Build profile diff (arm_release)Comparing ✅ No significant changes. 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. Object file sizes4 object files changed (+55.00 KiB total), 0 added.
737 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, 124 s compile time in total, 30 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR adds an ARM NEON SIMD specialization for the array hasAll function on integer arrays. None of the flagged ClickBench queries use hasAll — they are all GROUP BY aggregations (Q16-Q18, Q32-Q34) that don't execute the changed code path, so the uniform +8% to +14% deltas cannot plausibly be caused by this change and look like run-to-run variance across the co-located source runs (only 6 source runs vs 21 baseline). The Q16 and Q17 regressions were downgraded to not-sure on that basis; the remaining queries already sit within master's variance band. No genuine regression is attributable to this diff. clickbenchFlagged queries (6 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
|
CI finish ledger - 29aacd2Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
178 check-runs completed: 159 success, 16 skipped, 3 failure, 0 queued or in progress. Session id: cron:our-pr-ci-monitor:20260825-080000 |
| @@ -0,0 +1,191 @@ | |||
| -- Every row prints 1. `hasAll(set, subset)` is compared against a brute-force | |||
There was a problem hiding this comment.
@groeneai Remove this test. All functionality is already covered by existing tests.
There was a problem hiding this comment.
Removed, and the comment too (bb72fcd).
You are right on coverage: src/Functions/tests/gtest_has_all.cpp calls sliceHasImplAnyAll, the dispatcher, so it routes to whichever arm the build selects, and its sizes 100/4096 (125 for 8-bit) are above this arm's entry threshold max(32, 4 * lanes) for all four widths, in both the all-present and one-absent directions, plus a null-map case. I also checked the other direction: every pre-existing hasAll call site in the stateless suite is either below that threshold or not a numeric slice, so none reached the arm before this PR either (04141_h3_polygon_to_cells_with_containment looked like the exception, but its array measures 7 elements).
One fact for the record, no action implied: Unit tests is AMD-only, all 7 paramsets RunnerLabels.AMD_LARGE (ci/defs/job_configs.py:1072-1085), so the gtest exercises the AVX2 arm and never the NEON one. That is pre-existing and applies equally to the four AVX2 kernels. Performance Comparison (arm_release) is what covers the new arm on ARM now.
|
|
||
| #elif defined(__aarch64__) && defined(__ARM_NEON) | ||
|
|
||
| /// AArch64/NEON counterpart of the x86 specialisations above. |
There was a problem hiding this comment.
Gone, along with the rest of the narration in that block (bb72fcd). What survives is one sentence on why the x86 lane-rotation shape is not reused, and the null-map/short-haystack note moved down to the guard it explains. No executable line changed: the header is 650 non-comment lines before and after, byte-identical.
Both changes were asked for in review. The stateless test is dropped: src/Functions/tests/gtest_has_all.cpp already covers the functional contract of this kernel. It calls sliceHasImplAnyAll, the dispatcher, so it routes to whichever arm the build selects, and its array sizes (100 and 4096, plus 125 for the 8-bit case) are above the new arm's entry threshold max(32, 4 * lanes) for all four widths, in both the all-present and one-absent directions, with a null-map case alongside. Every hasAll call site in the pre-existing stateless suite is below that threshold or is not a numeric slice, so none of them reached the arm before this change either. The comment block above the arm is reduced to the one thing not visible in the code: why the x86 lane-rotation shape is deliberately not reused. The null-map/short-haystack justification moves to the guard it explains. The remaining narration went; no executable line changes (650 non-comment lines in the header, byte-identical before and after).
CI finish ledger - bb72fcdEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
This diff cannot reach either failure: it is one file,
Session id: cron:our-pr-ci-monitor:20260825-200000 |
|
Completing the finish ledger above.
Root cause is |
Algunenano
left a comment
There was a problem hiding this comment.
Better to avoid intrinsics
|
I'll do the comparison myself and apply any improvements from this PR into #123420 instead |
|
Thanks. From the code, the shapes where this PR could still be ahead of #123420 are narrow: it only vectorizes |

Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
hasAllon arrays of 8, 16, 32 and 64-bit integers is now much faster on AArch64 (ARM) servers, where it previously ran an unaccelerated element-by-element search. Queries over long integer arrays benefit the most.Description
Closes: #116069
The patch is @ egor-click's, taken from the issue body, measured by him on AArch64, credited in the commit message. He asked for a PR; I verified it.
Cause. All four vectorised specialisations in
sliceHasImplAnyAll.hsit inside one#if defined(__AVX2__)block, as does the dispatcher's selection chain. With no#elif, AArch64 falls through tosliceHasImplAnyAllGenericImpl, a per-needle linear scan. Over 5524 CI(test, queryIndex)pairs (ARM/AMD duration medians, 10 days, master) the fleet-wide median ratio is 0.87 (ARM normally ~13% faster), whilehas_allquery 5 is 13.4x, rank 1 of 5524.Change. An
#elif defined(__aarch64__) && defined(__ARM_NEON)arm:neonEqualMask,sliceHasImplAnyAllImplNeon, and a dispatcher arm guarded the same way. The x86 lane-rotation algorithm is deliberately not ported (it can only leave the inner scan once every lane has been found), so this vectorises only the haystack scan and keeps the scalar loop's early exit. NEON is unconditional at ClickHouse's AArch64 baseline, so no runtime dispatch; null maps and short haystacks take the existing scalar loop before any vector load.Validation. His AArch64 A/B (32-core Neoverse, 11 interleaved runs/side): the ten affected queries 10.72 s to 3.81 s (2.82x), medium_Int16 5.20x, controls flat. I have no AArch64 hardware, so that is his number; the authoritative one is this PR's
Performance Comparison (arm_release). I did verify x86 is bit-identical (disassembly of the three affected TUs, with a deliberate AVX2-side change as the control) and that the kernel matches an independent reference on 76,408 cases under qemu.Trade-off he discloses. A needle found in the first few elements of a long haystack pays a reduction where the scalar loop needs one compare: 1.76x at depth 0, against 40-100 us saved at the depths these queries see. I swept a 0/2/4/8 scalar prefix and rejected it; the penalty is independent of P.
Workflow [PR]
Sync PR [sync-upstream/pr/116224]