shubhamvishu opened a new pull request, #16976:
URL: https://github.com/apache/lucene/pull/16976

   ### Description
   
   Worked with Claude/AI (with human in the loop :) ) to find this nice 
optimization idea(s) (one of many) to have a scratch array per level instead of 
creating new one and growing everytime on insertions. 
   
   `addGraphNodeInternal` allocated a new `NeighborArray` per level per 
inserted node; it starts at [1/8 of its 
capacity](https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java#L54-L55)
 and regrows about 14 times (happens [here in 
ArrayUtil](https://github.com/apache/lucene/blob/main/lucene/core/src/java/org/apache/lucene/util/ArrayUtil.java#L133-L164))
 to hold beamWidth(eg : 250) candidates. Each builder now keeps one array per 
level and reuses it so we don't create it per insertion and the overhead of 
growing.
   
   Ran luceneutil on Cohere 1024d vectors 1M docs 
   
   | quantized | run | index(s) | Δ index | merge wait(s) | force\_merge(s) | 
total(s) | Δ total | recall | visited | index\_size(MB) |
   | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
   | 1 bit | main | 191.27 |  | 9.96 | 217.85 | 419.07 |  | 0.687 | 8536 | 
4181.86 |
   | 1 bit | PR | 182.11 | **−4.8%** | 8.11 | 225.72 | 415.94 | −0.7% | 0.687 | 
8548 | 4181.87 |
   | 4 bit | main | 197.83 |  | 26.33 | 230.20 | 454.35 |  | 0.911 | 7350 | 
4535.59 |
   | 4 bit | PR | 188.58 | **−4.7%** | 17.52 | 225.62 | 431.72 | **−5.0%** | 
0.911 | 7337 | 4535.47 |
   | float32 | main | 223.50 |  | 114.21 | 159.91 | 497.61 |  | 0.979 | 7269 | 
4031.67 |
   | float32 | PR | 218.41 | **−2.3%** | 102.09 | 165.86 | 486.36 | **−2.3%** | 
0.979 | 7269 | 4031.66 |
   
   <!--
   If this is your first contribution to Lucene, please make sure you have 
reviewed the contribution guide.
   https://github.com/apache/lucene/blob/main/CONTRIBUTING.md
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to