Skip to content

perf: cache the address-based deletion mask per dataset version - #10404

Merged
Xuanwo merged 4 commits into
lance-format:mainfrom
HeartLinked:perf/cache-address-deletion-mask
Nov 4, 2026
Merged

Xuanwo merged 4 commits into
lance-format:mainfrom
HeartLinked:perf/cache-address-deletion-mask

Conversation

@HeartLinked

@HeartLinked HeartLinked commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Part of #10402. #10403 is now in main; this branch is merged with the current main.

Problem

In DatasetPreFilter::create_deletion_mask_impl (rust/lance/src/index/prefilter.rs), the stable-row-ID path caches its constructed RowAddrMask in dataset.metadata_cache under RowAddrMaskKey (keyed by version, e_tag, and fragment-set hash).

However, the default address-based path (!manifest.uses_stable_row_ids()) rebuilds the dataset-wide deletion mask on every query: it loads every fragment's DeletionVector, converts each into a RoaringBitmap, and merges them into a RowAddrTreeMap. Because deletion files for a committed dataset version are immutable, the resulting mask only depends on the dataset version and the target fragment set.

Solution

  1. Extract fragment-set hashing into a shared helper fragment_set_hash(&RoaringBitmap) -> u64.
  2. When dataset.manifest_location().e_tag is present, cache the address-based RowAddrMask in dataset.metadata_cache under RowAddrMaskKey:
    • version: dataset.manifest().version
    • e_tag: Some(e_tag.as_str())
    • restrict_hash: Some((fragment_set_hash(&fragments) << 1) | restrict_to_fragments as u64) (bit 0 separates the restricted allow-list from the unrestricted block-list over the same fragment set).
    • Consistent with the stable-row-ID path, masks are not cached when e_tag is None.

Benchmark

Measurement boundary: these numbers are the author's pre-integration measurements. They are problem evidence, not a benchmark of the current head; this branch has not re-measured them.

Steady-state k=10 latency on the same 6.8B-row dataset (99,020 fragments, 153 IVF segments; see #10402):

Dataset State & Metric main With #10403 With #10403 + This PR
With deletion vectors (10.4% deleted), nprobes=1 66.0 – 66.9 s 34.5 – 35.2 s 0.35 – 0.40 s
With deletion vectors (10.4% deleted), nprobes=32 66.9 – 68.3 s 34.8 – 34.9 s 0.65 – 0.67 s
No deletions (baseline), nprobes=1 0.30 s 0.29 – 0.32 s 0.28 – 0.30 s

All benchmark runs used metadata_cache_size_bytes=48 GiB and index_cache_size_bytes=96 GiB so steady-state numbers measure CPU overhead only.

The cached mask takes ~1.4 GB in metadata_cache for 790M deleted rows (~1.8 bytes per deleted row, tracked via DeepSizeOf). Because DEFAULT_METADATA_CACHE_SIZE is 1 GiB (~0.97 GiB single-shard admission limit in QuickCacheBackend), the default cache budget accommodates masks up to roughly 500M deleted rows out of the box; workloads with more than ~500M deleted rows should configure a larger metadata_cache_size_bytes to retain the mask.

Tests

  • test_address_deletion_mask_cached_per_version (index/prefilter.rs): verifies cache hits, narrower-fragment and newer-version entries, distinguishes restricted from unrestricted masks with a live row outside the requested fragment set, and checks that a changed e-tag at the same version gets a separate entry. The e-tag case is focused cache-key isolation evidence, not a recreated-dataset I/O experiment.
  • Parameterized test_deletion_mask_recreated_at_same_uri and test_deletion_mask_without_generation_token_is_not_cached over use_stable_row_id in [false, true]. The local-filesystem recreation case has no e-tag, so it covers mask semantics without exercising cache-enabled generation isolation.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Without stable row ids, every vector search rebuilds the dataset-wide
deletion mask: it walks every fragment with a deletion file, converts each
deletion vector into a bitmap and merges them. Deletion files of a version
are immutable, so the result only depends on the version and the fragment
set. The stable-row-id path already caches its mask under `RowAddrMaskKey`;
the address path did not.

Cache the address mask the same way, in the metadata cache, keyed by
(version, manifest e-tag, fragment-set hash, restricted or not). As on the
row-id path, a dataset without an e-tag is not cached, because a dataset
recreated at the same URI restarts at the same version numbers.

On a 6.8B-row table with 99,020 fragments (all with deletion files), 153
index segments and 10% rows deleted, this eliminates the ~35 s per-query
mask reconstruction overhead; combined with lance-format#10403, steady-state k=10
search drops from 66 s to 0.37 s, versus 0.30 s on the same data files
without deletions. Results are unchanged.
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 28, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 28, 2026
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 4, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Gate recommendation: approve with a non-blocking risk.

Caching the immutable, version-scoped mask remains appropriate alongside #10403’s mask sharing, now in main.

The accepted capacity constraint remains: the metadata cache must retain the mask alongside other active metadata to avoid per-query reconstruction. The benchmark figures predate this integration; current-head latency has not been remeasured. No further change is requested.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 4, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. The address-based deletion mask is cached per version, manifest e-tag and fragment set, with the restricted/unrestricted discriminator; the strengthened tests cover cache hits, fragment-set and version separation, e-tag key isolation, and the restricted/unrestricted semantic difference. Local fmt, full ci-profile Clippy, the prefilter and affected segment-skip tests pass; applicable CI and Gatekeeper are green. The benchmark figures remain author-reported pre-integration evidence and the metadata-cache capacity caveat is documented in the description.

@Xuanwo
Xuanwo merged commit 343aa21 into lance-format:main Nov 4, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants