Repository navigation
perf(rowids): reuse prepared fragments across snapshots - #10800
Conversation
80b8bf4 to
b2b38d4
Compare
There was a problem hiding this comment.
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.
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.
23acecc to
588903f
Compare
wjones127
left a comment
There was a problem hiding this comment.
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.
| /// Without them, only overlapping ID spans require deletion files to | ||
| /// disambiguate copies produced by updates. |
There was a problem hiding this comment.
question: why do we cache without knowing the deleted rows? Should we just switch to always knowing deletions when we cache?
| self.with_deletions, | ||
| self.e_tag.unwrap_or("") | ||
| )) | ||
| Cow::Owned(format!("row_id_index/current/{}", self.with_deletions)) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
## 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.
All review items addressed at latest head (1e05cd0): matched benchmarks and pruning ablation passed, CI green, Gatekeeper and Xuanwo approved.
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-freeMergedSourceGroupis built via bounded streaming parallel scatter (Vec<AtomicU64>+ collisionoverflow, without retaining duplicate per-fragment copies) and shared across snapshots through a lightweight weak-referencedSnapshotRowIdRoutekeyed 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 assmall-cacheat 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
e91aafecdvsmain(e03f5e2f9)Measured on a managed Linux VM (
c4-standard-32, Intel Xeon Platinum 8581C, 32 vCPU, 117 GiB RAM, cgroup v2, swap 0 B, Rust1.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-inbenchmarks/row-id-cache/harness.rs, identical immutable dataset versions and independently scanned oracles, 1 GiB metadata cache, and 4 GiB index cache (128 MiB forsmall-cache). Values average two fresh processes in reversed arm order.End-to-end
take_rows(lower is better)main(e03f5e2f9)e91aafecd)headvsmainno-deleteswarm p50 (4 GiB, 32 warm)no-deletespeak RSSsmall-updates7 snaps / 56 takes (8 GiB)small-updatespeak RSSheavy-deletes0–91%, 56 takes (8 GiB)heavy-deletespeak RSSsmall-cache(128 MiB, 91% del, 32 warm, 4 GiB)default-compacted7 snaps / 56 takes (8 GiB)mainOOMs;headcompletes cleanlyIsolated
resolve_row_ids(lower is better)main(e03f5e2f9, matched 4 GiB)e91aafecd, matched 4 GiB)headvsmainno-deletes(1000-way overlap, 0 del, 32 warm)small-updates7 snaps / 56 callsmainOOMs;headreuses 1 shared group across all 7 snapshotsheavy-deletes0–91%, 7 snaps / 56 callsmainOOMs;headreuses 1 shared group across all 7 snapshotssmall-cache(128 MiB, 91% del, 64 IDs, 32 warm)default-compacted7 snaps / 56 callsmainOOMs;headcompletes cleanlyAdmission, fallback & pruning ablation
2539067ab): Onsmall-cache(128 MiB index cache, 91% deleted), removing pruning (head-unpruned) caused 11.3 GiB of warm cloud reads and degraded warmtake_rowsto 1387.6 ms (8.7x slower thanmain) and warm resolver to 1058.8 ms (31.6x slower thanmain). Ate91aafecd, the cache-capacity and live-density gates automatically bypassMergedSourceGrouponsmall-cache, retaining pruned per-fragment caching (103.5 MiB charged, 0 warm reads, 7.44x faster warm resolver and 1.20x faster warm take thanmain).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.headcompletes all 56 calls in 4.22 s (0.143 ms warm resolver) and 63.68 s full take whilemainOOM-kills at both 4 GiB and 8 GiB.SnapshotRowIdRouteholds only aWeak<MergedSourceGroup>and accessesMergedRowIdGroupKeythroughindex_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 invokeget_row_id_index.Validation & CI
e91aafecdCI passes across all applicable checks (37 succeeded, 4 conditionally skipped, 0 failed): Rust/Clippy/MSRV/ARM, Python, and Java 11/17/21/25.rust/lance/src/dataset/rowids/group.rsverify dense group cross-snapshot reuse (updates, deletes, time-travel), disjoint-fragment bypass, heavy-deletion/small-cache fallback, andindex_cacheeviction release.