Skip to content

Comments

chore: avoid redundant IndexDocument construction in heap emplace#152

Open
longway-code wants to merge 1 commit intoalibaba:mainfrom
longway-code:chore/flat-heap-early-pruning
Open

chore: avoid redundant IndexDocument construction in heap emplace#152
longway-code wants to merge 1 commit intoalibaba:mainfrom
longway-code:chore/flat-heap-early-pruning

Conversation

@longway-code
Copy link

@longway-code longway-code commented Feb 19, 2026

Summary

IndexDocumentHeap::emplace now checks score < front().score() before calling into ailego::Heap, avoiding unnecessary object construction for candidates that would be rejected anyway.

Performance

Tested locally, decreased ~15% end-to-end latency of FlatSearcher::search_impl (N=100k, dim=128, topk=10, FP32 SquaredEuclidean, 200 queries averaged).

All Tests Passsed

…e cannot improve top-k

In IndexDocumentHeap::emplace, the parent ailego::Heap::emplace constructs
the IndexDocument object before checking whether the candidate score beats
the current heap front. For rejected candidates this construction is wasted.

Add an early-exit guard: when the heap is full, skip the emplace call
entirely if score >= front().score(). The short-circuit evaluation of ||
ensures front() is only accessed when the heap is non-empty.

Benchmark (N=100k, dim=128, topk=10, 200 queries): ~14% latency reduction.
@longway-code longway-code changed the title chroe: avoid redundant IndexDocument construction in heap emplace chore: avoid redundant IndexDocument construction in heap emplace Feb 19, 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.

2 participants