apache / apache/lucene

Improve sorting logic in NeighborArray

Open
#16,321 0 comments 0 reactions 0 assignees View on GitHub
type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

### Description

The legacy sorting logic in NeighborArray below takes long N^2 in worst case, as it is a simple insertion sort and pushes/copies the rest of the array towards the end for each `uncheckedIndex`.

https://github.com/apache/lucene/blob/d87b4f3881511092bb2a5ec7530e7418157c16fc/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java#L152

I think it has a lot of scope for improvement and I'm attaching a PR below and opening a discussion for same.

Contributor guide

Open the contributing guide

Research direction

Start by reading the sorting logic in lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java around line 152. Understand how uncheckedIndex ordering and array contents are preserved, then inspect the relevant Lucene tests or benchmarks before changing the algorithm. Done means sorting is measurably improved without changing the expected neighbor ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.