Repository navigation
perf: assemble stable-row-id prefilter allow lists from cached per-fragment pieces - #8880
JaySon-Huang wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The content-keyed per-fragment cache is a sound reuse boundary, but piece construction must preserve the existing async/CPU separation. Load row IDs and deletion vectors asynchronously, then run the clone, deletion masking, and tree construction for each miss on spawn_cpu; the final merge can remain on the CPU pool.
…agment pieces do_create_deletion_mask_row_id builds a whole-dataset allow list by loading every fragment's row id sequence and deletion vector, so the cost is proportional to the dataset size rather than to what changed. The result is cached under (manifest version, restrict set), which amortizes less than it looks: every commit invalidates the entry, distinct restrict sets each pay their own full rebuild, and the resident mask scales with the dataset. Assemble the allow list from per-fragment pieces instead. Each piece is one fragment's live stable row ids (row id sequence minus deletion vector), cached under its content identity: the row id generation (the same identity RowIdSequenceKey uses for generation-safe sequence caching) plus the deletion file identity. Pieces are OR-ed into the requested mask: - commits that leave a fragment's row ids and deletions untouched keep its piece warm, so a post-commit rebuild only reloads touched fragments - overlapping restrict sets share pieces instead of reloading them - content is unchanged: a piece is exactly what the old fold OR-ed in for that fragment, and missing fragments contribute nothing The whole-mask cache under (version, restrict_hash) is kept, so repeated identical queries still hit it unchanged.
a32381b to
1647231
Compare
Loading a fragment's row id sequence and deletion vector stays async, but the sequence clone, deletion masking and tree construction for each piece are CPU-bound and were running inline on the async runtime. Move them into spawn_cpu, matching the whole-mask fold's original async/CPU separation while keeping the per-piece pipelining: each piece loads on the IO path and builds on the CPU pool independently, so IO of one piece overlaps CPU of another. The final merge stays on the CPU pool.
wjones127
left a comment
There was a problem hiding this comment.
This is a good fix, but the test needs some improvement to show what it is claiming.
| // The allow list is assembled from per-fragment pieces cached by content | ||
| // identity (row id generation + deletion file). A commit that deletes rows | ||
| // must invalidate exactly the touched fragments' pieces: a mask rebuilt in | ||
| // the same session must reflect the new deletions while untouched | ||
| // fragments are served from cache. | ||
| #[tokio::test] | ||
| async fn test_row_id_allow_list_pieces_invalidate_on_new_deletions() { |
There was a problem hiding this comment.
issue(blocking): the test claims that "while untouched fragments are served from cache", but that isn't asserted. Could you use the assert_io_eq!() macro to assert the amount of IO each of the operations does, and thus prove that caching is happening?
There was a problem hiding this comment.
Addressed in 0c0698e222980708f1a788bf5325838799680b76. The focused regression now creates a real RowIdMeta::Column fragment with an inline deletion vector, proves the cold build performs storage reads, and then asserts the restricted rebuild performs read_iops == 0 with an exact metadata-cache delta of one piece hit and one composed-mask miss while the RowIdSequenceKey and DeletionFileKey entries remain resident. A subsequent unrelated commit reuses the same piece with zero reads. Could you take another look?
…anwo/pr-8880-merge-20261101 # Conflicts: # rust/lance/src/index/prefilter.rs
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The added I/O and cache-counter assertions demonstrate reuse across restrictions and commits, addressing the cache-reuse test request. The prefilter and cache-identity tests pass. The merged implementation preserves restricted-mask semantics and CPU-pool separation while accounting for spilled lineage files and inline deletion payloads.
wjones127
left a comment
There was a problem hiding this comment.
Thanks for the update. The new test counts reads and cache hits/misses, so it shows the reuse directly, which is what I asked for.
I'm holding off on approving the piece cache for now. We're planning to move indices to the address domain (#10960), which removes the need for this allow list, so I'd like a benchmark showing the cache is worth it in the meantime. I also left a question about sharing the fragment row-id identity with #10800, and a note on the DeletionFileKey identity change.
| pub deletion_file: &'a DeletionFile, | ||
| } | ||
|
|
||
| fn write_deletion_file_identity(builder: &mut KeyBuilder, deletion_file: &DeletionFile) { |
| dataset | ||
| .metadata_cache | ||
| .as_ref() | ||
| .get_or_insert_with_key(piece_key, || { |
There was a problem hiding this comment.
question: Our plan is to move indices to the address domain (#10960). Once they return row addresses, the prefilter only needs a block list of deleted addresses, like the non-stable-row-id path, so this whole-dataset allow list goes away for index search. merge_insert reaches it through the BTREE join-key lookup (#6877), so that use goes away too.
Given that, I'd want a benchmark showing a meaningful interim win before we add another cache layer here. The row-id sequence and deletion vector are already cached under RowIdSequenceKey/DeletionFileKey, so on a warm session a piece hit only saves the clone + mask + RowAddrTreeMap::from per fragment, and the final OR is still O(live rows).
Could you share before/after numbers for the case this targets: the first prefiltered query after a small commit on a large stable-row-id table?
| pub lineage_file: Option<&'a DataFile>, | ||
| } | ||
|
|
||
| fn write_row_id_identity( |
There was a problem hiding this comment.
question: #10800 also keys per-fragment row-id state by row-id source + deletion identity, but builds that identity differently. On top of the RowIdSequenceKey bytes it adds physical_rows, the resolved base path, and the row-id column index:
lance/rust/lance/src/dataset/rowids/cache.rs
Lines 192 to 206 in b5ee153
The base-path part comes from its keys living in the root namespace rather than the dataset-prefixed cache. The column index and physical_rows aren't explained by that, though. If they're needed there, are they needed here, and in RowIdSequenceKey? If not, could both PRs use this write_row_id_identity helper, so there is one definition of a fragment's row-id identity?
| } else { | ||
| builder.write_none(); | ||
| } | ||
| if let Some(inline) = &deletion_file.inline { |
There was a problem hiding this comment.
suggestion: This changes the identity of the existing DeletionFileKey (and bumps its schema), not only the new piece key. #10800 independently adds the inline payload to its deletion identity too:
lance/rust/lance/src/dataset/rowids/cache.rs
Lines 111 to 123 in b5ee153
So two inline deletion files with the same (read_version, id, type) and different bytes look like a real case. Could the description call this out as a fix to the deletion-vector cache? Once this lands, #10800's extra inline write becomes redundant.
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 - Exact-head `e91aafecd` CI passes across all applicable checks (37 succeeded, 4 conditionally skipped, 0 failed): [Rust/Clippy/MSRV/ARM](https://github.com/lance-format/lance/actions/runs/44933829515), [Python](https://github.com/lance-format/lance/actions/runs/44933829441), and [Java 11/17/21/25](https://github.com/lance-format/lance/actions/runs/44933829393). - New unit tests in `rust/lance/src/dataset/rowids/group.rs` verify dense group cross-snapshot reuse (updates, deletes, time-travel), disjoint-fragment bypass, heavy-deletion/small-cache fallback, and `index_cache` eviction release. - Benchmark helper & configs are checked in at [benchmarks/row-id-cache](https://github.com/lance-format/lance/tree/e91aafecdeb12185d88d05350a11a7831b02c72b/benchmarks/row-id-cache). - Follow-ups noted (non-blocking): common metadata-cache deletion key ownership with #8880, and coexistence of complete and fragment representations with #11012.
Fixes #8849 (assembled-from-pieces variant; see the issue for the whole-dataset allow-list cost analysis)
Problem
DatasetPreFilter::do_create_deletion_mask_row_idbuilds a whole-dataset allow list by loading every fragment'sRowIdSequenceand deletion vector and folding them into oneRowAddrTreeMap. The cost is proportional to the dataset size, not to what changed. The whole mask is cached under(manifest version, restrict_hash), which amortizes less than it looks:restrict_tosets get distinct cache entries, so a workload with varying fragment restrictions rebuilds repeatedly at the same version;Change
Assemble the allow list from per-fragment pieces. Each piece is one fragment's live stable row ids (row id sequence minus deletion vector, exactly what the old fold OR-ed in for that fragment), cached in the dataset metadata cache under its content identity:
RowIdSequenceKey: the inline digest, or the lineage data file'spath/base_idforRowIdMeta::Column;Pieces are fetched concurrently and OR-ed on a blocking thread. The whole-mask cache under
(version, restrict_hash)is kept, so repeated identical queries still hit it unchanged.restrict_tosets share pieces instead of reloading them.Correctness
A piece's content is fully determined by its key identity: any change to a fragment's row ids or deletions changes
row_id_metaor the deletion file identity, so a stale piece cannot be served.mask(F) = OR(pieces(F ∩ manifest))is identical to the old restricted fold (#6563/#6877 semantics preserved).Tests: the existing prefilter mask tests (including the #6877 regression test) pass unchanged. Regression coverage now includes cross-commit invalidation, multi-fragment restrictions, spilled
RowIdMeta::Columnlineage, inline deletion vectors, and typed cache/I/O evidence. The cache test warms the underlying row-id and deletion caches, then verifies that a restricted rebuild performs zero reads and records exactly one piece-cache hit plus one miss for the newly composed mask. A subsequent commit that leaves that fragment untouched reuses the piece without I/O.Performance
No wall-time benchmark was rerun for the integrated head. The original PR described an author-reported local NVMe benchmark from an earlier revision, but the measured commit and harness are not identified here, so those numbers are omitted. The cache/I/O regression verifies behavior, not throughput.
Cost and scope
The final composition still ORs the selected pieces and remains O(dataset live rows); this change does not make a full allow-list build proportional only to the restriction. Pieces and composed masks may both remain resident in the existing metadata-cache budget.
The piece cache avoids rebuilding each fragment's live-row set and avoids repeated
RowIdSequenceKey/DeletionFileKeylookups. When those underlying caches are already warm, the previous path could also avoid storage I/O. This change therefore does not universally reduce object-store round trips; it can avoid lower-tier loads when those caches are cold, evicted, or contended.Notes / follow-ups
FilterLoadercurrently does not expose fragment coverage.