Hey guys, I found this: <https://github.com/Kotlin...
# announcements
o
Hey guys, I found this: https://github.com/Kotlin/kotlinx.collections.immutable. Does a PersistentList have the same performance as a MutableList? For example, I'm now using a MutableList for accumulating all the chat messages in a conversation inside a flow, thinking about going a more immutable way but scared of the performance hit since chat message lists can get big. Will a PersistentList have the same performance as a MutableList in these cases?
b
There is no short answer for you - it depends on your use-case - it's necessary to consider which MutableList (e.g. LinkedList or ArrayList) and which operations do you use. Assuming default usecase - LinkedList/ArrayList + add element to end as modification - then yes, complexity will be the same
👍 1
o
Going to try it out
e
Asymptotic complexity is the same for some operators (like adding to the end) and slower by
O(log n)
factor for others (like indexed access). The real perfromance is much lower (3x-10x slower than
ArrayList
), though these are the fastest persistent collection implementations on JVM according to our tests.