Skip to content

perf(fts): remove OR hot path bookkeeping#7416

Merged
BubbleCal merged 1 commit into
mainfrom
yang/fix-fts-or-hotpath
Jun 24, 2026
Merged

perf(fts): remove OR hot path bookkeeping#7416
BubbleCal merged 1 commit into
mainfrom
yang/fix-fts-or-hotpath

Conversation

@BubbleCal

Copy link
Copy Markdown
Contributor

Performance Improvement

What is the performance issue or bottleneck?

Recent FTS changes added AND/fuzzy bookkeeping to shared OR query paths. Ordinary non-fuzzy OR searches were still allocating and checking grouped expansion state, maintaining matched-position tracking in posting-list loading, and recording AND-only WAND metrics even though those values are only meaningful for conjunction/grouped expansion paths.

How does this PR improve performance?

This PR keeps ordinary OR on the lightweight path:

  • only allocates and updates required/matched position tracking for AND or phrase queries
  • skips grouped-position HashSet creation and per-frequency grouped checks unless grouped fuzzy expansions are present
  • records AND-only WAND metrics only for Operator::And

Grouped fuzzy AND rescoring remains on its existing grouped path so matched-expansion scoring stays correct.

Benchmark or measurement results

No benchmark was run in this PR. The change is intentionally scoped to hot-path bookkeeping removal; benchmark validation can run later on the existing benchmark branch/VM if needed.

Bug Fix

What is the bug?

The ordinary OR path was paying for bookkeeping intended for AND/fuzzy/grouped expansion correctness.

What issues or incorrect behavior does the bug cause?

It caused avoidable overhead in OR query execution and showed up as a small regression in OR benchmark configurations after the recent FTS changes.

How does this PR fix the problem?

The OR path now bypasses the AND/fuzzy-only bookkeeping while preserving the grouped expansion branch used by fuzzy AND.

Validation

  • cargo fmt --all
  • cargo fmt --all --check
  • git diff --check
  • CARGO_TARGET_DIR=/tmp/lance-target-fts-or-hotpath cargo clippy -p lance-index --tests -- -D warnings
  • CARGO_TARGET_DIR=/tmp/lance-target-fts-or-hotpath cargo test -p lance-index scalar::inverted::wand::tests -- --nocapture
  • CARGO_TARGET_DIR=/tmp/lance-target-fts-or-hotpath cargo test -p lance-index scalar::inverted::index::tests::test_bm25_search_uses_global_idf -- --nocapture
  • CARGO_TARGET_DIR=/tmp/lance-target-fts-or-hotpath cargo test -p lance-index scalar::inverted::index::tests::test_and_query_returns_empty_when_exact_term_missing -- --nocapture
  • CARGO_TARGET_DIR=/tmp/lance-target-fts-or-hotpath cargo test -p lance-index scalar::inverted::index::tests::test_fuzzy_and -- --nocapture

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer performance labels Jun 23, 2026
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-index/src/scalar/inverted/wand.rs 72.50% 10 Missing and 1 partial ⚠️
rust/lance-index/src/scalar/inverted/index.rs 80.00% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@BubbleCal
BubbleCal marked this pull request as ready for review June 23, 2026 11:41

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

One minor suggestion from Claude:

rust/lance-index/src/scalar/inverted/index.rs ~line 884 — Scoring loop body is duplicated ~25 lines between the two branches. The fast path and full path share identical logic for addr resolution, score accumulation over freqs, and heap push/pop. Only the grouped_positions.contains guard and the grouped-expansion inner loop differ. Extracting the shared scaffolding (addr resolution + heap update) into a closure or small helper would halve the duplication and reduce maintenance risk when either scoring formula changes in the future. This is a cleanup concern, not a correctness bug.

@BubbleCal
BubbleCal force-pushed the yang/fix-fts-or-hotpath branch from 7a8cb25 to 94c6e2a Compare June 24, 2026 04:22
@BubbleCal
BubbleCal merged commit 941c808 into main Jun 24, 2026
30 checks passed
@BubbleCal
BubbleCal deleted the yang/fix-fts-or-hotpath branch June 24, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants