Closed michaelamaura closed 5 years ago
The JVM's escape analysis exists for exactly these sorts of situations, and should prevent any actual allocations from occurring. I'm willing to consider benchmarks that prove real overhead here, but otherwise I'm going to err on the side of keeping the code simpler.
Closing, pending justifying benchmarks.
Currently,
DirectedGraph#edge
relies onMap#get(K)
which returns an optional.This could be improved by using
Map#get(K, V)
with a default value - especially in highly frequently used graph traversals this could save man allocations.So instead of:
It could be something like: