Skip to content

Speed up PIVCO decode with NEON and AVX2 kernels - #12355

Draft
lwwmanning wants to merge 3 commits into
wm/pivco-arrayfrom
wm/pivco-simd-decode
Draft

lwwmanning wants to merge 3 commits into
wm/pivco-arrayfrom
wm/pivco-simd-decode

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #12103

This adds SIMD kernels to the decode side of vortex-pivco, the experimental wavelet-tree integer encoding from #12103. It covers the bottom-up tree merge, popcount, and the flat-subtree unpack for depths 2 to 6. The encoder, the file format and the public API are unchanged.

Before, decode ran scalar code on every target. After, src/simd/mod.rs dispatches to NEON on aarch64 at compile time, and to AVX2 with POPCNT on x86 when the CPU has them at run time. Other targets, and the tails that the vector loops do not cover, still use the scalar code. There is no SSSE3, SSE4.1 or AVX-512 tier. The kernels, about 1,250 lines in neon.rs and x86.rs, derive from Marcin Zukowski's pivco-huffman (Apache-2.0).

Tests compare each kernel bit for bit with the scalar code, including all 65,536 masks of the 16-bit merge. PR CI runs on arm64, so it covers only NEON. All 26 vortex-pivco tests also passed on an x86_64 AVX2 host. No CI job runs the AVX2 kernels yet. The nightly AVX2 job in release-checks.yml can test vortex-pivco only after #12103 lands on develop.

On that x86_64 AVX2 host, the pivco_compress decode benchmarks from #12358 run 2.9x to 6.0x faster than scalar across all 9 cases. For example, zipf64_u32/pha goes from 3.03 ms to 716 µs, and skewed_gt_u64/ph from 632 µs to 105 µs. NEON has no numbers yet.

Authored with AI assistance.

@lwwmanning lwwmanning added the changelog/performance A performance improvement label Nov 30, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T00:59:08.680076Z 8310a72 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I read the NEON and AVX2 kernels against the scalar code. I found no bug. The in-place merges are safe. Each 16-byte store holds 16 merged symbols, so a store never overwrites a byte that a later load needs. Every vector load stays inside the l_len, r_len or packed.len() guard, and the unpack tails read only the bytes the scalar path reads.

The AVX2 code has not run in CI. On pull requests, the workspace tests run only on Rust tests (linux-arm64). The nightly x86 musl job runs them only after merge. The nightly rust-test-cpu-features avx2 job tests only vortex-buffer, vortex-mask and vortex-array. So before merge, merge_vec_vec_avx2, merge_cst_side_avx2, merge_cst_cst_avx2 and the five unpack_flat_d*_avx2 kernels have no CI coverage. Please add -p vortex-pivco to the cpu-features job, or run the pivco tests once on an AVX2 host and say so in the description.

The NEON shuffle tables have no exhaustive check, but the x86 tables do (test_x86_merge_pshufb_tables_exhaustive_16bit). One test can cover both. Call merge_vec_vec, merge_cst_vec and merge_vec_cst with k = 16 and 16-byte inputs for all 65,536 masks, and compare with the scalar merge. That runs the real dispatch on each target. It can replace the table-only x86 test.

The parity tests use seeded loops over fixed lengths and patterns. A Hegel property that draws the bitmap bytes, k, the slack and the depth would cover the same cases with less code. This is optional.

The PR adds about 1,560 lines of unsafe SIMD with no measured result. Please add one line with the decode speedup over scalar, on NEON and on AVX2. The pivco_compress decode benches in #12358 can give it.

Adds NEON and AVX2+POPCNT SIMD decode merges, popcount, and flat-subtree
unpack kernels (D in 2..=6) behind the scalar fallbacks in vortex-pivco,
deduplicating NEON 64-byte merge bodies and dropping shadowed SSSE3/SSE4.1
x86 tiers, plus bit-exact SIMD-vs-scalar parity tests.

Co-Authored-By: Antigravity <noreply@google.com>
Signed-off-by: Will Manning <will@willmanning.io>
@codspeed

codspeed Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 15.51%

Warning

vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 4 improved benchmarks
✅ 2173 untouched benchmarks
⏩ 196 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation for_each_set_index[(16384, 0.01)] 15.3 µs 12.9 µs +19.27%
⚡ CPU Simulation scan[1000] 12.1 ms 10.3 ms +16.73%
⚡ CPU Simulation scan[100] 1.3 ms 1.1 ms +16.16%
⚡ CPU Simulation scan[1] 79.5 µs 72.2 µs +10.09%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing wm/pivco-simd-decode (109801e) with wm/pivco-array (88d0377)2

Open in CodSpeed

Footnotes

  1. 196 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on wm/pivco-array (84ea4a3) during the generation of this report, so f03b93b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed in 01b2b3550 (rebased onto #12103 f13531526):

  • Added -p vortex-pivco to rust-test-cpu-features in .github/workflows/release-checks.yml, and verified all 26 vortex-pivco unit tests directly on an x86_64 AVX2 host.
  • Replaced test_x86_merge_pshufb_tables_exhaustive_16bit with target-independent test_simd_merge_exhaustive_16bit, running merge_vec_vec, merge_cst_vec, and merge_vec_cst via runtime dispatch across all 65,536 16-bit masks against scalar (covering both NEON and AVX2).
  • Added the local x86_64 AVX2 vs scalar decode headline speedup (2.9x–6.0x across all 9 pivco_compress decode cases; e.g. zipf64_u32/pha 3.03 ms -> 716 µs, skewed_gt_u64/ph 632 µs -> 105 µs) to the PR description (NEON host not available here).

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

The 04:38 reply says 01b2b35 adds -p vortex-pivco to the rust-test-cpu-features job in release-checks.yml. The force push at 04:39 replaced that commit with a95e4e9, which drops the line. As far as I can tell, no CI job now runs the AVX2 kernels. PR CI runs on arm64, so the new exhaustive dispatch test covers only NEON there.

If the drop was deliberate, please say why in the description. Otherwise please restore the line. The AVX2 decode numbers and the exhaustive 16-bit test look good.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

The drop in a95e4e9 was deliberate: touching .github/workflows/release-checks.yml triggered the release-checks workflow on this stacked PR, where rust-test-cpu-features failed with package ID specification 'vortex-pivco' did not match any packages (and Rust publish dry-run failed on unpublished workspace crate versions) because vortex-pivco is not on develop yet. Verified all 26 vortex-pivco tests (including all AVX2 kernels and the exhaustive 16-bit dispatch test) directly on an x86_64 AVX2 host instead, and noted this in the PR description — -p vortex-pivco can be added to rust-test-cpu-features once #12103 lands on develop.

@lwwmanning lwwmanning changed the title Add NEON and AVX2 decode SIMD kernels for PIVCO Speed up PIVCO decode with NEON and AVX2 kernels Nov 30, 2026
Signed-off-by: Will Manning <will@spiraldb.com>
@lwwmanning
lwwmanning marked this pull request as draft November 30, 2026 18:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/performance A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant