Skip to content

perf: Add AVX2 SIMD acceleration for power-of-two Hadamard transform - #119064

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
philip-jingxin:perf/hadamard-x86-simd
Sep 12, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
philip-jingxin:perf/hadamard-x86-simd

Conversation

@philip-jingxin

@philip-jingxin philip-jingxin commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Speed up FWHT kernels using AVX2 SIMD instructions (~28.6% higher throughput, 22.5% lower median latency).

Detailed Description

This PR adds AVX2 SIMD optimizations for FWHT (Fast Walsh-Hadamard Transform) kernels:

  • AVX2 Vectorization: Replaced the scalar loop with 256-bit AVX2 intrinsics to process multiple array elements in parallel.
  • Codebase Consistency: Mirrored ClickHouse's existing Neon kernel implementation pattern to keep the architectural structure clean, maintainable, and fully backward-compatible with non-AVX2 hardware.

Testing

  • Passed all relevant unit and stateless tests across both scalar and AVX2 execution paths.

Benchmark Environment

  • CPU: 13th Gen Intel(R) Core(TM) i9-13900K (32 vCPUs, 36 MiB L3 cache)
  • Memory: 64 GB
  • OS / Kernel: Ubuntu 26.04 LTS / Linux 7.0.0-31-generic
  • Compiler: Clang 21.1.8
  • Benchmark Tool: clickhouse-benchmark

Benchmark Results

Ran 10,000 queries using clickhouse-benchmark on localhost:9000 to compare the scalar baseline against the AVX2 SIMD implementation:

1. Throughput Comparison

Metric Baseline (Scalar) AVX2 Optimized Improvement
QPS (Queries/sec) 38.65 49.71 +28.63%
RPS (Rows/sec) 386,489.61 497,126.09 +28.63%
Throughput (MiB/s) 6,041.85 7,771.39 +28.63%

2. Latency Percentiles Comparison

Percentile Baseline (sec) AVX2 Optimized (sec) Latency Reduction
Min (0%) 0.077 0.052 32.47%
P50 (Median) 0.102 0.079 22.55%
P90 0.117 0.093 20.51%
P95 0.128 0.104 18.75%
P99 0.140 0.117 16.43%
P99.99% (Max) 0.183 0.171 6.56%

Workflow [PR]
Sync PR [sync-upstream/pr/119064]

@CLAassistant

CLAassistant commented Sep 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 9, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [185779f]

Summary: ✅


AI Review

Summary

This PR adds an AVX2 FWHT kernel for power-of-two dimensions, wires the same dispatch into the VectorQuantizer projection path, and adds larger exact-output stateless coverage. I did not find a remaining correctness, compatibility, or metadata issue in the current diff; the earlier gaps around VectorQuantizer dispatch, large-dimension coverage, and kernel-selection comments are fixed.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 185779f.

Metric Baseline Current Δ
Lines 88.90% 89.00% +0.10%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 54/62 (87.10%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... labels Sep 9, 2026
Comment thread src/Common/HadamardTransform.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 185779f31 with master 592da49d0 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 9 s compile time in total, 8 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 40 queries analysed

This PR adds an AVX2 fast Walsh-Hadamard kernel used only by randomHadamardTransform and vector quantization; none of the flagged ClickBench queries (Q28, Q33, Q34) call that code path, so the changed code cannot execute during these queries. Q28's +6.9% is on an intrinsically noisy query with disagreeing tests, and Q33/Q34's +5.6% deltas both land inside master's current variance band. All three flags are downgraded to not_sure as run-to-run variance rather than a real PR effect. The envelope suppressions on Q33/Q34 are consistent with the diff, which touches no ClickBench execution path.

clickbench

⚠️ 3 inconclusive

Flagged queries (3 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 28 not_sure 1050 1122 +6.9% <0.0001 This PR only adds an AVX2 kernel for randomHadamardTransform; ClickBench Q28 never calls that function, so the +6.9% is run-to-run variance on a noisy query.
⚠️ 33 not_sure 1147 1211 +5.6% <0.0001 Q33 does not exercise randomHadamardTransform or vector quantization, the only paths this PR touches, so this +5.6% sits within master's variance band and is not a PR effect.
⚠️ 34 not_sure 1156 1221 +5.6% <0.0001 Same as Q33: the AVX2 Hadamard kernel is unrelated to what Q34 runs, and the delta falls inside master's current variance band, so treat +5.6% as noise.

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
  • StressHouse run: 6f55d9f7-6bd2-4f9c-a6f7-a8291373ae74
  • MIRAI run: c2c02205-a825-43b2-aced-d03ab809694a
  • PR check IDs:
    • clickbench_131807_1789099878
    • clickbench_131813_1789099878
    • clickbench_131819_1789099878
    • tpch_adapted_1_official_131830_1789099878
    • tpch_adapted_1_official_131842_1789099878
    • tpch_adapted_1_official_131849_1789099878

Comment thread src/Common/HadamardTransform.h Resolved
@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Sep 11, 2026
@maxknv maxknv removed the external Author is not a member of the ClickHouse organization label Sep 11, 2026
@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Sep 11, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit 02a401e Sep 12, 2026
174 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... external Author is not a member of the ClickHouse organization pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants