Skip to content

perf(rowids): reuse prepared fragments across snapshots - #10800

Merged
BubbleCal merged 40 commits into
mainfrom
yang/rowid-cross-version-reuse
Dec 1, 2026
Merged

BubbleCal merged 40 commits into
mainfrom
yang/rowid-cross-version-reuse

Conversation

@BubbleCal

@BubbleCal BubbleCal commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Cache stable-row-ID lookups per immutable fragment so append and snapshot changes reuse unchanged work. Lookup mappings and snapshot deletion visibility are charged separately. Sparse per-fragment mappings rebuild when deletions remove at least half of the retained rows; compact range mappings stay reusable, and pruned mappings are reused only when they cover the requested snapshot. Batched sparse lookups use interleaved search while preserving physical addresses, input order, duplicates and deletion visibility.

When more than 64 non-range fragments overlap in row-ID space (verified by a 64-fragment stride sample) and the snapshot satisfies cache-capacity (<=75% of index_cache) and live-density (>=50% live) gates, a single deletion-free MergedSourceGroup is built via bounded streaming parallel scatter (Vec<AtomicU64> + collision overflow, without retaining duplicate per-fragment copies) and shared across snapshots through a lightweight weak-referenced SnapshotRowIdRoute keyed by (version, e_tag). Deletions and incremental appends reuse the same shared group while filtering only hit-fragment deletions and probing the small uncovered delta. Heavily deleted cold snapshots under tight caches (such as small-cache at 128 MiB / 91% deleted), disjoint fragments, and compact range fragments bypass group merging and retain the pruned per-fragment path. Persisted formats are unchanged.

Matched e91aafecd vs main (e03f5e2f9)

Measured on a managed Linux VM (c4-standard-32, Intel Xeon Platinum 8581C, 32 vCPU, 117 GiB RAM, cgroup v2, swap 0 B, Rust 1.98.1, release-with-debug) against identical immutable datasets in regional GCS (us-central1, 100M shuffled/spilled row IDs, 1000 initial fragments, five UInt64 columns, 1000-way fragment span overlap). Both arms use the checked-in benchmarks/row-id-cache/harness.rs, identical immutable dataset versions and independently scanned oracles, 1 GiB metadata cache, and 4 GiB index cache (128 MiB for small-cache). Values average two fresh processes in reversed arm order.

End-to-end take_rows (lower is better)

Scenario (budget) main (e03f5e2f9) PR head (e91aafecd) head vs main
no-deletes warm p50 (4 GiB, 32 warm) 1455.9 ms (cold 14.78 s) 1655.4 ms (cold 6.79 s) 2.18x faster cold, +13.7% warm (GCS I/O variance on 160k identical reads; resolver is 2.44x faster)
no-deletes peak RSS 3.558 GiB 0.957 GiB 3.7x lower peak RSS
small-updates 7 snaps / 56 takes (8 GiB) 263.12 s (warm 1801.0 ms) 99.57 s (warm 1264.1 ms) 2.64x faster total, 1.42x faster warm
small-updates peak RSS 7.465 GiB 0.931 GiB 8.0x lower peak RSS
heavy-deletes 0–91%, 56 takes (8 GiB) 159.79 s (warm 1798.7 ms) 89.16 s (warm 1225.9 ms) 1.79x faster total, 1.47x faster warm
heavy-deletes peak RSS 4.122 GiB 1.038 GiB 4.0x lower peak RSS
small-cache (128 MiB, 91% del, 32 warm, 4 GiB) 145.6 ms (cold 4.51 s, 0.804 GiB) 121.3 ms (cold 2.23 s, 0.251 GiB) 1.20x faster warm, 2.03x faster cold, 3.2x lower RSS
default-compacted 7 snaps / 56 takes (8 GiB) OOM-kill (>8 GiB) 63.68 s (warm 742.7 ms, 2.039 GiB) main OOMs; head completes cleanly

Isolated resolve_row_ids (lower is better)

Scenario (budget) main (e03f5e2f9, matched 4 GiB) PR head (e91aafecd, matched 4 GiB) head vs main
no-deletes (1000-way overlap, 0 del, 32 warm) cold 9636.9 ms / warm 0.0205 ms (3.560 GiB) cold 1844.7 ms / warm 0.0084 ms (0.891 GiB) 2.44x faster warm, 5.22x faster cold, 4.0x lower RSS
small-updates 7 snaps / 56 calls OOM-kill (>4 GiB) 2.34 s / warm 0.1673 ms (0.887 GiB) main OOMs; head reuses 1 shared group across all 7 snapshots
heavy-deletes 0–91%, 7 snaps / 56 calls OOM-kill (>4 GiB) 3.86 s / warm 0.6503 ms (0.921 GiB) main OOMs; head reuses 1 shared group across all 7 snapshots
small-cache (128 MiB, 91% del, 64 IDs, 32 warm) cold 5277.0 ms / warm 34.50 ms (0.796 GiB) cold 1937.0 ms / warm 4.63 ms (0.227 GiB) 7.44x faster warm, 2.72x faster cold, 3.5x lower RSS
default-compacted 7 snaps / 56 calls OOM-kill (>4 GiB) 4.22 s / warm 0.1434 ms (1.965 GiB) main OOMs; head completes cleanly

Admission, fallback & pruning ablation

  • Pruning under cache pressure (prior 3-arm ablation at 2539067ab): On small-cache (128 MiB index cache, 91% deleted), removing pruning (head-unpruned) caused 11.3 GiB of warm cloud reads and degraded warm take_rows to 1387.6 ms (8.7x slower than main) and warm resolver to 1058.8 ms (31.6x slower than main). At e91aafecd, the cache-capacity and live-density gates automatically bypass MergedSourceGroup on small-cache, retaining pruned per-fragment caching (103.5 MiB charged, 0 warm reads, 7.44x faster warm resolver and 1.20x faster warm take than main).
  • Default-compaction lifecycle (CompactionOptions::default()): 1000 mixed-deletion fragments (0/5/9/25/75% deleted) compacted to 72 fragments with 0% deletions, followed by 5 steady update/delete rounds. head completes all 56 calls in 4.22 s (0.143 ms warm resolver) and 63.68 s full take while main OOM-kills at both 4 GiB and 8 GiB.
  • Admission & eviction safety: SnapshotRowIdRoute holds only a Weak<MergedSourceGroup> and accesses MergedRowIdGroupKey through index_cache, so evicted groups are never retained; single-flight per-group locks coalesce concurrent cold builds. Disjoint spilled fragments and compact inline range fragments remain on the per-fragment path without allocating a merged table. Allow memory headroom for cold preparation and coexisting complete/fragment/merged lookups when callers also invoke get_row_id_index.

Validation & CI

@BubbleCal
BubbleCal force-pushed the yang/rowid-cross-version-reuse branch from 80b8bf4 to b2b38d4 Compare November 6, 2026 15:50
@BubbleCal BubbleCal changed the title perf(rowids): reuse unchanged fragments across snapshots perf(rowids): cache fragment lookups across snapshots Nov 6, 2026
@BubbleCal
BubbleCal marked this pull request as ready for review November 6, 2026 17:20

@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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

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 Nov 6, 2026
BubbleCal added a commit that referenced this pull request Nov 9, 2026
Shuffled stable row IDs retain both their source arrays and a padded
inverse mapping. When the resulting RowIdIndex cannot enter the cache,
small requests reconstruct the complete map. This change compacts the
prepared representation and allows verified unchanged fragments to share
lookup data across snapshots and independently cached units.

- Use bitmap/rank offsets for dense IDs, packed relative-ID/offset words
for narrower sparse IDs, and 12-byte entries for wide IDs. Release
redundant source arrays and skip inverse preparation when the existing
cost model selects merging.
- Share immutable prepared fragments and merged chunks through
`new_reusing` and `try_reuse_fragments`. The caller verifies content,
deletion and physical-address identity; partial merged groups or
representation changes retain an explicit rebuild fallback.
- Add `try_combine` to compose independently prepared probe indices
after original arrays are released. It shares prepared allocations,
rebuilds routing metadata, rejects duplicate fragment namespaces and
preserves the global probe/merge cost gate. Merged or mixed inputs
return `None` for the caller to rebuild. It never retains the input
indices themselves.
- Keep `FragmentRowIdIndex::get_many` available for explicit direct
lookup of native encodings. Dataset loading and prepared-fragment cache
admission are integrated in #10800; this core API does not provide
routing metadata for unknown spilled candidates.

Shared allocations are counted once per DeepSizeOf context. No on-disk
format change.

Validation on this source:

- 64 RowIdIndex tests passed, including independent physical-offset
expectations, deletion and duplicate cases, released original arrays,
input-index lifetimes, shared accounting and the 64-to-65 overlap
fallback.
- All four row-ID API doctests passed.
- `cargo fmt --all` and `git diff --check` passed.
- Full workspace `cargo clippy --profile ci --all --tests --benches --
-D warnings` passed with pinned Rust 1.98.1.

