Skip to content

perf(knn): keep the NoFilter fast path for segment-scoped ANN scans - #11250

Merged
Xuanwo merged 2 commits into
lance-format:mainfrom
vaibhavdabas16:perf/11166-segment-nofilter-fast-path
Nov 25, 2026
Merged

Xuanwo merged 2 commits into
lance-format:mainfrom
vaibhavdabas16:perf/11166-segment-nofilter-fast-path

Conversation

@vaibhavdabas16

Copy link
Copy Markdown
Contributor

Closes #11166.

Problem

SegmentPreFilter only checks cached partition row coverage when its base prefilter is_empty(). When a scan selects one segment out of several, DatasetPreFilter restricts the base to that segment's fragment_bitmap. The base is then never empty, so IVF hands HNSW the per-row filter, even for partitions where every row passes.

Fix

Gate needs_partition_row_ids / is_empty_for on base.only_deletions() instead of base.is_empty(). With a deletions-only base, wait_for_ready already sets the segment's final mask to the ownership mask (the base selects every live row of the selected fragments), so ownership_mask.selects_all(rows) proves NoFilter is equivalent. A user filter, an overlay block, or FTS fragment pruning still disables the fast path, which the existing ordinary_segment assertion covers.

Tests

Extended test_append_only_deltas_keep_empty_prefilter_fast_path with the single-segment case. The base built from only the old segment is non-empty, the old segment's partition still takes the fast path, and rows of fragments outside the segment are still filtered.

Note: I couldn't run the lance crate tests or clippy locally (the test build runs out of memory on my machine). cargo fmt and typos pass. I'm relying on CI here and will fix anything it flags.

@vaibhavdabas16
vaibhavdabas16 marked this pull request as ready for review November 19, 2026 09:17

@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-approved Latest Gatekeeper recommendation permits acceptance. label Nov 19, 2026
@vaibhavdabas16

Copy link
Copy Markdown
Contributor Author

Hi @Xuanwo, when you have a moment, could you take a look at this one or point me to the right reviewer? It keeps the cached-partition NoFilter fast path for segment-scoped ANN scans (#11166). The Gatekeeper review passed, and the main CI hasn't run yet because the workflows need maintainer approval for this fork PR. Thanks!

SegmentPreFilter only consulted cached partition coverage when its base
prefilter was empty. A scan that selects one index segment out of
several builds a base restricted to that segment's fragments, so the
base is never empty and every partition paid for a per-row filter even
when all of its rows pass.

When the base only removes deleted rows and rows outside the selected
fragments, the segment's final mask is its ownership mask, so gate the
fast path on only_deletions() instead of is_empty().

Closes lance-format#11166
@vaibhavdabas16
vaibhavdabas16 force-pushed the perf/11166-segment-nofilter-fast-path branch from 0d1631a to ba3e892 Compare November 25, 2026 08:57
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 25, 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 25, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested ba3e892b against cb8c25692. The segment-scoped queries returned the expected top-k with deleted and stale rows, with stable row IDs both enabled and disabled. SQL filters, external masks and fragment subsets also returned the expected rows.

On the same IVF_PQ fixture (100k rows per segment, 64 partitions, 16 probes, k=10), the clean warm median fell from 3.89 to 2.56 ms. With 1% uniformly deleted, it rose from 3.52 to 4.55 ms and cache usage grew by about 203 KB. Results matched across revisions. These timings come from one sequential comparison on a shared host.

When every probed partition contains a deletion, selects_all clones and subtracts the allow-list before falling through to masked top-k. Could you avoid that extra work while preserving the clean-partition gain, or run interleaved parent/head measurements to establish the tradeoff?

selects_all cloned the partition's row map and subtracted (or
intersected) the mask just to test the result for emptiness. Vector
search asks it for every probed partition, so a partition holding a
deleted row paid for that copy before falling through to masked top-k.

Add RowAddrTreeMap::is_subset and is_disjoint, which compare the maps
in place, and use them in selects_all.
@vaibhavdabas16

