The disadvantage of mutable data is that execution must strictly follows the programmer instructions / code, thereby, apply optimizations like “out-of-order execution” is very difficult.
The permission to change any piece of data, also cause side-effects, which makes the optimization of the compiled code even more complicated.
For example: In Java, the JVM can apply various optimizations if variables are instantiated with the keyword “final”, which defines the variable as immutable.
Java also defines strings as immutable. here is why:
the immutability of String objects can lead to better multithreaded performance, as these objects do not require synchronization or checking when used in multithreaded code. The application, and the JVM, can take for granted that a String object’s value will never change.