Combined acceptance with #10800 at
`23aceccd1fe83a44ba48b3d52028b264ef2803e8` is complete; its five core
files match this PR at `7786af74faca4103f801cce0d929b336c04b6ebe`. The
integration passed 116 row-ID tests (including 11 resolver cases), 56
take tests, 6 compaction tests, the cache-key test and full workspace
Clippy. Real-S3 validation covered 34 matched jobs with equal cache and
process-memory limits, verified executable/source identities and
independent row-address/payload oracles. Every current arm completed;
the sole OOM was the core-only parent while retaining an old reader
during 300M-row append under a 4 GiB cap. The current arm completed once
with a cgroup peak near that cap, so this is a feasibility observation,
not an arbitrary-input memory guarantee.

The loader now caches prepared fragment indices rather than individual
ID answers. #10800 reports the current child-versus-this-core-parent
measurements, including improved cold/distinct-ID and append behavior,
cache-pressure behavior, and regressions in warm high-fragment-count and
point-to-bulk workloads. `try_combine` deliberately rejects merged/mixed
or cost-rejected unions; the loader then rereads/rebuilds. Unknown
overlapping spilled candidates still require inspection. Earlier
core-only measurements apply to `e3d3a2869`, not this complete head; no
current-head core-only speedup is claimed here.

Separate S3 mutation checks validated update, deleted IDs, missing IDs
and retained snapshots on the same product source. The fixture's hidden
persistent-row-ID index metadata prevented UpdateBuilder discovery on
both parent and current; the mutation helper removed that metadata only
on an owned shallow clone. This does not validate coexistence with that
persistent index or modify the retained input dataset. No BTree
performance claim is made.
Base automatically changed from yang/rowid-bounded-memory to main November 9, 2026 10:53
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 9, 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 Nov 9, 2026
@BubbleCal
BubbleCal marked this pull request as draft November 10, 2026 16:56
@BubbleCal
BubbleCal force-pushed the yang/rowid-cross-version-reuse branch from 23acecc to 588903f Compare November 10, 2026 16:56
@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 10, 2026

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

Thanks for this. Content-addressing the per-fragment units is a sound way to reuse work across snapshots. The tests are strong: the fixtures check results against oracles computed from the fixture's own arithmetic, and they cover duplicates, deletions, eviction, admission rejection and old snapshots. The append result (8s to 39ms for old-key takes) is a real win.

Blocking: the single current entry means handles on different versions evict each other's view, and that likely forces full rebuilds when a delete lands between them. I've suggested a way around it inline: cache only the parts, and make the per-version view lightweight.

Also, could you trim the PR description? It will become the commit message. It references local paths (/Users/yang/Documents/Codex/...) and internal terms ("frozen v7", "mbx", "wake9", rejected v4/v5) that won't mean anything to future readers. A short paragraph on the design (three tiers: complete view, prepared fragment units, span metadata) plus the benchmark table would be enough.

Comment thread rust/lance/src/session/index_caches.rs Outdated
Comment on lines +102 to +103
/// Without them, only overlapping ID spans require deletion files to
/// disambiguate copies produced by updates.

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.

question: why do we cache without knowing the deleted rows? Should we just switch to always knowing deletions when we cache?

Comment thread rust/lance/src/session/index_caches.rs Outdated
self.with_deletions,
self.e_tag.unwrap_or("")
))
Cow::Owned(format!("row_id_index/current/{}", self.with_deletions))

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.

question(blocking): With one current entry per dataset, two handles on different versions keep evicting each other's view. The PR's own numbers show old-snapshot revisit going 0.002 ms -> 2.1 ms in the append case. If a delete lands between the versions, reuse_merged can't keep the changed group, so build() reloads every fragment's sequence on each alternation. Why one entry rather than per-version entries that share the prepared allocations? To clear this: either keep per-version keys with shared allocations, or add a test where two handles alternate across a delete and assert bounded read_bytes on the second round trip. One way to unblock this is the suggestion on resolve.rs:535: if the per-version view didn't own the shared allocations, per-version entries would be cheap.

.session()
.row_id_index_builds
.for_dataset(&dataset.uri)?;
let guard = lock.lock().await;

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.

