benwtrent commented on code in PR #14527:
URL: https://github.com/apache/lucene/pull/14527#discussion_r2058763024


##########
lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java:
##########
@@ -32,13 +33,15 @@
 public class NeighborArray {
   private final boolean scoresDescOrder;
   private int size;
-  private final float[] scores;
-  private final int[] nodes;
+  private final int maxSize;
+  private final FloatArrayList scores;
+  private final IntArrayList nodes;
   private int sortedNodeSize;
 
   public NeighborArray(int maxSize, boolean descOrder) {
-    nodes = new int[maxSize];
-    scores = new float[maxSize];
+    this.maxSize = maxSize;
+    nodes = new IntArrayList();
+    scores = new FloatArrayList();

Review Comment:
   two things, I think these should be initialized to something like 
`maxSize/4` or `maxSize/8`.
   
   Additionally, the array lists should enforce the max size and ensure the 
underlying buffer does not get bigger than the expected max. I think you can do 
this pretty simply by having something like `MaxSizedIntArrayList` that accepts 
an init & max size parameters in its ctor, and overrides `ensureBufferSpace` so 
that it:
   
    - disallows growth past `maxSize`
    - Instead of doing `ArrayUtil.grow` it does `ArrayUtil.growInRange(buffer, 
elementsCount + expectedAdditions, maxSize)`
   
   This will prevent overallocation of the underlying buffer and enforce max 
size limitations.



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to