perf(vector/search): stop materializing vector_ids() on count and warmup paths (#672) - #930
Merged
Conversation
…mup paths (closes #672)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #633 the audit-flagged "clone" in
vector_ids()is really an O(N) per-call String rehydration at the trait boundary (readers store interned(u64, u16)+ a field dictionary). Rather than breaking the publicvector_ids()signature, this PR stops every per-query and startup call site from using it:hnsw/flat/ivfsearchers, no-field branch):.len()of a full materialization →vector_count()(equal by construction: one entry per(doc, field)record).SegmentFanoutSearcher::count: per-segment full materialization → per-field iteration overdoc_ids_for_field(an O(1)Arcclone on all three reader types, perf(vector): cache vector_ids per field at reader load #405), with dictionary-backedfield_names()supplying the field list for unfiltered counts. Newest-wins masking and deletion filtering unchanged.pub(crate) HnswIndexReader::interned_vector_ids()borrows dictionary names — the code already held the concrete reader, so the 10M-String startup spike disappears with no trait change.Measured
10 segments × 2k docs, 100
countcalls, release, best of 3:count(field)380.7 → 352.6ms,count(None)378.5 → 350.4ms (-7.4% both). Honest read: at this in-memory scale the containment masking dominates and the allocation was ~7% — the real win is that the removed allocation grows linearly with corpus size (~32 B/record/segment; the audit priced 320 MB per call at 10M records), so a scale-proportional allocation spike is gone rather than a large steady-state percentage.Tests
count_masks_duplicates_and_deletionsregression test on the bug(vector/search): cross-segment scores are not comparable — out-of-range queries clamp to similarity 1.0 per segment #927 mixed-range fixture: distinct live(doc, field)keys, cross-segment duplicates counted once, deletions excluded, field filter honored (missing field → 0) — count semantics pinned unchanged across the rewrite.Verification
cargo fmt --checkandcargo clippy --all-targets -- -D warningsclean on stable and 1.97.0cargo test -p laurus --lib: 1258 passed;--tests: all 64 binaries okcargo check -p laurus-wasm --target wasm32-unknown-unknown: cleanCloses #672. Builds on #633 (interning) / #405 (
doc_ids_for_field) / #926 (shared fan-out).