Repository navigation
Vectorize <, >, <=, >= on IPv6 and FixedString(16) for CPUs with AVX-512 - #125151
Conversation
`base/base/bigEndianCompare.h` uses the two-64-bit-halves form, which vectorizes to `vpcmpuq`, only under `__AVX512F__`, which official x86-64-v3 builds never define. The `x86_64_v4` clone of the IPv6 ordered comparison kernels therefore inlined the `unsigned __int128` form and extracted every lane to general purpose registers (16 `vpextrq`, 17 stack accesses, no vector compare), and the `FixedString(16)` kernels had no AVX-512 clone. These are exactly the four `uuid_ip_comparison` queries (ClickHouse#2, ClickHouse#3, ClickHouse#10, ClickHouse#11) that are noisy on the amd performance runners. Define the halves form unconditionally as `lessBigEndian16Halves` / `compareBigEndian16Halves` (the default selection is unchanged) and run it in one x86-64-v4 loop, `compareBigEndian16_x86_64_v4`, for `<`, `>`, `<=`, `>=` on IPv6 and FixedString(16), column-column and column-constant, when the CPU supports x86-64-v4. The IPv6 constant goes through a small x86-64-v4 wrapper that takes it by value: passing `&b` from `vectorConstant` itself added a stack frame and a stack protector check to the default path. Release builds, `uuid_ip_comparison` queries x25, 3 rounds, one core: ClickHouse#2 70 -> 42 ms, ClickHouse#3 57 -> 42, ClickHouse#10 54 -> 32, ClickHouse#11 58 -> 32, the other eight within 2%. The non-AVX-512 code is unchanged apart from the dispatch, and ARM is not affected. The test gains FixedString(16) cases and checks every ordered operator on both types against `hex()` strings over blocks of 1001 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the kernel's doc comment to one line and drop the trait comment that restates its specializations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Independent model review (codex; 1 finding) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261011-035600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261011-021500 |
|
Workflow [PR], commit [cd75e4f] Summary: ✅
AI ReviewSummaryThis PR factors the 16-byte big-endian helper so the Missing context / blind spots
Final Verdict✅ No review findings on the current revision. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only adds an AVX-512 path for ordered comparisons (<, >, <=, >=) of IPv6 and FixedString(16) values. No flagged ClickBench query compares values of those types. Q16, Q18, Q32 and Q34 came out between +5.4% and +23.3% slower, but each stayed inside master's normal range and was correctly left as not_sure. I see no reason to challenge those decisions. All four are aggregation-heavy queries that slowed together with higher CPU time, and two of the PR's ClickBench runs shared one host, which points to contention on the test machines rather than this change; tpch_adapted_1_official showed nothing flagged. clickbenchFlagged queries (4 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
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units4071 translation units recompiled, 19349 s compile time in total, 4071 of them have a recent master baseline. |
Related: #120193
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Comparisons
<,>,<=and>=ofIPv6andFixedString(16)values are 1.4 to 1.8 times faster on CPUs with AVX-512.Description
Performance Comparison (amd_release)often flagsuuid_ip_comparisonqueries #2 (ipv6_a < ipv6_b), #3 (fs16_a < fs16_b), #10 and #11 (< (SELECT ...)) on unrelated PRs, for example this job. Over 21 days of amd runs these four move by 10% or more in about 3% of runs, the other eight queries of the test (UUID<, every=, IPv4) in at most 0.5%; on arm all twelve are quiet.These four are the only ones whose AVX-512 kernel is not a vector compare.
base/base/bigEndianCompare.huses its vectorizable two-halves form only under__AVX512F__, which official (x86-64-v3) builds do not define, so thex86_64_v4clone of theIPv6kernels inlines theunsigned __int128form and moves every lane back to general purpose registers (16vpextrq, 17 stack accesses). TheFixedString(16)kernels have no AVX-512 clone at all.This PR adds one loop,
compareBigEndian16_x86_64_v4, built for x86-64-v4 from the existing halves form, and uses it for<,>,<=,>=onIPv6andFixedString(16)(column-column and column-constant) when the CPU has AVX-512: the follow-up scoped in #120193. It compiles tovpcmpuqwithout lane extraction. Code for other x86 CPUs is unchanged apart from the dispatch, and ARM is not affected.Release builds with identical flags, each query of
uuid_ip_comparison25 times in 3 interleaved rounds on one pinned core: #2 70 -> 42 ms, #3 57 -> 42, #10 54 -> 32, #11 58 -> 32, the other eight within 2%.05218_uuid_ip_comparison_vectorizedgainsFixedString(16)cases and checks all four operators againsthex()strings over blocks of 1001 rows; it fails if the halves are compared as signed or swapped. I could not reproduce the CI noise itself locally, so whether it goes away will show on the dashboard after merge.Workflow [PR]
Sync PR [sync-upstream/pr/125151]
Version info
26.10.1.2143-master(included in26.10and later)