2 ms·
Which optimizations are enabled by immutable data? If nothing else, deep immutability means you can pass around a reference to data instead of the data itself
by Silhouette 7y ago
Which optimizations are enabled by immutable data?
If nothing else, deep immutability means you can pass around a reference to data instead of the data itself but still treat it as having value semantics. This can be a huge saving with large data structures, sharing data across threads, etc.
C++ programs are full of functions taking const references to things instead of the things themselves because C++ programmers have to do this optimisation (or some equivalent) manually to get the same performance boost, because the language doesn't prevent all possible cases of aliasing that would make automatically applying that transformation safe.