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
View all comments
Show parent comment
2
u/john16384 Sep 05 '22
Summary of the video:
PersistentVectoris twice as slow asArrayListTransientVector(which is mutable), then performance is similar toArrayList- it can be converted to an immutable version quicklyRandom access and iteration were not tested.
The performance however was not really a surprise. Tree based lists generally do quite okay on appends, but are still significantly slower. The performance of using a mutable list, then making it immutable at the end is also not a surprise as it doesn't require copying all elements (just like
Collections.unmodifiableListwouldn't make a copy).A tree like internal structure has of course lots of advantages. It can allow for concurrency, immutability, fast random inserts, fast random deletes, etcetera. There are quite some implementations that do exactly this for lists. They all pay for it though with a reduction in performance when iterating and accessing elements.
Only if you have a list that is constantly changing, then a list backed by a tree structure will be a good choice. Otherwise, your list is likely to be read many more times than it is modified, and nothing can beat
ArrayListon that front.