Repository navigation
perf(index): open fragment reuse indexes 10-2200x faster - #8887
Conversation
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The compact rank structures address FRI open-time hash-map expansion at the right boundary while preserving ordered multi-version remapping, deletions, split outputs, and unaffected-row pass-through. The focused remap and FRI integration coverage is green.
Please mark this PR with the breaking-change label.
| distance_type: DistanceType, | ||
| frag_reuse_index: Option<Arc<dyn RowIdRemapper>>, | ||
| ) -> Result<Self> { | ||
| if frag_reuse_index.is_some() { |
There was a problem hiding this comment.
Could we keep the existing public constructors on the legacy dispatch path? StorageBuilder::new still accepts a FragReuseIndex, but it wraps it as a RowIdRemapper and build now always reaches this default method. Any out-of-tree QuantizerStorage that already handles Some(frag_reuse_index) in try_from_batch will still compile but fail here with NotSupported; IvfQuantizationStorage::try_new has the same regression. Only the new compact/remapper-specific constructors should call the generic remapper method.
There was a problem hiding this comment.
I don't think this is a real issue any more
LuciferYang
left a comment
There was a problem hiding this comment.
Read this focusing on whether the swap preserves the tri-state remap semantics, and on the open path itself.
The mapping logic holds up. I checked rank agreement across all three RankedOffsets arms including offsets past the universe, the Err(i) => i - 1 in compute_new_addr (unreachable, since a non-empty range vec always starts at key 0 and the empty vec is excluded by the row-count check), the u32 bound on rank_before_word, and the chained get against the legacy per-version walk. No input gives a different answer. The persisted old_frags ordering question also resolves in the new code's favour: manifest_build.rs:1233 forces ascending manifest order after every commit, and in the two cases where that does not hold (a hand-assembled CompactionTask, a pre-#2075 manifest) the list-order rank matches what compaction actually read and wrote, while the legacy ascending-address zip did not.
Five comments below. The first is the only one I would call a must-fix before merge, and it is three ?. The last is a design question rather than a defect, and since it changes which representation the common case gets, it needs a benchmark re-run rather than a patch.
One thing for the description rather than the code: upstream/main rejected non-ascending new-fragment ids in GroupRemap::new and had test_compact_rejects_new_frags_out_of_write_order asserting that. This PR removes the check and replaces the test with one asserting the opposite. The reasoning is sound, since compute_new_addr binary-searches on rewritten_rows_before, which is monotonic by construction and independent of fragment id order. Flipping a guard added by #7237 is worth a sentence for whoever reads this later.
## Background We had independently implemented the equivalent of #8887 on our own branch: opening the fragment-reuse index into a compact per-fragment representation instead of expanding every reuse version into a per-row map. Same reason, the expansion dominates memory on a long reuse chain, and much the same shape, positional mapping of rewritten rows onto new fragments with rank lookups over roaring bitmaps. By the time we came to propose it, #8887 was already merged, so none of that implementation is needed here. What our branch also carried was the tests written while getting the mapping right, and those cover behaviours the current suite does not. This PR is only those tests, adapted to the code on `main`. ## What it adds The existing tests in `rust/lance-table/src/system_index/frag_reuse.rs` cover a one-to-many split, a two-link chain, corrupt bytes and three layout validations. These fill in the gaps: - **Rank across container types.** A 200k-row fragment with holes at 7, 65535, 65536 and 131072, so the rewritten offsets land in run and bitmap containers rather than the small array containers every existing test produces. This exercises all three `RankedOffsets` variants at the sizes real payloads reach, where a rank error returns a wrong row address rather than failing. - **Agreement with the direct transposition.** `transpose_row_ids_from_digest` is still the compaction-side path under `IndexRemapMode::Direct`. One test in the `lance` crate checks the compact index against it on every address of an ascending-fragment payload, the ordering compaction actually produces. Nothing in the tree asserted that the two agree. - **Row-count validation, both directions.** Too few and too many new rows; the only coverage of that check. - Moved, deleted and untouched rows in one group, including that an output address is not remapped again and that an offset past a fragment's recorded row count passes through unchanged. - Positional pairing in the order the old fragments are listed rather than by address, since the builder assigns positions by walking that list rather than sorting it. - A task whose output rolls into five new fragments, so the destination search lands strictly inside the list. - An emptied fragment mid-group not shifting later positions; a 32-link chain; a deletion mid-chain being terminal; groups within one version keeping independent positions; empty payloads. - A truncated changed-row-addrs body, added as a second case to the existing corrupt-bytes test. ## Notes Test-only; no production code changes. The tests build `FragReuseIndexDetails` directly with the module's existing helpers plus `group` and `details` constructors, and run synchronously. --- **Tracking:** Ported in part from rerun-io#59. Co-authored-by: Xuanwo <[email protected]>
Problem
Opening a fragment reuse index expands every affected row in every retained version into
HashMap<u64, Option<u64>>. Large or deferred compaction chains can therefore consume hundreds of MB and spend more than a second rebuilding maps before the index is usable.Design
Apply the persisted remap chain directly. Each old fragment selects one private rank representation when the FRI is opened:
Lookups preserve the existing tri-state behavior: unaffected rows pass through, deleted rows are dropped, and moved rows continue through later FRI versions. New-fragment ranges preserve writer order; fragment IDs do not need to be ascending because cumulative row positions, rather than ID ordering, determine remapping.
Compatibility
The protobuf schema, inline/external encoding, public API, and serde representation are unchanged. Files written by existing releases remain readable; the adaptive rank representation is private and rebuilt when the FRI is opened.
Performance
Measured at commit
f2e48591cecc5a3f8d33f2dbb746eb2a581469fcon a dedicated AWSc7i.4xlargewith the repository release profile. The four complete runs cover 15 workloads, two Local stores, two S3 stores, and 30 CPU samples per workload. Every workload verifies identical legacy and compact results before timing. CPU ranges use each workload's minimum speedup across all four runs to avoid reporting phase-dependent outliers.The remaining tradeoff is limited to small sparse inputs: at 0.1% changed, random-batch throughput is 0.84-0.90x of legacy; scalar throughput for the 0.1%-1% cases is 0.70-0.88x of legacy.
S3 external details
This metric includes the S3 read, protobuf decode, and runtime open for externally stored FRI details. Both implementations read the same object, with 10 samples each and alternating measurement order.
All 11 external-detail workloads improve, with an overall S3 speedup of 3.36-53.81x.
Raw JSONL results and the benchmark manifest are retained at:
Validation
cargo fmt --allcargo clippy --all --tests --benches -- -D warningscargo test -p lance-core -p lance-tablelance-core,lance-table, andlance