Repository navigation
perf(bloom): streamline insertion without membership checks - #306
Conversation
…n' into xuanwo/bloom-minimal-optimization
|
Local ARM64 follow-up for Method
Results
Across these 17 workloads, the largest median slowdown introduced by helper inlining was 1.65%. This does not establish that inlining is performance-neutral in every build or environment. Three baseline-relative regressions exceeded 5%. Each was confirmed in a separate nine-pair run, alternating baseline and inlined binaries with the baseline workload near 500 ms:
AssessmentI would accept this as an explicitly scoped optimization for fresh multi-hash filter construction, while acknowledging the platform-specific regressions. It is not a universal net win, and it does not satisfy a requirement that every measured workload stay within 5% of baseline on this ARM64 host. The substantial construction gains, improved repeated membership-and-insert path, and nearly unchanged membership queries support the intended optimization direction. API choice should follow the caller's needs: use Test cleanup and validationThe test-only follow-up The wider Bloom test review merged duplicate rounded-capacity/allocation setup, replaced repeated partial round-trip checks with full-filter equality, and removed redundant emptiness/count assertions and a second membership sample after round-trip. Java/C++/Go fixture matrices, set-operation contracts, and malformed-input checks remain covered. Validation: |
BloomFilter::insertreuses the conditional membership-insertion path for one hash. For multiple hashes, the insertion loop directly updates bits unconditionally and counts newly set bits arithmetically, avoiding the per-bit branch during fresh insertion.contains_and_insertretains conditional writes. Both paths preserve bit counts and serialized bytes, including collisions and repeated items.Benchmark
Measured
7eb0d2d1c9e38af4ebad7278a4bccf4cfcbd5a3fagainst675e3e123fda6da19657d345038252b16adc2ebbon an isolated EC2 c7i.2xlarge (Xeon Platinum 8488C), Rust 1.99.1 release defaults, CPU 2. The baseline sets a fixed workload near 300 ms; both variants execute exactly that same count in seven alternating pairs. These are measured whole-batch totals, not scaled ns/op figures.Before/after are median batch times. Speedup is baseline time divided by candidate time, reported as the median of seven paired ratios: above 1× is faster; below 1× is slower. Ratios use unrounded times; integer milliseconds are rounded only for display. These batch totals do not describe a single request or an application latency improvement.
Fresh-filter rows count inserted items: every 20,000 items create and destroy a separate filter inside timing. Repeated insertion and membership rows count calls on prebuilt fixtures. The benefit is concentrated in fresh multi-hash insertion; these measurements do not establish a universal application-level speedup.
All 17 measured workloads satisfy the per-case 5% median latency-regression limit (
median(after / before) <= 1.05). None has a positive median regression; the closest to baseline is membership hits at 0.44% less time. The limit applies to this matrix and host, not every individual noisy sample or every possible workload and environment.Validation
The insertion-helper inlining follow-up
2f2cac2passedcargo x check,cargo x test(777 passed, 0 failed), and the fullcargo x lintin a clean source copy containing the same changes. The existing checkout has generatedtarget/packagemanifests that fail Taplo formatting. The benchmark table above describes the pre-inlining revision7eb0d2d1c9e38af4ebad7278a4bccf4cfcbd5a3f; performance has not been remeasured after inlining.