Skip to content

perf: specialize comparison bitmap packing for 8-bit inputs - #9948

Merged
robert3005 merged 4 commits into
developfrom
mk/primitive-compare-bitmap
Sep 23, 2026
Merged

robert3005 merged 4 commits into
developfrom
mk/primitive-compare-bitmap

Conversation

@mhk197

@mhk197 mhk197 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Speed up comparisons over i8 and u8 arrays by packing each 64-row group with the existing collect_bool_word helper. The byte representation lets the compiler vectorize the comparison and bitmap construction efficiently.

Dedicated collect_bits_dispatch and collect_zip_bits_dispatch helpers select this path from T::PTYPE, which is constant for each compiled primitive type. The byte-packing loops live separately in collect_bits_narrow and collect_zip_bits_narrow. Wider integer and floating-point types continue to use the original lane collectors, so they avoid the AVX2 regressions from applying byte packing to wider masks.

Changes

  • Specialize bitmap collection for 8-bit array/array and array/constant comparisons, including constants on either side.

No benchmark source or public API changes. This primitive optimization is independent of NarrowArray.

Performance

Unchanged existing benchmarks on Apple M5 Max (aarch64), Rust 1.98.0, 8,192 rows.

Existing benchmark Before 8-bit specialization Speedup
compare_f32 2.833 µs 2.832 µs 1.00×
compare_float 3.791 µs 3.791 µs 1.00×
compare_int 1.958 µs 1.958 µs 1.00×
compare_int_constant 1.624 µs 1.624 µs 1.00×
compare_int_eq 1.978 µs 1.958 µs 1.01×
compare_int_nullable 2.165 µs 2.166 µs 1.00×
compare_u8 1.874 µs 0.698 µs 2.69×
compare_u64 1.979 µs 1.999 µs 0.99×

@codspeed

codspeed Bot commented Sep 18, 2026

Copy link
Copy Markdown

Merging this PR will regress 4 benchmarks

⚠️ 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

⚡ 6 improved benchmarks
❌ 4 regressed benchmarks
✅ 2198 untouched benchmarks
⏩ 293 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime mul_u64_nonnull_neon 28.9 µs 40.4 µs -28.63%
Simulation take_fsl_u32_random[256, 10] 124.4 µs 157.9 µs -21.22%
WallTime mul_i64_nonnull_neon 32.9 µs 38.6 µs -14.97%
WallTime multiply_shapes_neon[(32768, PerRowPerRow)] 32.8 µs 38.4 µs -14.53%
WallTime compare_u8_avx2 3.5 µs 1.8 µs +95.03%
WallTime compare_u8_neon 3.9 µs 2.2 µs +77.02%
WallTime compare_u8_avx512 2.4 µs 1.7 µs +39.79%
Simulation take_fsl_u32_random[16, 100] 165.8 µs 124.3 µs +33.43%
Simulation take_fsl_nullable_random[16, 100] 187.7 µs 162.9 µs +15.25%
WallTime dict_canonicalize_gt_u8_neon[1000000] 547 µs 488.3 µs +12.03%

Tip

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


Comparing mk/primitive-compare-bitmap (c215b0e) with develop (c3ade49)2

Open in CodSpeed

Footnotes

  1. 293 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 develop (ca2538d) during the generation of this report, so c3ade49 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@mhk197 mhk197 changed the title perf: pack primitive comparison results in fixed-size chunks perf: specialize comparison bitmap packing for 8-bit inputs Sep 22, 2026
@mhk197 mhk197 added the changelog/performance A performance improvement label Sep 22, 2026
@mhk197
mhk197 marked this pull request as ready for review September 22, 2026 15:19
Reuse collect_bool_word for primitive comparison bitmaps while preserving
execution-context allocation and comparison semantics. Cover bitmap
boundaries, all primitive types, nulls, and constant operand orientation.

Signed-off-by: "Matt Katz" <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Use byte packing only for i8/u8 and preserve the existing lane collectors
for wider primitive types. The type selection folds away during
monomorphization and avoids the wider AVX2 comparison regressions.

Signed-off-by: "Matt Katz" <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Keep type selection in collect_bits_dispatch and collect_zip_bits_dispatch,
with independent narrow collectors and the existing wider collectors.

Signed-off-by: "Matt Katz" <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Limit the new boundary matrix to the i8/u8 specialization. Existing tests
cover the unchanged wider primitive comparison paths.

Signed-off-by: "Matt Katz" <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@mhk197
mhk197 force-pushed the mk/primitive-compare-bitmap branch from 6a69442 to c215b0e Compare September 22, 2026 15:23
@connortsui20
connortsui20 self-requested a review September 22, 2026 15:44
@connortsui20

Copy link
Copy Markdown
Member

related: #9703

@robert3005 robert3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's merge this, I know we will soon replace this with rowfn

@robert3005
robert3005 merged commit d55f2ab into develop Sep 23, 2026
89 of 90 checks passed
@robert3005
robert3005 deleted the mk/primitive-compare-bitmap branch September 23, 2026 21:32
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