Skip to content

perf(index): key v0 fragment reuse cache entries by the versions each segment predates - #10538

Merged
Xuanwo merged 10 commits into
lance-format:mainfrom
xuanyu-z:v0-fri-per-segment-cache-key
Nov 10, 2026
Merged

Xuanwo merged 10 commits into
lance-format:mainfrom
xuanyu-z:v0-fri-per-segment-cache-key

Conversation

@xuanyu-z

@xuanyu-z xuanyu-z commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With a v0 fragment reuse index (FRI), every index segment's cache entries are keyed by the whole FRI history, so any change to it (a deferred-remap compaction or a trim) cold-starts every segment of every index.

This keys each segment only by the versions that can still change its decoded rows: those it was not built after. A segment built (or remapped) after a version's rewrite holds none of that version's source addresses, so decoding with or without the version gives the same rows.

  • Built after the whole history: the plain per-index key, as with no FRI.
  • Otherwise: a hash of the digests of the versions it predates, so trimming older versions leaves its key unchanged.
  • No fragment bitmap: the whole-history key, as before. A rewrite group split by the segment's coverage counts as a version it predates.

Disjoint coverage alone is not treated as unaffected: deferred overlay compaction (#10109) withdraws coverage from a stale index while its data keeps the rows, which the remapper still translates.

What it improves

  • Compaction: no change; every existing segment predates the new version.
  • Trim: segments built or remapped after the trimmed versions stay warm. Older segments still reload.

Changes

  • index/frag_reuse_v0_cache.rs: v0_segment_cache_id, plus per-version digests (blake3 of the protobuf encoding) cached once per history.
  • ResolvedRemapping::V0 carries the segment's cache_id; fri_cache_id returns it, so the scalar and IVF open paths use it.
  • dataset/index/frag_reuse.rs: index_postdates_rewrite split out of is_index_remap_caught_up (trim unchanged).
  • Unchanged: tagged (v1) histories, legacy vector file formats, the FRI's own cache key.

Test plan

  • test_overlay_compaction_reconciles_stale_index (deferred case): a fresh reader warms the latest snapshot, then an indexed query on the pre-compaction snapshot must still match. Fails if disjoint coverage is treated as unaffected, or if v0 segments use the plain key.
  • v0_history_keeps_remapped_segments_warm_through_trim: segments reload once after the compaction and are then warm (the vector segment through the generic open); the remapped segment stays warm through the trim; scalar and nearest-neighbor queries stay correct. Fails if keys change on every open.
  • v0_segment_cache_id_tracks_versions_on_the_path: one case per branch.
  • cargo nextest run -p lance --lib filtered to frag_reuse, v0_, overlay, prewarm, legacy, defer, remap_caught_up (1,107 tests).
  • cargo clippy -p lance --tests -- -D warnings, RUSTDOCFLAGS="-D warnings" cargo doc -p lance --no-deps.

Under a v0 fragment reuse history every segment's cache entries were keyed
by the whole history, so each deferred-remap compaction or trim cold-started
every segment, including ones whose rows it never touched. Key a segment by
the versions it has not caught up on, the same condition the trim uses; a
segment with none shares the plain per-index namespace.
@xuanyu-z

Copy link
Copy Markdown
Contributor Author

@LuQQiu @wjones127 @jackye1995 could you take a look when you have time? This applies the per-segment idea from the tagged history's translation_fingerprint to v0: a segment's cache key covers only the versions is_index_remap_caught_up says it has not caught up on, so its soundness rests on the same condition the trim already uses. Keeping it as a draft until CI is green.

Hash each history version once and cache the digests with the history's
fragment set, so resolving a segment's key on every open only folds cached
digests. Move the per-segment key into its own module and cover each of its
branches with a table test.
@xuanyu-z
xuanyu-z marked this pull request as ready for review October 30, 2026 18:51

@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.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 30, 2026
Borrow the index fragment bitmap in is_index_remap_caught_up instead of
cloning it on every call, and return early from v0_segment_cache_id when
the segment shares no fragments with the reuse history.

Hash each reuse version's fields in place rather than converting to
protobuf and encoding, which copied every group's changed row addresses
twice. Lengths separate the variable-sized fields, and destructuring
makes a new field a compile error until it is added to the digest.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 30, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 30, 2026
BubbleCal added a commit that referenced this pull request Nov 3, 2026
FRI changes currently invalidate native RaBitQ plane and code-only
entries even though their files have not changed. Give immutable entries
a physical-file namespace shared by opens and shallow clones in the same
cache pool. Keep translated partitions and prefilter state in the
existing dataset/FRI namespace.

Cache candidate address views separately, preserving physical slots and
tombstones. These RAM-only entries own and charge only their address
buffers. Fresh opens, cached reconstruction, prewarm, code-only reads
and the scan extension use the same boundaries. Address diagnostics
report cache hits (including coalesced loads), loader misses, translated
slots and elapsed loader time.

The additive storage builder binds a cache already scoped to the
immutable file and current translation:

```rust
let storage = storage.with_row_address_cache(translated_file_cache);
let sign = storage
    .load_sign_stage(partition_id, &raw_file_cache, io_stats)
    .await?;
```

Part of [OSS-2841](https://linear.app/lancedb/issue/OSS-2841). This
reuses the existing translation fingerprint;
[#10538](#10538) separately
narrows v0 invalidation. No on-disk index format or production
dependency pin changes.

The benchmark consumer's performance acceptance remains open: the
existing Sophon resident-to-eager shortcut produces a concurrent
regression in this fixture despite reduced origin I/O.
[OSS-2844](https://linear.app/lancedb/issue/OSS-2844) already requires
resident/whole/sparse routes to share the address view. Keep this
consumer-integration finding visible in review; default-path production
acceptance remains gated on OSS-2844.

A separate benchmark-only Sophon ablation removed just the per-probe
resident shortcut, keeping this Lance head unchanged. All 4,548
diagnostic results matched Full and `eager_resident` was zero. The first
frozen 1,024 queries' mean latency fell from 733.76 ms to 146.43 ms. Its
overall 75.50 QPS spans repeated cycles over 60.24 seconds and is not
included in the formal PR comparison below. This supports the
routing-policy interaction; it does not isolate remapping, repacking and
scoring costs individually. The query-level all-resident fallback
remains a separate OSS-2844 acceptance case.

| Scenario / metric | Baseline | This PR | Benefit |
| --- | ---: | ---: | ---: |
| No FRI, c1, QPS (higher is better) | 5.60 queries/s | 5.42 queries/s |
1.03x slowdown |
| FRI transition, c1, QPS (higher is better) | 2.95 queries/s | 3.67
queries/s | 1.24x throughput |
| FRI transition, c8, QPS (higher is better) | 12.70 queries/s | 10.89
queries/s | 1.17x slowdown |
| FRI transition, c1, S3 read bytes/query (lower is better) | 15.20
MB/query | 12.02 MB/query | 1.26x less origin I/O |
| FRI transition, c1, disk-cache read bytes/query (lower is better) |
6.24 MB/query | 8.33 MB/query | 1.34x more disk I/O |
| FRI transition, c8, S3 read bytes/query (lower is better) | 15.56
MB/query | 11.97 MB/query | 1.30x less origin I/O |
| FRI transition, c8, disk-cache read bytes/query (lower is better) |
5.98 MB/query | 8.07 MB/query | 1.35x more disk I/O |

These are single-process observations for each arm/scenario, without
confidence intervals. Baseline is direct parent
`1b8e2426a69a589a9bf4309f7218b8ee914105c0`; candidate is
`e75d3685fa2259633cb0b178b19caefec623d867`. The no-FRI throughput
decrease and FRI c8 regression are retained.

Environment/workload: c7i.8xlarge in us-east-1a, pinned to 8 physical
cores, 350 GiB gp3 at 8,000 IOPS/1,000 MiB/s (not instance-store NVMe);
RAM and disk cache each 7,006,754,887 bytes. Frozen Coyo has 15,380,795
rows × 2,048 float32 dimensions, a shared native 7-bit cosine index with
4,096 partitions, k=100 and nprobes=64. Each phase covers the frozen
1,024 queries and at least 60 seconds, then drains. A fresh
process/cache prewarms snapshot 2, runs 32 warm queries, then checks out
snapshot 4 in the same session for transition cases. Prewarm and
snapshot checkout are excluded from query timing; the first measured
query opens/uses the new index view. The local mirror is disabled for
warm and timed queries. Both arms use the same index/model and Full
references; no historical benchmark comparison is claimed.

The benchmark-only fixture is Sophon #9381 at
`12ccd06400b49c226ac3a92c2906141fb9664007`, LanceDB
`d5013459eb4c7beb84d80bc2c26720d58f347611`, Rust 1.97.1,
`release-with-debug`, identical lockfile and harness. Exact archive
contents and built binary hashes were verified. This is not production
adoption.

All 6,144 measured results matched the Full reference's row IDs and
distance bits. Recall@100 was 0.97376953125; RAM/disk/S3, error and
runtime address-counter gates passed. In the c8 candidate, the address
cache recorded 19,490 hits and 7,955 loader misses. Cache-accounted
bytes remained about 7.00 GB in both FRI arms; end-of-run RSS was
8.24→8.03 GB at c1 and 8.88→8.86 GB at c8. RSS and lifetime high-water
marks are distinct from cache charging; no general memory reduction is
claimed.

Validation on the exact PR head: 51 native tests passed, including
v0/tagged FRI × resident on/off, two compactions, old snapshots, clone
divergence, eager-result parity, refinement and controlled partition
streams. Formatting, full workspace Clippy and all applicable CI checks
passed (38 success, 2 skipped).

Cache namespaces change on adoption, so persistent entries repopulate
under the new keys. Address views compete for the same cache budget.
Production Sophon integration remains released upstream → internal-fork
synchronization → separate dependency adoption and integrated
acceptance.
A segment whose coverage is disjoint from the reuse history was given the
plain cache namespace, on the assumption that the remapper leaves its rows
unchanged. Deferred overlay compaction withdraws rewritten fragments from a
stale index's coverage while the index data still holds their rows, which
the remapper translates on decode. Warming the latest snapshot then cached
translated pages under the key an older snapshot reads, and indexed queries
on that snapshot dropped matches.

Key each segment by every version it was not built after, ignoring
coverage disjointness. The trim gate keeps accepting disjoint coverage; the
shared version-and-coverage check moves into index_postdates_rewrite.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 3, 2026
@xuanyu-z xuanyu-z changed the title perf(index): scope v0 fragment reuse cache keys to each segment perf(index): key v0 fragment reuse cache entries by the versions each segment predates Nov 3, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 3, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 3, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

The generic open's vector-cache probe resolved the segment's remapping to
build its per-segment key, and on a hit the open path resolved it again. A
probe under the whole-history key misses instead, and the open path finds
the entry under the segment's own key, so the probe keeps main's form.

The warm-through-trim test now opens the vector segment through the generic
open and checks a second open of every segment loads nothing.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 9, 2026
Hash each version's protobuf encoding instead of a hand-rolled digest
(the encoding covers every field, so the field-coverage test goes), reuse
the fragment reuse test fixtures, fold the overlay regression into the
existing deferred overlay compaction test, and shorten comments.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 9, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 9, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 9, 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.

The verified cache reuse across eligible trims and historical-query isolation are preserved. New compactions still rekey older segments.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 9, 2026
@wjones127
wjones127 self-requested a review November 10, 2026 06:51
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 10, 2026
@Xuanwo
Xuanwo merged commit a2615db into lance-format:main Nov 10, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants