Immutable designs are great but we know that we can be slower than mutable designs.
Check it out below.
Immutable APIs and mutable internals: a Scala design case study
We love immutability for creating clear APIs that are easy to understand. Unfortunately, many immutable designs are slower than comparable mutable designs.
In this tutorial style talk we will consider the case of parser combinators. We will first create a simple immutable API for our parser combinator library. Then we will consider an alternate implementation that keeps the immutable API but composes using hidden mutable state. The result is an immutable public API with twice the performance of the original. This design approach can generalize to other use cases in Scala to retain a safe and clean API but dramatically improve performance.