You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Almost 7% of the allocations seem to be due to usage of ArrayDeque and autoboxing that's required to build the stack in this code:
privatestaticComponentmarkRooted(
HnswGraphhnswGraph,
intlevel,
FixedBitSetconnectedNodes,
FixedBitSetnotFullyConnected,
intmaxConn,
intentryPoint)
throwsIOException {
// Start at entry point and search all nodes on this level// System.out.println("markRooted level=" + level + " entryPoint=" + entryPoint);Deque<Integer> stack = newArrayDeque<>();
stack.push(entryPoint);
intcount = 0;
while (!stack.isEmpty()) {
intnode = stack.pop();
if (connectedNodes.get(node)) {
continue;
}
count++;
connectedNodes.set(node);
hnswGraph.seek(level, node);
intfriendOrd;
intfriendCount = 0;
while ((friendOrd = hnswGraph.nextNeighbor()) != NO_MORE_DOCS) {
++friendCount;
stack.push(friendOrd);
}
if (friendCount < maxConn && notFullyConnected != null) {
notFullyConnected.set(node);
}
}
returnnewComponent(entryPoint, count);
}
Is this something that's worth improving - seems like a low hanging fix? (I can contribute)
If it's worth improving, then:
If there's a theoretical max depth for the stack, then the stack can be implemented with primitives avoiding the autoboxing cost, and reducing the allocation cost.
In case there's no reasonable max depth, then starting off with a higher capacity for ArrayDeque should reduce some allocations. This code in ArrayDeque::grow looks quite wasteful in terms of allocations.
Interesting. The "theoretical" max depth of this stack would be the size of this graph. I suppose the stack does get large, which would explain a high no. of Array::grow calls? Would be interesting to see the impact of just setting initial capacity to half of the size of graph.
I do think it's worth improving. Another way could be to measure empirically the stack depth - maybe it scales in a predictable way with total number of vectors? And then we can use that prediction as an initial size. We could also think of using a primitive array that grows (implement our own primitive ArrayDeque).
Description
I was going through the nightly benchmark runs and came across this https://blunders.io/jfr-demo/indexing-1kb-vectors-2024.11.17.18.04.47/allocations-drill-down
Almost 7% of the allocations seem to be due to usage of
ArrayDeque
and autoboxing that's required to build the stack in this code:Is this something that's worth improving - seems like a low hanging fix? (I can contribute)
If it's worth improving, then:
ArrayDeque
should reduce some allocations. This code inArrayDeque::grow
looks quite wasteful in terms of allocations.Thoughts?
The text was updated successfully, but these errors were encountered: