Skip to content

Improve BufferedUnionScorer performance by ~9%#2942

Open
PSeitz wants to merge 7 commits into
mainfrom
faster_union
Open

Improve BufferedUnionScorer performance by ~9%#2942
PSeitz wants to merge 7 commits into
mainfrom
faster_union

Conversation

@PSeitz

@PSeitz PSeitz commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Improves Batch-handling of BufferedUnionScorer for better performance.

BufferedUnionScorer now has two refill paths.
The old path scores from the scorer's current doc one by one.

The new path is for scorers that can score a doc passed in explicitly, which can work on batches:

  • fill a buffer with docs below the current horizon
  • fetch term frequencies for to those docs
  • insert the buffered docs into the union window
  • score them with score_doc(doc, term_freq)

score_doc(doc, term_freq) is differnt because the scorer's current doc is not the current doc being scored.
This direction is required for a more batch oriented approach to scoring.

TermScorer implements score_doc, but most scorers like a union scorer will not.
For those scorers we will check upfront if they implement score_doc and if not we will fallback to the old path.

BM25 fieldnorm score caches are also reused per thread.
This reduces the different memory addresses we need to access.

Benchmark

union_top100_count union_count_only

Caveat

The performance improvement mostly affects terms with many hits. Low number of hits degrade in perforamnce. (this should be fixable)

Future Work

The biggest consumer with 17% is BufferedUnionScorer::advance_buffered. A collect_block for scores may help

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 672bf45235

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/exclude.rs Outdated
@PSeitz PSeitz force-pushed the faster_union branch 2 times, most recently from 51902f6 to 1095543 Compare May 31, 2026 19:23

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10955437d2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/union/buffered_union.rs
@PSeitz PSeitz force-pushed the faster_union branch 2 times, most recently from 679dc20 to 74f37f0 Compare May 31, 2026 19:58
@PSeitz PSeitz changed the title Improve scored unions by ~9% Improve scored and count-only unions by ~9% May 31, 2026
PSeitz added 7 commits June 12, 2026 09:29
Add horizon-limited buffering APIs for docsets and scorers so buffered union can refill from block-oriented postings while preserving term frequencies. This lets term scorers score buffered docs directly and reduces per-document refill overhead for dense unions.
Reuse BM25 TF normalization caches for weights with the same average fieldnorm using a bounded thread-local LRU. This avoids recomputing and duplicating the cache for many terms on the same field without adding cross-thread contention.
BufferedUnionScorer can use score_doc during refill only when the score combiner needs scores. DoNothingCombiner now advertises that scoring is unnecessary, preserving the no-score path for count collectors and avoiding wasted score_doc calls.

Add a regression test that verifies DoNothingCombiner does not invoke score() or score_doc() while counting a buffered union.
@PSeitz PSeitz changed the title Improve scored and count-only unions by ~9% Improve unions by ~9% Jun 12, 2026
@PSeitz PSeitz changed the title Improve unions by ~9% Improve unions performance by ~9% Jun 12, 2026
@PSeitz PSeitz changed the title Improve unions performance by ~9% Improve BufferedUnionScorer performance by ~9% Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant