Skip to content

perf: use CPU pool to run WAND algo#5363

Merged
Xuanwo merged 3 commits intolance-format:mainfrom
BubbleCal:fts-cold-latency
Nov 28, 2025
Merged

perf: use CPU pool to run WAND algo#5363
Xuanwo merged 3 commits intolance-format:mainfrom
BubbleCal:fts-cold-latency

Conversation

@BubbleCal
Copy link
Copy Markdown
Contributor

this reduces 10%~20% cold latency for full text search

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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.

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +795 to +799
let partition_ptr = PartitionPtr::new(self);
let (candidates, local_metrics) = spawn_cpu(move || {
let local_metrics = LocalMetricsCollector::default();
// SAFETY: `partition_ptr` points to `self`, which outlives this task because we await it.
let partition = unsafe { partition_ptr.deref() };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep partition alive for spawn_cpu WAND task

The WAND search is now offloaded to spawn_cpu using a raw PartitionPtr to self, but the background CPU task is not tied to the async future’s cancellation. If the bm25_search future is dropped (e.g., request cancellation) while the index is concurrently torn down, the blocking task will continue running and dereference a pointer to a freed InvertedPartition, leading to potential use-after-free/UB. Consider holding an Arc<InvertedPartition> inside the closure or otherwise ensuring the partition outlives the spawned CPU job under cancellation.

Useful? React with 👍 / 👎.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 27, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-index/src/scalar/inverted/index.rs 91.66% 1 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@BubbleCal BubbleCal requested a review from Xuanwo November 27, 2025 14:13
let partition_ptr = PartitionPtr::new(self);
let (candidates, local_metrics) = spawn_cpu(move || {
let local_metrics = LocalMetricsCollector::default();
// SAFETY: `partition_ptr` points to `self`, which outlives this task because we await it.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we avoid this? This can't be guaranteed since the future itself could be dropped at any time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was wondering if you could refactor this function.

Move the postings calculation out and await it separately, since bm25_search is just a pure blocking function.

Signed-off-by: BubbleCal <bubble-cal@outlook.com>
Copy link
Copy Markdown
Collaborator

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Nice, I love it

@Xuanwo Xuanwo merged commit 9344121 into lance-format:main Nov 28, 2025
39 of 43 checks passed
jackye1995 pushed a commit to jackye1995/lance that referenced this pull request Jan 21, 2026
this reduces 10%~20% cold latency for full text search

---------

Signed-off-by: BubbleCal <bubble-cal@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants