guava icon indicating copy to clipboard operation
guava copied to clipboard

Update AbstractBaseGraph.java

Open Abubakar-Sattar opened this issue 10 months ago • 0 comments

Upon reviewing the AbstractBaseGraph class in the Guava library, I have identified an opportunity to enhance its performance by reducing redundant object creation. Specifically, in methods that return collections, such as edges(), new AbstractSet instances are created each time the method is called. This can be optimized by caching these collections, assuming the graph's structure remains unchanged.

Proposed Improvement:

Introduce caching for the edges() method to avoid unnecessary object creation. This involves storing the result in a private transient field and returning the cached collection on subsequent calls, provided the graph hasn't been modified.

PS: @cpovirk Do let me know if you want me to change something from it...

Abubakar-Sattar avatar Feb 03 '25 17:02 Abubakar-Sattar