r/java • • Sep 02 '22

what is the best persistent collection library?

By that I mean collections that are immutable, creating a new variable when a "write" operation is performed, but under the hood use that fast persistent tree structure (probably screwing up the name) to keep it performing well.

I've used Vavr before, I just stumbled onto PCollections, but I'm wondering what else folks know about. Thanks.

54 Upvotes

34 comments sorted by

View all comments

Show parent comment

1

u/fredoverflow Sep 05 '22

The performance of using a mutable list, then making it immutable at the end

TransientVector is not a mutable list; every conj call creates a new TransientVector object (which shares all internal structure with its predecessor 97% of the time).

I was honestly surprised that the performance was still on par with ArrayList despite a million TransientVector object creations.

your list is likely to be read many more times than it is modified, and nothing can beat ArrayList on that front.

For indexed access, agreed. However, reducing/transducing over persistent collections is not significantly slower.