fix: avoid index cache capacity fragmentation - #9115
Open
kamronis wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The change removes per-shard capacity fragmentation for automatically constructed index caches while preserving recommended sharding for metadata caches and caller-provided backends. Capacity, admission, residency, loader failure, and cancellation behavior are covered; existing high-concurrency measurements keep the single-shard trade-off bounded.
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.
fix(cache): avoid index cache capacity fragmentation
Problem
Increasing the session index cache from 7.5 to 8 GiB can introduce repeated
partition loading even when the index working set fits within both capacities.
With sufficient CPUs, the existing policy switches from one shard to two at
8 GiB. Quick cache shards have independent weight limits and cannot borrow
unused capacity from each other. A few large partition entries can overload
one shard while leaving space in the other.
This was observed with a synthetic 10M-row, 128-dimensional IVF_HNSW_FLAT index
containing nine partitions and an approximately 6.808 GiB cached working set.
Large partitions are relevant beyond this dataset: the current HNSW defaults
target approximately one million vectors per partition.
Change
Use a single Quick shard for automatically constructed session index caches,
giving all entries access to one shared weight budget. Apply this consistently
through
Session::new,Session::default, and the default/size variants ofSession::with_cache_backends.Metadata caches and
QuickCacheBackend::with_capacityretain recommendedsharding. Caller-provided backends remain unchanged. The explicit
QuickCacheShardPolicyoption is additive; there are no persistent-format orexisting public API signature changes. The configured capacity remains a
weighted-entry budget, not a process RSS limit, and Quick's existing admission
limits still apply.
Validation
The local workload reused the same saved synthetic index and queries with
L2, k=10, nprobes=9, and ef=320. Each residency run used a fresh process,
100 warmup calls, and 100 measured queries. A run without reloads means zero
partition loads during its measured phase. The p95 range below is across
individual processes.
The previous-policy results are historical measurements, not a new interleaved
comparison against a rebuilt baseline. Moka retained the working set in all
20 runs at each capacity. The insufficient-capacity 6 GiB Quick control
continued reloading partitions in all five runs and stayed within its budget.
Tests
Regression tests cover deterministic shard imbalance with unequal declared
weights, direct insertion, capacity/admission limits, shard-count boundaries,
loader failure/retry and cancellation, and automatic session construction.
Local checks passed on the implementation used for the experiments:
cargo test -p lance-core cache::quick::tests --lib: 9 passedcargo test -p lance session::tests --lib: 11 passedcargo fmt --all -- --checkcargo clippy --all --tests --benches -- -D warnings