Skip to content

Blocked BitPacked: share the encoder loops with the global width - #10249

Closed
mhk197 wants to merge 16 commits into
mk/bitpacked-variable-encodefrom
mk/bitpacked-variable-encode-shared
Closed

mhk197 wants to merge 16 commits into
mk/bitpacked-variable-encodefrom
mk/bitpacked-variable-encode-shared

Conversation

@mhk197

@mhk197 mhk197 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Tracking Issue: #10167

Stacked on #10203; this PR targets mk/bitpacked-variable-encode.

Summary

Share the packing loop and patch gathering between the global-width and blocked encoders. They differed only in where each 1024-value block's bit width comes from.

  • bitpack_blocks(array, capacity, bit_width) is the existing bitpack_primitive loop, taking the width as a closure.
  • gather_patches_with(parray, bit_width, ..) is the existing gather_patches body, with the same change.

Both live in bitpack_compress/mod.rs next to ensure_non_negative_integers, the other helper the two encoders share.

bitpack_primitive and gather_patches keep their signatures and pass move |_| bit_width. The blocked encoder passes |block| bit_widths[block] and drops its own copies. The encoder is 63 lines shorter overall.

The bit-width histogram stays duplicated. Sharing it left the loop out of line under #[inline], which adds a call per array, and #[inline(always)] is denied by clippy.

Codegen

Each caller gets its own copy of the shared code, compiled with its own width closure. The global copy sees a constant width, so it compiles like the original loop. Comparing release assembly (codegen-units=1) before and after:

  • Every global gather_patches_impl copy is identical. The width closures are move; capturing the width by reference added a load.
  • bitpack_unchecked is 97% the same once register names are normalized. The differences are instruction order and block layout around the per-chunk unchecked_pack calls.

Results

Median walltime over 10 interleaved runs of the before and after bench binaries, 100 iterations per sample for bitpacked_compress_u32 and 20 for bitpack_blocked_compress:

Bench Before After Change
single_encoding_throughput::bitpacked_compress_u32 250.1 ns 251.4 ns +0.5%
bitpack_blocked::bitpack_blocked_compress 3,347 ns 3,365 ns +0.5%
alp_compress::compress_rd f64, 6 cases −0.7% to +0.9%, and +3.9% for (2000, 0.1)

(2000, 0.1) has measured −5.4%, −3.8% and +3.9% across runs. bitpacked_compress_u32 and compress_rd are the benches CodSpeed flagged on an earlier attempt at this sharing. That attempt zeroed a padding block on every call and passed the width as &dyn Fn.

@mhk197 mhk197 added the changelog/chore A trivial change label Oct 2, 2026
@codspeed

codspeed Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 10.22%

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

⚡ 1 improved benchmark
✅ 2103 untouched benchmarks
⏩ 518 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ WallTime words_gather_dispatch_neon[65536] 2.3 µs 2 µs +10.22%

Tip

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


Comparing mk/bitpacked-variable-encode-shared (bb0d98a) with mk/bitpacked-variable-encode (fbf3501)2

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

  2. No successful run was found on mk/bitpacked-variable-encode (f55497a) during the generation of this report, so f915a0d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

mhk197 added 3 commits October 5, 2026 11:39
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@mhk197
mhk197 force-pushed the mk/bitpacked-variable-encode branch from de28cfc to fbf3501 Compare October 5, 2026 15:45
@mhk197
mhk197 force-pushed the mk/bitpacked-variable-encode-shared branch from edacfb4 to eb38aaa Compare October 5, 2026 15:47
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.45324% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.23%. Comparing base (fbf3501) to head (eb38aaa).

Files with missing lines Patch % Lines
...lanes/src/bitpacking/array/bitpack_compress/mod.rs 84.80% 19 Missing ⚠️
...s/src/bitpacking/array/bitpack_compress/blocked.rs 60.00% 4 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

mhk197 added 11 commits October 5, 2026 12:19
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@mhk197
mhk197 force-pushed the mk/bitpacked-variable-encode branch from fbf3501 to f55497a Compare October 5, 2026 16:22
mhk197 added 2 commits October 5, 2026 12:22
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@mhk197
mhk197 force-pushed the mk/bitpacked-variable-encode-shared branch from eb38aaa to bb0d98a Compare October 5, 2026 16:22
@mhk197
mhk197 force-pushed the mk/bitpacked-variable-encode branch from f55497a to 977cca1 Compare October 5, 2026 16:39
@mhk197 mhk197 closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant