Commit b43c4ef
authored
use sorted inserts to improve builder performance (#91553)
## What
Optimizes AMQF (Approximate Membership Query Filter) construction in `StreamingSstWriter` by deferring filter building to `close()` time and using qfilter's sorted `Builder` API.
## Why
The previous approach inserted each key hash into the AMQF filter eagerly during `add()`, using random-access `insert_fingerprint` calls. The new qfilter `Builder` API supports sequential sorted insertion which is significantly faster, but requires fingerprints in non-decreasing order.
## How
1. **Deferred construction**: Instead of building the AMQF incrementally during `add()`, collect key hashes (truncated to `u32`) into a vec during writes, then build the filter in one pass at `close()` time.
2. **Sorted Builder insertion**: Sort collected hashes by fingerprint value, then feed them to `Builder::insert_fingerprint` in order. This uses the Builder's optimized sorted-insert path.
3. **u32 storage**: Since fingerprint size is always ≤32 bits, store collected hashes as `u32` instead of `u64`, halving memory usage and improving sort cache behavior.
4. **Exact sizing**: The Builder is constructed with the exact entry count (known at `close()` time) rather than the `max_entry_count` estimate, producing optimally-sized filters.
## Benchmark results (vs `filter_ref` baseline)
`write/key_8/value_4/` benchmark:
| Entries | filter_ref | sorted_insert | Change |
|---------|-----------|---------------|--------|
| 85K | 22.3 ms | 21.1 ms | **-5.3%** |
| 853K | 149.2 ms | 111.9 ms | **-25.0%** |
| 8.3M | 1049 ms | 998.8 ms | **-4.8%** |
The 853K case (typical compacted SST size) shows the largest improvement as AMQF construction is a significant fraction of total write time at that scale.1 parent d3cbd5b commit b43c4ef
1 file changed
Lines changed: 25 additions & 18 deletions
Lines changed: 25 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
509 | | - | |
510 | | - | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
511 | 512 | | |
512 | 513 | | |
513 | 514 | | |
| |||
536 | 537 | | |
537 | 538 | | |
538 | 539 | | |
539 | | - | |
540 | | - | |
541 | | - | |
| 540 | + | |
542 | 541 | | |
543 | 542 | | |
544 | | - | |
545 | | - | |
546 | 543 | | |
547 | 544 | | |
548 | 545 | | |
| |||
569 | 566 | | |
570 | 567 | | |
571 | 568 | | |
572 | | - | |
| 569 | + | |
573 | 570 | | |
574 | 571 | | |
575 | 572 | | |
| |||
627 | 624 | | |
628 | 625 | | |
629 | 626 | | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
| 627 | + | |
| 628 | + | |
636 | 629 | | |
637 | 630 | | |
638 | 631 | | |
| |||
950 | 943 | | |
951 | 944 | | |
952 | 945 | | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
957 | 964 | | |
958 | 965 | | |
959 | 966 | | |
| |||
0 commit comments