Skip to content

Commit 285a3ba

Browse files
author
Stefan Vodita
committed
Revert changes to NeighborArray and OnHeapHnswGraph
1 parent b5e150e commit 285a3ba

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

lucene/CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Optimizations
299299
* GITHUB#12782: Use group-varint encoding for the tail of postings. (Adrien Grand, Zhang Chao)
300300

301301
* GITHUB#12839: Introduce method to grow arrays up to a given upper limit and use it to reduce overallocation for
302-
DirectoryTaxonomyReader and NeighborArray. (Stefan Vodita)
302+
DirectoryTaxonomyReader#getBulkOrdinals. (Stefan Vodita)
303303

304304
Changes in runtime behavior
305305
---------------------

lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,17 @@
3232
* @lucene.internal
3333
*/
3434
public class NeighborArray {
35-
private static final int INITIAL_CAPACITY = 10;
3635
private final boolean scoresDescOrder;
37-
private final int maxSize;
3836
private int size;
3937
float[] score;
4038
int[] node;
4139
private int sortedNodeSize;
4240
public final ReadWriteLock rwlock = new ReentrantReadWriteLock(true);
4341

4442
public NeighborArray(int maxSize, boolean descOrder) {
45-
node = new int[INITIAL_CAPACITY];
46-
score = new float[INITIAL_CAPACITY];
43+
node = new int[maxSize];
44+
score = new float[maxSize];
4745
this.scoresDescOrder = descOrder;
48-
this.maxSize = maxSize;
4946
}
5047

5148
/**
@@ -55,7 +52,7 @@ public NeighborArray(int maxSize, boolean descOrder) {
5552
public void addInOrder(int newNode, float newScore) {
5653
assert size == sortedNodeSize : "cannot call addInOrder after addOutOfOrder";
5754
if (size == node.length) {
58-
node = ArrayUtil.growInRange(node, size + 1, maxSize);
55+
node = ArrayUtil.grow(node);
5956
score = ArrayUtil.growExact(score, node.length);
6057
}
6158
if (size > 0) {
@@ -76,7 +73,7 @@ public void addInOrder(int newNode, float newScore) {
7673
/** Add node and newScore but do not insert as sorted */
7774
public void addOutOfOrder(int newNode, float newScore) {
7875
if (size == node.length) {
79-
node = ArrayUtil.growInRange(node, size + 1, maxSize);
76+
node = ArrayUtil.grow(node);
8077
score = ArrayUtil.growExact(score, node.length);
8178
}
8279

lucene/core/src/java/org/apache/lucene/util/hnsw/OnHeapHnswGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ public long ramBytesUsed() {
279279
(long) nsize0 * (Integer.BYTES + Float.BYTES)
280280
+ RamUsageEstimator.NUM_BYTES_ARRAY_HEADER * 2L
281281
+ RamUsageEstimator.NUM_BYTES_OBJECT_REF * 2L
282-
+ Integer.BYTES * 5;
282+
+ Integer.BYTES * 3;
283283
long neighborArrayBytes =
284284
(long) nsize * (Integer.BYTES + Float.BYTES)
285285
+ RamUsageEstimator.NUM_BYTES_ARRAY_HEADER * 2L
286286
+ RamUsageEstimator.NUM_BYTES_OBJECT_REF * 2L
287-
+ Integer.BYTES * 5;
287+
+ Integer.BYTES * 3;
288288
long total = 0;
289289
total +=
290290
size() * (neighborArrayBytes0 + RamUsageEstimator.NUM_BYTES_ARRAY_HEADER)

0 commit comments

Comments
 (0)