Skip to content

perf: vectorize small u8 table take with AVX2 - #9572

Open
joseph-isaacs wants to merge 1 commit into
ji/small-u8-table-take-neonfrom
ji/small-u8-table-take-avx2
Open

perf: vectorize small u8 table take with AVX2#9572
joseph-isaacs wants to merge 1 commit into
ji/small-u8-table-take-neonfrom
ji/small-u8-table-take-avx2

Conversation

@joseph-isaacs

Copy link
Copy Markdown
Contributor

Rationale

Add the x86 table-lookup implementation after the NEON implementation in #9571.

This is the upper PR in the stack: #9566 (benchmark) → #9571 (NEON) → this PR (AVX2).

Changes

  • Use AVX2 VPSHUFB on x86/x86-64.
  • Apply the path to u8 codes, at most 16 one-byte values, and at least 64 rows.
  • Retain runtime AVX2 detection, bounds checks, and the existing general AVX2/scalar fallbacks.

CodSpeed wall-time results

Medians over 1,000 samples on the same Sapphire Rapids metal family, compared with #9566:

Build Rows Baseline AVX2 table Speedup Time reduction
AVX2 1M 428.1 µs 61.12 µs 7.00× 85.7%
AVX2 16M 6.809 ms 1.361 ms 5.00× 80.0%
AVX-512 1M 426.5 µs 59.28 µs 7.19× 86.1%
AVX-512 16M 6.778 ms 1.358 ms 4.99× 80.0%

The AVX-512 leg is an AVX-512-enabled whole-crate build executing this AVX2 VPSHUFB kernel; there is no separate AVX-512 table kernel.

Runs: baseline, optimized.

Validation

  • 3,352 vortex-array tests passed; 1 skipped
  • targeted Clippy passed
  • x86-64 cross-check passed
  • formatting and diff checks passed

@codspeed-hq

codspeed-hq Bot commented Aug 24, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 11 improved benchmarks
❌ 1 regressed benchmark
✅ 2181 untouched benchmarks
⏩ 218 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime filtered_owned_i64_avx2[OneNullInEight] 21.9 µs 26.8 µs -18.4%
WallTime dict_canonicalize_gt_u8_avx2[1000000] 419.8 µs 58.2 µs ×7.2
WallTime dict_canonicalize_gt_u8_avx512[1000000] 419.5 µs 58.8 µs ×7.1
WallTime dict_canonicalize_gt_u8_avx2[16000000] 6.8 ms 1.4 ms ×5
WallTime dict_canonicalize_gt_u8_avx512[16000000] 6.8 ms 1.4 ms ×5
Simulation decode_primitives[u8, (2000, 8)] 43.8 µs 33.4 µs +30.88%
Simulation decode_primitives[u8, (2000, 4)] 43.8 µs 33.4 µs +30.88%
Simulation decode_primitives[u8, (2000, 2)] 43.8 µs 33.4 µs +30.88%
Simulation decode_primitives[u8, (1000, 8)] 36.3 µs 31.5 µs +15.07%
Simulation decode_primitives[u8, (1000, 4)] 36.3 µs 31.5 µs +15.06%
Simulation decode_primitives[u8, (1000, 2)] 37.1 µs 32.3 µs +14.69%
WallTime words_gather_scalar_avx2[65536] 9.4 µs 8.3 µs +13.35%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ji/small-u8-table-take-avx2 (134d1c5) with ji/small-u8-table-take-neon (e97db31)

Open in CodSpeed

Footnotes

  1. 218 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.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This PR has been marked as stale because it has been open for 14 days with no activity. Please comment or remove the stale label if you wish to keep it active, otherwise it will be closed in 7 days

@github-actions github-actions Bot added the stale This PR is stale and will be auto-closed soon label Sep 9, 2026
Use AVX2 VPSHUFB for u8-coded tables with at most 16 one-byte values.

Signed-off-by: Joseph Isaacs <joseph-isaacs@users.noreply.github.com>
@joseph-isaacs
joseph-isaacs force-pushed the ji/small-u8-table-take-avx2 branch from 0129184 to 134d1c5 Compare September 9, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This PR is stale and will be auto-closed soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant