Effective Kotlin Item 56: Consider using mutable collections
The biggest advantage of using mutable collections instead of immutable is that they are faster in terms of performance. When we add an element to an immutable collection, we need to create a new collection and add all elements to it. Here is how it is currently implemented in the Kotlin stdlib (Kotlin 1.2):
When we deal with bigger collections, adding multiple elements to another collection can be a costly process. This is why using mutable collections, especially if often we need to add elements, is a performance optimization. On the other hand Item 1: Limit mutability taught us the advantages of using immutable collections for safety. Notice that those arguments rarely apply to local variables where synchronization or encapsulation is rarely needed. This is why for local processing, it generally makes more sense to use mutable collections. This fact can be reflected in the standard library where all collection processing functions are internally implemented using mutable collections:
Instead of using immutable collections:
Adding to elements mutable collections is generally faster, but immutable collections give us more control over how they are changed. Though in local scope we generally do not need that control, so mutable collections should be preferred. Especially in utils, where element insertion might happen many times.