issue(non-blocking): When there is no complete view, every call takes this dataset-wide lock, including warm calls answered entirely from resident units. The lock is then held across the cold prepare_fragment reads below. A cold lookup on fragment A blocks an unrelated warm lookup on fragment B, which probably explains the C=4 regression in the description. Could the resident-hit pass run before taking the lock, with cold preparation deduplicated per fragment (e.g. get_or_insert_with_key on PreparedRowIdFragmentKey) instead of per dataset?

};
// LanceCache intentionally has no per-key remove. Metadata-only replacement
// releases matching prepared values without clearing unrelated cache entries.
for (key, cached) in retire {

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.

suggestion: The retirement pass (and, I think, the single current entry) exists because the complete view and the per-fragment units are both cache entries charged for the same shared allocations. Could we avoid the overlap instead? Cache only the parts — per-fragment units, plus merged chunks keyed by their source group — each charged once, and make the per-version view a lightweight value (probes/end_tree plus Arcs into the parts) charged only for its own overhead. That would remove the need to retire units (including the fallback case where they're retired but no view is admitted), and per-version entries would be cheap enough to avoid the thrashing above.

@BubbleCal BubbleCal changed the title perf(rowids): cache fragment lookups across snapshots perf(rowids): reuse prepared lookups across snapshots Nov 11, 2026
@BubbleCal
BubbleCal marked this pull request as ready for review November 11, 2026 11:45

@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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

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 Nov 11, 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 Nov 21, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 21, 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 Nov 21, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 21, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Nov 21, 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.

The matched e91aafec versus main results address the remaining performance acceptance condition. The largest reported warm-take regression is 13.7%, within the roughly 20% bound; the no-deletes warm resolver is 2.44× faster, and the tight-cache fallback retains the pruning benefit. This supersedes the earlier request for current-head measurements.

The cloud measurements remain author-reported, and warm latency remains workload dependent. Allow process-memory headroom beyond the cache budget for cold preparation and coexisting complete, fragment, and merged lookups. Use the observed warm-take cost when sizing latency-sensitive workloads.

@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 21, 2026
@BubbleCal
BubbleCal requested a review from wjones127 November 21, 2026 20:54
@lance-gatekeeper lance-gatekeeper Bot removed K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Nov 24, 2026
BubbleCal added a commit that referenced this pull request Nov 30, 2026
## Summary

Reuse deletion masks, stable row ID indices, and the point lookup range
cache when the object store supplies no manifest ETag. Use a lazy BLAKE3
fingerprint of the manifest row layout and deletion descriptors as a
separate cache namespace. Keep the URI, version, fragment subset, and
deletion mode in the cache identity. Reuse the published ETag or
memoized fingerprint only while the handle retains the bound manifest
instance. A replacement manifest gets a content-derived cache namespace.

This change is scoped to snapshot cache keys and leaves the row ID index
representation independent of #10800.

## Validation

- Exercise both ETag and fingerprint paths across same-URI table
recreation.
- Verify repeated calls share deletion masks and the row ID index
without an ETag.
- Cover a warmed RowIdIndex followed by cloning the handle and removing
the deletion descriptor. The original still hides the row, and the clone
resolves it at the same manifest version. Exercise both ETag and no-ETag
inputs.
- GitHub Actions validates the updated head `9b26be6d7`.
- On a dedicated GCP VM with 16 vCPUs and 62 GiB RAM, `2d2b107` and
`db02d4d` used 1,048,576 rows in 256 fragments with stable row IDs and
one deletion per fragment. A commit-handler shim suppressed the ETag.
Each arm ran two cold opens and 60 warm operation pairs.

| Warm operation p50 (lower is better) | Baseline `2d2b107` | Earlier
head `db02d4d` | Benefit |
| --- | ---: | ---: | ---: |
| Deletion mask | 0.781 ms | 0.00959 ms | 81.4x speedup |
| RowIdIndex lookup | 18.32 ms | 0.000871 ms | 21,033x speedup |

These times measure direct cache operations at the earlier head.
First-call RowIdIndex construction remained near 18 ms per arm. The
updated head still needs cgroup-paired performance validation. Recheck
shared row ID lookup paths if #10800 lands first.
@BubbleCal
BubbleCal dismissed wjones127’s stale review December 1, 2026 08:38

All review items addressed at latest head (1e05cd0): matched benchmarks and pruning ablation passed, CI green, Gatekeeper and Xuanwo approved.

@BubbleCal
BubbleCal merged commit f4f066d into main Dec 1, 2026
40 checks passed
@BubbleCal
BubbleCal deleted the yang/rowid-cross-version-reuse branch December 1, 2026 08:39
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.

3 participants