Repository navigation
Conversation
Opening a vector index from its cached IvfIndexState reconstructed the index object for every query: Q::from_metadata ran again (widening an f16 PQ codebook and preparing its L2 targets, about 1.5 MB per query) and a fresh QueryScratchPool was created whose scratches then grew on first use. The state now holds the quantizer and the scratch pool in runtime-only cells, excluded from the cache codec like rq_search_cache, so later reconstructions share them. With an external row-id mask the mask was deep-copied twice per query: MaskAndLoader::load returned it by value while the plan still held the Arc, and DatasetPreFilter cloned both the loaded mask and the deletion mask before intersecting. FilterLoader::load now returns the Arc, RowAddrMask::intersect_ref combines masks from references, and a lone mask is shared with its cache entry. Per query (4M rows, fsl<f16,768>, IVF_PQ 128 x 48, k=10, nprobes=20): plain 7 849 -> 6 489 allocations and 11.7 -> 4.3 MB, p50 5.3 -> 4.4 ms; 5% allowlist mask 19 717 -> 17 828 allocations and 15.7 -> 9.0 MB, p50 6.4 -> 6.0 ms.
FilterLoader is public, so its load signature stays; a provided load_shared hands out the mask behind an Arc and MaskAndLoader overrides it to share the Arc it already holds. The cached quantizer is only built for storages that keep one, so an RQ index does not carry its rotation matrices in the cache for nothing. The intersect_ref test now pins an empty intersection and a Full/Partial pair.
The quantizer is now built when a state entry is exported or decoded, so the cache charges for it on admission and a reconstruction can no longer grow the entry. The scratch pool is no longer kept in the state: its buffers grow with use after admission, which the cache would not see.
|
Addressed the accounting note: the quantizer cell is now filled when the state entry is exported or decoded, before the entry enters the cache, so its size is part of the admission charge, and the scratch pool is no longer kept in the state since its buffers grow after admission. |
wjones127
left a comment
There was a problem hiding this comment.
Nice profiling-driven PR: caching the PQ quantizer in the index cache entry and intersecting masks by reference are both clear wins, and the cache-accounting issue from the first revision is fixed.
Requesting changes for one thing: the new RowAddrTreeMap::intersection/difference sit on every prefiltered query, and their whole-fragment branches (including the deleted-fragments path) aren't covered by the parity test. The rest is non-blocking: making the quantizer field a plain Option, tightening the state-entry test, reusing the storage's quantizer on export, and collapsing load/load_shared into one method.
- Cover every arm of `RowAddrTreeMap::intersection` and `difference` against the consuming `intersect`, and spell out the expected masks. - `intersection` drops a fragment left without rows whichever side the empty set came from, as `BitAndAssign` does. - `FilterLoader::load` returns `Arc<RowAddrMask>`; `load_shared` is gone. - `IvfIndexState::quantizer` is a plain `Option<Quantizer>`, taken from the storage on export instead of being rebuilt. - The state test asserts that the quantizer is present. - `DatasetPreFilter` folds its masks without a counter or `expect`.
wjones127
left a comment
There was a problem hiding this comment.
Thanks for working through the last round so thoroughly. The parity test now reaches every arm of intersection/difference, including the deleted-fragment block list, and spells out the expected masks. The quantizer is a plain field set at construction, export reuses the storage's copy, and load/load_shared are one method. Those were all my earlier points.
Blocking (1): the FilterLoader::load signature change doesn't compile against current main, because PrefilterUnionExec (#10001) landed after this branch was cut. Rebasing and updating that call site should clear the CI failures.
Encouraged: find a way to share the set-algebra logic between the in-place and by-reference mask operations without giving up performance, plus a couple of small simplifications inline.
Re the gatekeeper's breaking-change ask: FilterLoader is documented as internal, so no label is needed.
PrefilterUnionExec now takes the shared mask FilterLoader::load returns.
The in-place and by-reference intersection and difference of RowAddrTreeMap go through one per-fragment definition. The storage hands out its retained quantizer for cache export, and from_cached_with_remapper takes the prebuilt quantizer instead of a third constructor.
RowAddrMask::intersect_with narrows an owned mask by a borrowed one, and the consuming intersect goes through it, so the allow/block rules of the owned form exist once.
|
@wjones127 thanks for the second round, everything from it is addressed:
Details are in the inline threads. |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The author's update is reflected in the current code: later mask-fold steps reuse the owned result while preserving the allow/block semantics. The main integration and cache-admission fixes remain intact. No blocking findings remain.
Please mark this PR with the breaking-change label: lance_index::prefilter::FilterLoader::load returns Result<Arc<RowAddrMask>>, so Rust loader implementations and callers must use the shared return type; lance_index::vector::storage::IvfQuantizationStorage::from_cached_with_remapper takes a new Option<Quantizer> argument, so its Rust callers must supply it.
wjones127
left a comment
There was a problem hiding this comment.
Thanks for another thorough round. Everything from last time is in: the in-place and by-reference set operations share one per-fragment definition, and export takes the storage's quantizer directly. CI is green. Approving, with a few non-blocking cleanups inline.
suggestion: The description still says IvfQuantizationStorage::from_cached_with_quantizer takes the cached quantizer, but that constructor is gone now that from_cached_with_remapper takes it. Could you update that line, and the FilterLoader bullet, to match the final shape? The description becomes the squash commit message.
BitAnd for RowAddrMask goes through intersect. PrefilterUnionExec and the shared multi-match prefilter intersect without cloning a mask. A whole fragment minus an empty partial stays whole. The decode-side quantizer helper is build_retained_quantizer, and two no-op async wrappers around FilterLoader::load are gone.
|
Thanks for the approval! The inline cleanups are in c454036, and I updated the description to the final shape: |
Summary
Allocation profiling of an IVF_PQ search with a
with_row_id_prefiltermask (a counting global allocator plusperf statpage-fault, dTLB and L1 counters) found work that every query repeated although nothing about it changes between queries:open_vector_indexhits theIvfIndexStatecache and callsreconstruct, which ranQ::from_metadataagain: for a PQ codebook that widens the f16 codebook to f32 and builds the 48 prepared L2 targets, about 1.5 MB per query.IvfIndexStatenow carries the quantizer as a runtime-onlyOption<Quantizer>, excluded from the cache codec likerq_search_cache. It is set when the state is built (taken from the storage on export, built from the metadata on decode), so the cache charges for it on admission and a reconstruction cannot grow the entry; only storages that retain a quantizer (PQ) carry it.IvfQuantizationStorage::retained_quantizerhands out the storage's copy for the export, and the hiddenfrom_cached_with_remapperconstructor takes the cached quantizer.MaskAndLoader::loadreturned the mask by value, soArc::unwrap_or_clonecopied it while the plan still held theArc, andDatasetPreFilter::wait_for_readycloned both the loaded mask and the deletion mask before intersecting.FilterLoader::loadnow returnsArc<RowAddrMask>(the trait is documented as internal;MaskAndLoaderhands out its sharedArc, other loaders wrap a fresh mask).RowAddrMask::intersect_ref(withRowAddrTreeMap::intersection/difference) builds the combined mask from references,RowAddrMask::intersect_withnarrows an owned mask by a borrowed one in place, and a lone mask is shared with its cache entry.DatasetPreFiltercombines its first two masks by reference and folds the rest into that result;PrefilterUnionExecand the shared multi-match prefilter intersect without cloning either.&=,-=) and by-reference (intersection,difference) operations ofRowAddrTreeMapgo through one per-fragment rule each onRowAddrSelection, andRowAddrMask's&andintersectgo throughintersect_with. A whole fragment minus an empty partial now stays whole instead of becoming a bitmap of every offset.Per query on the same 4M-row dataset as #10828 (
fsl<f16,768>, IVF_PQ 128 × 48, k=10, nprobes=20, one client, measured with the scratch pool also cached; the quantizer is the larger part):The remaining mask-side allocations are the per-run roaring intersections inside
selected_indices; walking the bitmap's range instead allocates nothing but measured slower, so they stay.Tests
test_state_entry_carries_quantizer_before_admission: an exported and a decoded PQ state entry report the samedeep_size_ofafter a reconstruction, so the cache's admission charge covers everything the entry retains.test_intersect_ref_matches_intersect:intersect_ref,intersect_withand the consumingintersectagree for every pairing of whole, partial, empty and absent fragments across allow/allow, allow/block and block/block masks, and the allow-list results are also spelled out.MaskAndLoader,DatasetPreFilterand prefilter loader tests cover the shared return.cargo fmt --allandcargo clippy --all --tests --benches -- -D warningsare clean.