Repository navigation
perf(fts): remove benchmark metrics from query hot paths - #8825
Conversation
5c83364 to
57d5091
Compare
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The change removes validation-only registration and bookkeeping from the FTS document, candidate, and window hot paths while retaining coarse production observability and test-only activation counters. The maintained oracle/equivalence tests and the controlled ABBA measurements support both result stability and the path-specific performance gain.
Please mark this PR with the breaking-change label.
57d5091 to
3d37d59
Compare
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The rebased patch remains a metrics-only cleanup: it removes validation bookkeeping from hot paths without altering scoring behavior or the newly shared MultiMatch prefilter contract. The result-stability and path-specific performance evidence continues to support the change.
Please mark this PR with the breaking-change label.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Neither scan orders equal scores, so the plan's `(score DESC, row_id ASC)` sort stays what decides which of two tied rows comes first. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
…AXSCORE The cross-field scan scores every candidate in the union of the query terms' postings. This adds the term-at-a-time MAXSCORE loop, which skips scoring a candidate whose upper bound cannot reach the running k-th score. Each term carries a constant ceiling `idf' · BM25_DOC_WEIGHT_UPPER_BOUND` (Lucene's `CombinedFieldQuery` uses a per-term constant rather than a per-block maximum, because the BM25F blend makes a block-max meaningless across columns). Terms are ordered by ceiling and split into an essential suffix, which drives candidate discovery, and a non-essential prefix, which is only probed once a candidate's partial score makes it viable. `BM25_DOC_WEIGHT_UPPER_BOUND` is the ceiling `doc_weight` already clamps to, so the bound holds by construction rather than by trusting the corpus statistics. Reuses `wand::score_sum_cannot_compete` for the prune test, widening its visibility to `pub(super)`. `CompetitiveFloorMode::Exclusive` matches this scan's score-only strict-`<` collector. The top-k scores are identical to the exhaustive scan by construction, and the tests assert exactly that: `exact_topk_scores` rescores every candidate the merged scan would and compares bit-for-bit, over OR and AND, every k, absent columns, a masked prefilter, ties and a clamped zero-idf term. Both scans order equal scores by `RankedDoc`, so the top-k is settled in the scan rather than by the plan's sort, which the fully covered plan does not have. The prune stays `Exclusive`: discovery is ascending by row id, so a candidate that only ties the k-th score always loses the tiebreak to the incumbents, and rejecting it drops nothing the collector would have kept. `test_combined_maxscore_ties_keep_lowest_row_ids` pins that. `MaxscoreStats` counts candidates discovered against candidates pruned and scored. Per-candidate bookkeeping does not belong on the production `MetricsCollector`, which lance-format#8825 deliberately reduced to coarse observability, so the counters reach dev targets the way the brute-force oracle already does: the `maxscore` module stays private and the new `test-scan-stats` feature re-exports `MaxscoreStats` next to `combined_fields_search_with_stats`, which is the whole implementation with plain `combined_fields_search` delegating to it and dropping the stats. Nothing is added to the default path. The unit tests assert on those counts directly, so a gate that never fires cannot pass as correct-but-inert.
Performance issue
Recent compound FTS optimizations exposed 41 validation metrics through the production DataFusion operator. This registered 58 metrics per FTS execution partition in total and kept benchmark bookkeeping in document, candidate, and window loops.
How this improves performance
MetricsCollectorsurface andFtsIndexMetricsregistration.#[cfg(test)]where practical.The FTS-specific registrations fall from 44 to 3. Including unchanged generic index and DataFusion baseline metrics, the total per FTS execution partition falls from 58 to 17.
Benchmark
Both runs compared baseline
0ac7d22fb35793fbf34b63e52061c1f91ea5722bwith this PR at57d50914b0596a18ee2cce3180cf69048a625e64onyang-agent-fts-compound-20260819-c, a GCPc4-highmem-16VM inus-central1-c, using therelease-with-debugprofile. Lower latency and higher QPS are better.Protocol: five stratified queries,
must_should,should_sum,boost_negative, andphrase_should,k=10,100, eight threads, one warmup plus three measured repetitions per trial, prewarmed index, and ABBA order (baseline, PR, PR,baseline) with forward/reverse case order. The manifest query IDs were normalized to contiguous IDs without changing query text, order, or source rows; its SHA256 is2efbbf779e213918c33d7517d069994a05a0b30cf9a9af4d22f9d0c9657d7dd1.Fully indexed 10M rows: compound fast path
All 24 preflight cases used
CompoundFtsScorerin both builds. Full plan text and ordered row/score digests were identical. All 120 timed ordered row+f32 digest cases matched exactly, with zero intra-build or cross-build drift.boost_negative, k=10, QPSboost_negative, k=100, QPSmust_should, k=10, QPSmust_should, k=100, QPSphrase_should, k=10, QPSphrase_should, k=100, QPSshould_sum, k=10, QPSshould_sum, k=100, QPSAcross these cases, p50 latency improved by 1.0527x to 1.2187x.
Result root:
/mnt/benchmark-ssd/mmlb-queue/08-compound-partial-layers/results/metrics-cleanup-57d50914b-full-index-abba2(results-fingerprint.jsontree SHA256a98748f9e4e3e942312cfb40943d7969d0836c8be69814c3b2c4dc683ca81cfd).10M indexed + 100k unindexed rows: current fast-search fallback
Current
mainplans this partially indexed workload into the leafBooleanQuery/BoostQueryfallback rather thanCompoundFtsScorer. All 24 preflight plans were byte-for-byte identical between builds, and all 120 timed ordered row+f32 digest cases matched exactly. The QPS ratios straddle 1.0x (0.9689x to 1.0261x), so this longer fallback workload shows no clear performance change.boost_negative, k=10, QPSboost_negative, k=100, QPSmust_should, k=10, QPSmust_should, k=100, QPSphrase_should, k=10, QPSphrase_should, k=100, QPSshould_sum, k=10, QPSshould_sum, k=100, QPSResult root:
/mnt/benchmark-ssd/mmlb-queue/08-compound-partial-layers/results/metrics-cleanup-57d50914b-abba2(results-fingerprint.jsontree SHA25684d789a5ef3e7e4589cb78573ca06af562dae028d896f8a1308d11f226663f61).Validation
cargo fmt --allgit diff --check