Skip to content

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

Merged
joseph-isaacs merged 1 commit into
developfrom
ji/small-u8-table-take-avx2
Oct 5, 2026
Merged

joseph-isaacs merged 1 commit into
developfrom
ji/small-u8-table-take-avx2

Conversation

@joseph-isaacs

@joseph-isaacs joseph-isaacs commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds AVX2 VPSHUFB small-table lookup on top of the NEON implementation merged in #9571. It handles u8 indices, up to 16 one-byte values, and at least 64 rows, with runtime AVX2 detection and the existing gather/scalar fallbacks.

The byte-value trait implementations live in the architecture-gated module. Table setup uses copy_from_slice, scalar tails use safe writes, and output buffers preserve the caller's allocator. Bounds tests cover invalid indices in both vector and scalar-tail positions on all targets.

For the 1M-row small-u8 dictionary benchmark, CodSpeed reports 55.4 µs versus 422.1 µs, a 7.6× speedup, on the AVX2 build. The AVX-512-enabled build runs the same AVX2 kernel and reports 55.2 µs. These measurements are from commit d138ae05b5, before the subsequent merge of develop.

Benchmark comparison

Validation: all reported CI checks on d138ae05b5 passed apart from pending review policy. After merging develop, the final diff was reviewed and new CI will validate the updated head; local tests were not rerun.

@codspeed

codspeed 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.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 1 regressed benchmark
✅ 2092 untouched benchmarks
⏩ 518 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation take[small_m/shuffled/primitive/nonnull/chunks=2048/indices=64] 280.1 µs 481 µs -41.76%
⚡ WallTime dict_canonicalize_gt_u8_avx512[1000000] 422.3 µs 55.4 µs ×7.6
⚡ WallTime dict_canonicalize_gt_u8_avx2[1000000] 423.4 µs 55.9 µs ×7.6
⚡ Simulation decode_primitives[u8, (2000, 8)] 44.5 µs 33.5 µs +32.83%
⚡ Simulation decode_primitives[u8, (2000, 4)] 44.5 µs 33.5 µs +32.83%
⚡ Simulation decode_primitives[u8, (2000, 2)] 44.5 µs 33.5 µs +32.83%
⚡ Simulation decode_primitives[u8, (1000, 8)] 37 µs 31.5 µs +17.45%
⚡ Simulation decode_primitives[u8, (1000, 4)] 37 µs 31.5 µs +17.45%
⚡ Simulation decode_primitives[u8, (1000, 2)] 37.4 µs 31.8 µs +17.43%

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 (25dce5c) with develop (e8e48c8)

Open in CodSpeed

Footnotes

  1. 518 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
@joseph-isaacs
joseph-isaacs force-pushed the ji/small-u8-table-take-neon branch from 21fa748 to e97db31 Compare September 9, 2026 16:21
@joseph-isaacs
joseph-isaacs force-pushed the ji/small-u8-table-take-avx2 branch from 0129184 to 134d1c5 Compare September 9, 2026 16:21
@github-actions github-actions Bot removed the stale This PR is stale and will be auto-closed soon label Sep 18, 2026
@github-actions

github-actions Bot commented Oct 2, 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 Oct 2, 2026
@joseph-isaacs joseph-isaacs added changelog/performance A performance improvement and removed stale This PR is stale and will be auto-closed soon labels Oct 5, 2026
Base automatically changed from ji/small-u8-table-take-neon to develop October 5, 2026 16:34
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
@joseph-isaacs
joseph-isaacs force-pushed the ji/small-u8-table-take-avx2 branch from 7d23aa5 to 25dce5c Compare October 5, 2026 16:53
@joseph-isaacs
joseph-isaacs removed this pull request from stack #9573 October 5, 2026 16:56
@joseph-isaacs
joseph-isaacs enabled auto-merge (squash) October 5, 2026 16:56
@joseph-isaacs
joseph-isaacs merged commit d97fb1c into develop Oct 5, 2026
89 of 90 checks passed
@joseph-isaacs
joseph-isaacs deleted the ji/small-u8-table-take-avx2 branch October 5, 2026 17:10
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.

3 participants