Copy link
Copy Markdown
Contributor Author

Thanks @Xuanwo, and thanks for the measurements.

The extra work was in RowAddrMask::selects_all: it cloned the partition's row map and subtracted the allow-list (or intersected the block list) just to check whether the result was empty. In 67ccbbb it uses two new in-place predicates, RowAddrTreeMap::is_subset and is_disjoint. A partition with a deleted row now costs one in-place subset check, which stops at the first fragment that isn't covered, before it falls through to masked top-k. The clean-partition path is unchanged.

test_is_subset_and_is_disjoint_match_set_operations checks both predicates against difference(..).is_empty() and intersection(..).is_empty() across full and partial fragments, and I extended test_row_addr_mask_selects_all_known_rows with full-fragment cases. All 133 lance-select tests pass.

I can't reproduce your 100k-row IVF_PQ setup on my machine, so I don't have new timings. Could you rerun the 1% deleted case against this head? If the remaining gap is from partition row IDs being loaded and cached for this check (about 203 KB in your run), I can look at gating needs_partition_row_ids on whether the scan has any deletions at all.

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

Verified the author’s allocation fix: the set predicates preserve the all-pass proof and remove its temporary-set allocations. All 133 selection tests and 15 focused vector regressions passed locally.

Deleted partitions still incur a coverage check and may occupy the coverage cache even when they cannot use NoFilter. The earlier timings were from the previous head and a sequential comparison, so the net latency trade-off after this fix remains unverified. Interleaved measurements would help decide whether coarser deletion gating is worthwhile.

@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 25, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaibhavdabas16 I reran the 1% deletion comparison. All three revisions read the same rebuilt seeded fixture (100k rows per segment, 64 partitions, nprobes=16, k=10). I interleaved 360 warm measurements per revision per workload. Every partition in the deletion case had 7–28 deleted rows.

Warm p50 Baseline cb8c25692 Previous ba3e892b Revised 67ccbbbd
1% deleted 4.099 ms 4.971 ms 4.084 ms
Clean 4.129 ms 4.098 ms 4.182 ms

The revised head's paired median latency was 0.21% below baseline with deletions and 0.70% above baseline without them. The previous deletion regression reproduced and the revision addressed it on this fixture. The earlier clean speedup did not reproduce. Session cache usage remained 206,400 bytes above baseline with deletions and 203,106 bytes above baseline without them. The ordered top-k IDs and distance bits matched for every query. These results give me no reason to ask for another deletion check.

@Xuanwo
Xuanwo merged commit e586ce9 into lance-format:main Nov 25, 2026
47 of 55 checks passed
Xuanwo added a commit to xiaguanglei/lance that referenced this pull request Nov 25, 2026
Start the allow-list range at the first probe fragment so an early
rejection does not scan an unrelated mask prefix.

Warm RowAddrMask::selects_all time per probe (two pinned physical cores,
30 interleaved trials per case per core, 124 probes per batch). Columns
show the range of the two run medians on a Xeon Platinum 8488C.

Probe                                main       dense before seek    with seek
16,924 fragments, all match (ms)     1.445-1.448   0.867-0.870    0.858-0.859
8,462 alternating, last reject (us)  753-758       467-469        461-462
8,462 upper half, first reject (ns)  47.2-47.6     10740-10870    53.0-53.1
128 spread, all match (us)           13.62-13.74   12.61-12.76    15.09-15.13

The allow list contained 16,924 partial fragment bitmaps with physical
rows 0..1024. Each probed fragment had four valid offsets. The rejection
cases also probed offset 1024. All three variants agreed on all 1,364
individual probe results per run. These timings cover the predicate.

Measured baseline cb512b6 contains lance-format#11250. The subsequent main commit
0944680 touches MemWAL only. The two measured source files match the
rebased revisions byte for byte.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: segment-scoped ANN misses the cached partition NoFilter fast path

2 participants