Repository navigation
perf(index): preserve raw RaBitQ caches across FRI changes - #10642
Conversation
b53cb0e to
e75d368
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.
There was a problem hiding this comment.
The cache change can land independently, while consumer adoption retains a performance risk: the reported FRI-transition benchmark drops from 12.70 to 10.89 queries/s at concurrency 8 despite lower S3 traffic. Those single-process observations do not establish an end-to-end throughput win.
Keep production adoption gated on integrated validation of the resident, whole-partition, and sparse routes under concurrency. I could not independently reproduce the private consumer benchmark.
Native RaBitQ Full/Accurate scoring with the `Planes` cache layout now combines the translated sign/address view used by sparse reads with immutable whole ex planes, avoiding full-partition address remapping and code repacking. File offsets, tombstones, filtering, refinement budgets, full-bit scoring and phase timers are preserved. `Partition` layouts retain their ordinary reader so preparation consumes the same entries as prewarm; Fast and unsupported encodings also retain their existing readers. Public method signatures and the on-disk format are unchanged. Targets `main` after [#10642](#10642) merged as `b4ad45c29f91ed4612f712584d1bf84322c530dd`. Current head: `5dbf7b3924e998f734d8c97c1ce904d91dcd8824`. This is the whole-scoring slice of [OSS-2844](https://linear.app/lancedb/issue/OSS-2844/featindex-make-lazy-full-the-normal-rabitq-execution-path); companion consumer routing is [lancedb/sophon#9631](lancedb/sophon#9631). Validation at `5dbf7b3924e998f734d8c97c1ce904d91dcd8824`: the [prewarm reproducer](#10677 (comment)) failed on parent `2298c5bb36f4844d5631cab3baf08f8402586ab5` with 34,888 extra bytes after prewarm, while the ordinary reader read zero. Both Partition and Planes regression cases now read zero additional bytes and preserve exact results and recall >= 0.5. All 64 native scan cases passed in 0.67 seconds, including v0/tagged FRI, cold and prewarmed dense queries, filters, refinement and cache lifecycle coverage. Test strategies explicitly select Planes for the shared-view cases, matching enabled Sophon LazyQuery. Formatting, full workspace Clippy with warnings denied, and commit hooks passed. The retained performance evidence below measures the **original paired Lance + Sophon source graph**, not the isolated benefit of this PR. No S3 benchmark was rerun for the cache-layout fix; the original measured heads are listed below. This is not a new-head or production performance claim. | Scenario / metric | Measured baseline | Measured source pair | Observed benefit | | --- | ---: | ---: | ---: | | FRI c8, common first 1,024 queries, mean latency (lower is better) | 672.07 ms | 138.86 ms | 4.84x speedup | Coyo: 15,380,795 rows × 2,048 float32 dimensions, native RQ7 cosine, 4,096 partitions, k=100, fixed nprobes=64, snapshots 2→4 with the same index/model. The S3 fixture was `s3://mmlb-us-east-1/lazy-rq-cache-validation/t031-20261103/coyo-frozen.lance/`, index UUID `489f5190-d049-476e-b51e-d77ceecfb2b2`. Runs used c7i.8xlarge, eight fixed physical cores, 350 GiB gp3 at 8,000 IOPS / 1,000 MiB/s, and 7,006,754,887 bytes each for RAM and disk cache. Rust 1.97.1, `release-with-debug`; 32 warm queries; prewarm and snapshot checkout excluded. The index mirror was disabled for warm and timed queries. One process per arm, at least 60 seconds and one frozen 1,024-query cycle, then drain; no confidence interval. Whole windows completed 1,024 / 3,999 queries at 11.88 / 66.36 queries/s. Different repeat counts make that QPS ratio unsuitable as the matched benefit. All 5,023 results matched Full reference row IDs and distance bits; unique-query recall@100 was 0.97376953125. The candidate retained 168,803 resident probes, and address-view hits + loader misses covered all 255,936 probes. End charged cache was 6,998,555,318 → 6,986,044,894 bytes; end RSS was 8,791,830,528 → 8,545,579,008 bytes; lifetime HWM was 9,721,434,112 → 9,618,374,656 bytes and includes initialization. These are separate observations, not a general steady-state memory claim. The earlier cache-only c8 1.17x slowdown remains historical evidence; this targeted result does not complete integrated acceptance. <details> <summary>Exact source and artifact provenance</summary> - Lance direct parent `e75d3685fa2259633cb0b178b19caefec623d867` → `3e8578b6589a3fd90f2791c0a5a1bbd53e1feb8b`. - Sophon rabit_scan direct parent `0314932b2c19694adbdf2388aa7680ec6d35f18a` → `7da85323facecc9d71d83758dacd250319575d78`. - The experimental consumer graph used Sophon `12ccd06400b49c226ac3a92c2906141fb9664007` from the existing [#9381](lancedb/sophon#9381), LanceDB `d5013459eb4c7beb84d80bc2c26720d58f347611`, the stated Lance source, and only the stated Sophon rabit_scan subtree overlay. This is not a production dependency upgrade. - Cargo.lock SHA256: `4a51717d183fc2d82e90c66af808cf5a6e6c8bb32e76c78409823af3b41bd1a6`. - Harness SHA256: `7fb017d6620c1c0e18638cb96ff09ab1641d131f377cb01d35e8da7862a035ad`. - Baseline ELF SHA256: `7ff0a05ccfdd9f2623899937551b29490ec240a7425e8e5a476d92de9c661443`. - Candidate ELF SHA256: `d28e30267949753720032f24d0d224bcbdf32438a39d4b1cac279c0c3bf794f4`. - The 44-file `c8-implementation-evidence.tar.gz` archive has SHA256 `86ce4a89513f7a8d57a457070de17b533ef3b5063ba55ed941a32692f19e3f1c`. Source/build proofs, results, logs and preserved binary receipts are in the coordinator delivery package. </details> The coordinator will recheck current-head feedback, approval and CI before merge. Released upstream → internal-fork sync → separate compatible Sophon dependency adoption, and OSS-2845 / T-027 integrated acceptance remain separate gates. The seven missing-dependency assertions in the companion remain intact.
…0765) Cache completed partition row IDs and quantized distances for repeated opt-in IVF_RQ refinement queries in the existing session index cache. Hits skip candidate discovery and Accurate scoring; exact refinement and projections still execute independently. Entries are memory-only, own their result columns, and share the existing budget, admission policy and load coalescing. Keys bind dataset/store, manifest generation/branch, physical index identity, original vector bits, resolved controls, budgets, factors and bounds. The manifest binds coverage and FRI state; ranked results never cross snapshots. Vector bits and invariant controls are fingerprinted once per segment; partition keys add the partition ID and centroid-distance bits. Eligibility is limited to fully indexed single-vector flat IVF_RQ queries with a proven snapshot identity. Caller filters, explicit fragment/segment selections, external masks, and stale vector overlays bypass the result cache. Entries hold coarse candidates only: cross-column refinement ([#9127](#9127)) still reranks them with its own column, key, metric and final-space bounds, so distinct refinement inputs may share one coarse entry. Immutable index-data caches remain independent and reusable across queries and snapshots. No public signatures, options, dependencies, or persistent formats change. Part of [#8634](#8634). Builds on merged [#8741](#8741) and preserves [#10642](#10642 immutable-cache boundaries. SQ8 and shared batch execution remain separate PRs. Validation after merging `main` at `e602c45026ecace05081c880906615e6341ab713`: result-cache key/value/lifetime/admission/concurrency cases, the affected scanner ANN tests and the `io::exec::knn` tests pass, together with cross-column refinement's paired single/batch and quantized-coarse cases. One added case warms the coarse entry and then reranks with a different refinement key: the hit reuses the cached coarse candidates and still returns the uncached final rows, distances and final-space bounds. Coverage also includes row/distance-bit parity and recall, both row-ID schemes, multi-fragment updates/deletes/compactions and FRI changes, snapshots/clones/index replacement, normalization/key separation, pressure/zero capacity, concurrent loads/cancellation/failures, and buffer ownership. Tests distinguish fully indexed queries with original vector files removed from exact refinement and unindexed fallback reads. `cargo fmt --all -- --check` and full workspace `cargo clippy --all --tests --benches --profile ci --locked -- -D warnings` passed (one Cargo job; tests use `ci`). Local performance measured before rebase (`00c563668c7c33c0c66e7cc4cfd164f0d1fde8ee`): reuse the frozen 16,384 × 128 float32 dataset, IVF_RQ8/Fast rotation model, eight partitions/probes, k=10 and quantized factor=32. Test 0/1/5/10/20/100% evenly distributed hot-query occurrences; other vectors are distinct. Index budgets are 32/3/2 MiB, metadata budget 8 MiB, resident columns Auto and Off. Two rounds in both arm orders, 400 requests per arm, give 1,600 observations per arm/case and 115,200 timed queries overall. All matched independent uncached row IDs and exact distance bits; minimum recall@10 was 0.9. Warm traffic with default resident columns (Auto), 32 MiB index cache: | Repeats | p50 µs, uncached → cached | p95 µs | p99 µs | Timed QPS change | | ---: | ---: | ---: | ---: | ---: | | 0% | 901 → 938 | 944 → 994 | 998 → 1043 | -3.9% | | 1% | 907 → 935 | 954 → 982 | 999 → 1028 | -2.3% | | 5% | 909 → 933 | 954 → 999 | 1002 → 1039 | +0.3% | | 10% | 908 → 932 | 965 → 981 | 1007 → 1018 | +4.2% | | 20% | 906 → 928 | 961 → 997 | 1014 → 1239 | +9.1% | | 100% | 877 → 284 | 929 → 304 | 976 → 330 | +208.3% | Distinct-query median overhead remains about 4.0%. At 5% repetition, paired QPS changes span −0.8% to +0.7%; at 10%, +2.8% to +5.0%. The 20% throughput gain accompanies a 22% worse p99. Full repeats reach 3.1× throughput and reduce the index-comparison counter from 18,944/query to zero; IVF ranking/planning still execute. Origin reads are zero in both arms. Cache pressure with default resident columns: | Budget | Repeats | Origin KiB/query, uncached → cached | p95 µs | Timed QPS change | | ---: | ---: | ---: | ---: | ---: | | 3 MiB | 0% | 0.0 → 0.0 | 953 → 979 | -2.4% | | 3 MiB | 20% | 0.0 → 0.0 | 957 → 996 | +7.7% | | 3 MiB | 100% | 0.0 → 0.0 | 926 → 305 | +208.7% | | 2 MiB | 0% | 2125.5 → 2104.6 | 2161 → 2166 | -0.4% | | 2 MiB | 20% | 2135.2 → 2148.5 | 2120 → 2190 | -2.9% | | 2 MiB | 100% | 1725.7 → 1749.2 | 1747 → 1749 | -0.9% | At 3 MiB, native occupancy stays at 2,569,802 bytes in both arms; results reach 575,616 bytes with turnover and no extra reads. With resident columns Off, native data also stays resident at 3 MiB: QPS changes −3.1% at 0% repeats and +12.1% at 20%. At 2 MiB, native data does not fit in either arm and result hits are zero at every repeat rate. Results occupy <2.7 KiB. Auto origin bytes change −3.2% to +1.4%; Off bytes/requests are identical between arms. Across both modes, QPS changes −2.9% to +0.3%, with p95 up to 3.9% worse. Size removals include rejected candidates and evicted residents. Keep the existing admission policy based on this evidence; other workload/cache mixes still need evaluation. Uncached parity oracles are prepared in an independent session, then dropped before timing; validation performs no searches on timed sessions. Recall uses exhaustive original-vector L2 references. Timing covers planning/execution, excluding preparation, verification, diagnostics and logging. QPS uses summed timed durations. Sessions are prewarmed; OS cache stays warm. Per-round/order observations are retained; no confidence intervals are claimed. Lifetime VmHWM was 81.7 MiB including oracle preparation; maximum accounted cache occupancy was 3.64 MiB. Dataset size is ~11 MiB. Build peaks were 6.65 GiB RSS/11.76 GiB artifacts under 9/24 GiB guards. Optimized artifacts were removed after recording the binary hash. Reproduction: base `cf47711bda260edaad14c34afd780742e0452f0a`, measured revision above, complete patch SHA-256 `a7017027c2b214042ec01dd7b412a8332df946513013216a0ded64b2730f207b`. Rust 1.98.1, Linux/i7-12700, `release-with-debug`/Haswell, two build jobs, affinity 2/4, two CPU/Rayon/Tokio workers, two allocator arenas, 2 GiB runtime address-space limit. Harness cloud/geo features are disabled; workspace checks use normal features. Baseline: the same executable’s uncached scorer selected by explicit full-fragment scope. Harness, raw CSV, per-order comparisons, hashes, environment and reproduction instructions: `/tmp/quantized-refinement-pressure/`. Frozen fixture and original warm/fresh-session observations: `/tmp/quantized-refinement-bench/`. Benchmark files are excluded from the PR. Benchmarks were not rerun against the rebased upstream cache implementation. Real remote-storage and production-workload performance remain unverified. The measured optimization is conditional on repeat traffic and a suitable cache budget. --------- Co-authored-by: Xuanwo <[email protected]>
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:
Part of OSS-2841. This reuses the existing translation fingerprint; #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 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_residentwas 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.These are single-process observations for each arm/scenario, without confidence intervals. Baseline is direct parent
1b8e2426a69a589a9bf4309f7218b8ee914105c0; candidate ise75d3685fa2259633cb0b178b19caefec623d867. 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, LanceDBd5013459eb4c7beb84d80bc2c26720d58f347611, 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.