Make HnswLock and LockedRow final (#13776)

Trivial commit that makes HnswLock final and LockedRow a record. This is general clean up and helps the JIT a little when reasoning about these types - which show quite a bit in indexing and search profiles.
This commit is contained in:
Chris Hegarty 2024-09-12 20:39:57 +01:00 committed by GitHub
parent 2f7da75b7d
commit 3a8f75ccfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 12 deletions

View File

@ -222,7 +222,7 @@ public class HnswConcurrentMergeBuilder implements HnswBuilder {
@Override
void graphSeek(HnswGraph graph, int level, int targetNode) {
try (HnswLock.LockedRow rowLock = hnswLock.read(level, targetNode)) {
NeighborArray neighborArray = rowLock.row;
NeighborArray neighborArray = rowLock.row();
if (nodeBuffer == null || nodeBuffer.length < neighborArray.size()) {
nodeBuffer = new int[neighborArray.size()];
}

View File

@ -339,7 +339,7 @@ public class HnswGraphBuilder implements HnswBuilder {
int nbr = candidates.nodes()[i];
if (hnswLock != null) {
try (HnswLock.LockedRow rowLock = hnswLock.write(level, nbr)) {
NeighborArray nbrsOfNbr = rowLock.row;
NeighborArray nbrsOfNbr = rowLock.row();
nbrsOfNbr.addAndEnsureDiversity(node, candidates.scores()[i], nbr, scorerSupplier);
}
} else {

View File

@ -25,7 +25,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* Provide (read-and-write) locked access to rows of an OnHeapHnswGraph. For use by
* HnswConcurrentMerger and its HnswGraphBuilders.
*/
class HnswLock {
final class HnswLock {
private static final int NUM_LOCKS = 512;
private final ReentrantReadWriteLock[] locks;
private final OnHeapHnswGraph graph;
@ -52,15 +52,7 @@ class HnswLock {
return new LockedRow(graph.getNeighbors(level, node), lock);
}
static class LockedRow implements Closeable {
final Lock lock;
final NeighborArray row;
LockedRow(NeighborArray row, Lock lock) {
this.lock = lock;
this.row = row;
}
record LockedRow(NeighborArray row, Lock lock) implements Closeable {
@Override
public void close() {
lock.unlock();