kirktrue commented on PR #12782:
URL: https://github.com/apache/kafka/pull/12782#issuecomment-2289733124
For grins I made a slight modification to invoke `replicaIds.size()` only
once, at the top of the method:
```java
private static Node[] convertToNodeArray(List<Integer> replicaIds,
Map<Integer, Node> nodesById) {
int size = replicaIds.size();
Node[] nodes = new Node[size];
for (int i = 0; i < size; i++) {
Integer replicaId = replicaIds.get(i);
Node node = nodesById.get(replicaId);
if (node == null)
node = new Node(replicaId, "", -1);
nodes[i] = node;
}
return nodes;
}
```
Here are the results from that extra optimization:
```
Benchmark (nodes) Mode Cnt Score
Error Units
MetadataResponseBenchmark.toPartitionInfo 10 avgt 5 100.544 ±
11.405 ns/op
MetadataResponseBenchmark.toPartitionInfo 500 avgt 5 2633.090 ±
28.746 ns/op
MetadataResponseBenchmark.toPartitionInfo 1000 avgt 5 6739.903 ±
46.862 ns/op
```
So it's ever so slightly faster at ~24-27%.
I don't think we need to include that change. I had fun playing around and
seeing what else could be done. I also tried using an `Iterator` which was a
total disaster, performance-wise 😆
--
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]