Skip to content

Add min bloom filter crate - #144

Open
aneubeck wants to merge 2 commits into
mainfrom
aneubeck-implement-min-bloom-filter
Open

Add min bloom filter crate#144
aneubeck wants to merge 2 commits into
mainfrom
aneubeck-implement-min-bloom-filter

Conversation

@aneubeck

@aneubeck aneubeck commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a split-block min Bloom filter storing eight nibbles per u32
  • implement max insertion and min retrieval with an AArch64 NEON fast path
  • size filters using the Poisson split-block occupancy model
  • add Criterion benchmarks against sbbf-rs-safe over 3 million entries
  • add an accuracy evaluation for geometrically distributed values

False-positive sizing

For block occupancy X ~ Poisson(lambda), the false-positive probability is:

P(FP) = sum(x = 0..infinity) [
    exp(-lambda) * lambda^x / x! * (1 - (7 / 8)^x)^8
]

Numerically solving this expression gives 13.43 nibbles/entry for 1% FPP and 25.34 nibbles/entry for 0.1% FPP. Over 10 million absent queries, observed rates were 0.9941% and 0.0991%.

Apple M4 Max benchmark results

Target FPP Min filter memory Min insert Min retrieve SBBF insert SBBF contains
1% 20.15 MB 2.71 ns/entry 1.63 ns/entry 1.52 ns/entry 1.23 ns/entry
0.1% 38.01 MB 5.02 ns/entry 3.08 ns/entry 1.57 ns/entry 1.26 ns/entry

An ordinary optimally sized Bloom filter requires 3.59 MB and 5.39 MB, respectively.

Value accuracy

For 3 million inserted values drawn from geometric distributions with ratios 0.5 and 0.2, all 10 million inserted-key queries returned the exact value; no overestimation was observed.

Run with:

cargo bench -p min-bloom-filter --bench performance
cargo run --release -p min-bloom-filter --example accuracy

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ab0460bc-ae55-4457-a8e0-00169d9c2692
Copilot AI balanced review requested due to automatic review settings August 5, 2026 10:38
@aneubeck
aneubeck requested a review from a team as a code owner August 5, 2026 10:38

Copilot AI 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.

Pull request overview

Adds a four-bit split-block Bloom filter with architecture-specific acceleration and performance benchmarks.

Changes:

  • Implements max insertion, min retrieval, sizing, and tests.
  • Adds an AArch64 NEON fast path.
  • Adds documentation and comparative Criterion benchmarks.
Show a summary per file
File Description
README.md Lists the new crate.
crates/min-bloom-filter/src/lib.rs Implements the filter and tests.
crates/min-bloom-filter/README.md Documents usage and benchmarks.
crates/min-bloom-filter/Cargo.toml Defines crate metadata and dependencies.
crates/min-bloom-filter/benchmarks/performance.rs Benchmarks against sbbf-rs-safe.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment on lines +130 to +134
#[cfg(target_arch = "aarch64")]
#[inline]
fn insert_block(block: &mut [u32; WORDS_PER_BLOCK], hash: u32, value: u8) {
// SAFETY: NEON is mandatory on AArch64, and `block` points to eight valid u32 values.
unsafe { neon::insert(block.as_mut_ptr(), hash, value) }
Comment thread crates/min-bloom-filter/src/lib.rs Outdated
Comment on lines +49 to +53
let probes = WORDS_PER_BLOCK as f64;
let bits_per_entry = -probes / (1.0 - false_positive_rate.powf(1.0 / probes)).ln();
let total_bits =
(expected_entries as f64 * bits_per_entry * f64::from(MAX_VALUE.ilog2() + 1)).ceil()
as usize;
Comment thread crates/min-bloom-filter/README.md Outdated
Comment on lines +26 to +29
| Target FPR | Memory | Insert | Retrieve |
|---|---:|---:|---:|
| 1% | 14.52 MB | 2.27 ns/entry | 1.42 ns/entry |
| 0.1% | 21.91 MB | 2.74 ns/entry | 1.58 ns/entry |
Comment thread crates/min-bloom-filter/README.md Outdated
Comment on lines +31 to +36
For comparison, `sbbf-rs-safe` on the same hashes:

| Target FPR | Insert | Contains |
|---|---:|---:|
| 1% | 1.50 ns/entry | 1.24 ns/entry |
| 0.1% | 1.55 ns/entry | 1.26 ns/entry |

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.

We might want to explain that this is doing something else so the better performance isn't apples-to-apples.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ab0460bc-ae55-4457-a8e0-00169d9c2692
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants