Skip to content

Optimise bitpacked filtering and take for valid runs - #10281

Merged
robert3005 merged 15 commits into
developfrom
rk/bitpacked-filter
Oct 15, 2026
Merged

robert3005 merged 15 commits into
developfrom
rk/bitpacked-filter

Conversation

@robert3005

Copy link
Copy Markdown
Contributor

Previous code assumed indices but these are almost never cached. Instead we handle the slices (which can be produced by lists) and bit buffers which are the default

@robert3005 robert3005 added the changelog/performance A performance improvement label Oct 4, 2026
@robert3005
robert3005 force-pushed the rk/bitpacked-filter branch from 0e06ee5 to fd431ca Compare October 7, 2026 15:41
@codspeed

codspeed Bot commented Oct 7, 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.

⚠️ 2 benchmarks measured no execution time

Nothing ran under measurement, usually because the compiler removed the code under test. These results are not comparable, so they count as unchanged.

Preventing compiler optimizations

⚠️ 19 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

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

⚡ 27 improved benchmarks
❌ 1 regressed benchmark
✅ 2231 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ WallTime bitpack_blocked_compress_avx2 6.8 µs 7.6 µs -10.78%
⚡ WallTime threshold_neon[8] 2.8 µs 1.5 µs +92.76%
⚡ WallTime threshold_neon[64] 4.3 µs 2.7 µs +61%
⚡ WallTime filter_neon[64] 2.7 µs 1.8 µs +52.33%
⚡ WallTime threshold_avx2[8] 1.9 µs 1.4 µs +38.72%
⚡ WallTime threshold_avx512[8] 2 µs 1.5 µs +38.4%
⚡ WallTime filter_avx512[80] 2.3 µs 1.7 µs +37.14%
⚡ WallTime threshold_avx2[80] 3.3 µs 2.6 µs +28.15%
⚡ WallTime filter_avx2[64] 2.1 µs 1.6 µs +25.69%
⚡ WallTime filter_avx512[64] 2.1 µs 1.7 µs +23.27%
⚡ WallTime filter_avx2[80] 2.2 µs 1.8 µs +22.12%
⚡ WallTime threshold_avx512[64] 3 µs 2.5 µs +21.35%
⚡ WallTime threshold_avx2[64] 3 µs 2.5 µs +21.33%
⚡ WallTime threshold_neon[80] 4.7 µs 3.9 µs +19.02%
⚡ ⚠️ Simulation random_i128[0.01] 7.6 µs 6.4 µs +18.66%
⚡ WallTime threshold_avx512[80] 3.3 µs 2.8 µs +16.81%
⚡ WallTime filter_avx2[8] 1,053 ns 904 ns +16.48%
⚡ WallTime filter_neon[80] 2.9 µs 2.5 µs +14.3%
⚡ WallTime starts_with_avx512[8, VarBin] 46.3 µs 40.5 µs +14.21%
⚡ Simulation random_i128[0.8] 175.3 µs 154.3 µs +13.62%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

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


Comparing rk/bitpacked-filter (066e637) with develop (505fcfa)

Open in CodSpeed

@joseph-isaacs

Copy link
Copy Markdown
Contributor

Do you have any numbers here?

@joseph-isaacs
joseph-isaacs marked this pull request as draft October 8, 2026 12:57
@robert3005
robert3005 marked this pull request as ready for review October 12, 2026 16:39
@robert3005 robert3005 changed the title Optimise bitpacked filtering for valid runs and buffer filtering Optimise bitpacked filtering and take for valid runs and buffer filtering Oct 12, 2026
@robert3005 robert3005 changed the title Optimise bitpacked filtering and take for valid runs and buffer filtering Optimise bitpacked filtering and take for valid runs Oct 12, 2026
@robert3005
robert3005 force-pushed the rk/bitpacked-filter branch 2 times, most recently from 04aca9b to 89220a8 Compare October 14, 2026 15:33
claude and others added 13 commits October 15, 2026 15:07
…rializing indices

BitPacked's filter kernel only handled very sparse masks (below 3-9% density),
and for those it materialized the mask's `usize` indices first; any denser mask
unpacked the whole array before filtering.

The kernel now walks the selection one 1024-value FastLanes chunk at a time:
from the mask's cached slices when it has them (as FixedSizeList element masks
do) and otherwise straight from the bitmap. Empty chunks are skipped, fully
selected chunks unpack directly into the output, chunks with few selected values
use `unchecked_unpack_indices` on a small stack array, and the rest unpack into
an L1-resident scratch chunk that is compacted with run copies, a branch-free
loop or a trailing-zeros walk per mask word. Dense masks with scattered values
still decline the kernel, so the vectorized canonical filter handles them.

Adds a `bitpacking_filter` benchmark covering primitive i32 and FSL<i32>
elements bit-packed to 16 bits. Each iteration builds a fresh mask so cached
indices are not reused across iterations.

Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GEPn56FBLoa8Yq6jexAwWL
…uses SIMD

The chunked BitPacked filter declined only above a fixed 0.2 density, which
only matches the canonical filter's SIMD compress crossover for 4-byte values.
For u8 and u16 the canonical filter compacts with AVX-512/AVX2/NEON at much
lower densities, so the chunked kernel was 2-6x slower there.

Expose `uses_simd_compress::<T>(mask)` from vortex-array and decline whenever
the canonical filter would compact with SIMD, except for very sparse masks
(<= 1%) and masks with long cached runs.

Also drop the branch-free word compaction, which ran the full word up to the
last selected value and was 20-25% slower than the trailing-zeros walk at the
densities where it was used.

Signed-off-by: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AazYKY45Y5yuV5NCYwqbNf
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Will Manning <will@willmanning.io>
Signed-off-by: "Robert Kruszewski" <github@robertk.io>
Use FL_CHUNK_SIZE for the FastLanes chunk length. Drop the max_sparse
and indices fields from ChunkedFilter: compute the sparse threshold from
the value width and keep the index scratch on the stack of each walk.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
filter_chunked is public, but its docs linked to the private chunked
module for the chunk strategies. Move the strategy table into the
filter_chunked docs and remove the links to private items.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
filter_buffer uses the cached indices of a mask when the density is at
most 0.5, but filter_chunked always walked the whole bitmap. For sparse
masks with cached indices, such as masks from Mask::from_indices, the
walk over every empty chunk cost more than the decode itself.

Add the cached indices step to filter_chunked, between the cached slices
and the bitmap, with the same density rule as filter_buffer.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
Signed-off-by: Robert Kruszewski <github@robertk.io>

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.

move to vortex-buffer (can be a follow up).

@joseph-isaacs joseph-isaacs 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.

Can we this filter magic for fixed width compute

@robert3005
robert3005 enabled auto-merge (squash) October 15, 2026 14:17
@robert3005
robert3005 merged commit 845511f into develop Oct 15, 2026
100 of 102 checks passed
@robert3005
robert3005 deleted the rk/bitpacked-filter branch October 15, 2026 14:27
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.

4 participants