Immutable designs are great but we know that we can be slower than mutable designs.
However, Software Engineer, Oscar Boykin gave a handy tutorial at Scale by the Bay on how we can create an immutable public API with twice the performance of the original!
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.
This talk was given by Oscar Boykin at Scale by the Bay 2018.