I realise that this is probably quite a subjective question, but I'm looking for some insights from those more experienced than I am in functional programming.
It's my understanding that the main motivators for keeping everything immutable are making things easier to understand, and stopping errors from creeping into parallel tasks. The downside to this is that every time you want to make a change to a data structure, you have to copy the whole data structure into a fresh object, but with the desired change. Presumably there is some performance cost to doing this: while I wouldn't think twice about doing that for a small object, surely that becomes incredibly slow if you're working on large matrices or tensors, or similarly large data structures?
In short:
- Is there a performance penalty for copying immutable data structures, and how significant is it?
- If so, can you give an example of where you (personally) would draw the line between making something immutable and making it mutable?