What it is
Immutability means never changing existing data; you produce a new value instead. The worry is cost, but structural sharing keeps it cheap by reusing the parts of a structure that did not change.
How sharing works
When you update one field of a nested object, you create new objects only along the path from the root to that field. Every untouched branch is reused by reference. A deep tree update touches a logarithmic or constant number of nodes, not the whole structure.
- Copy the changed path, share the rest.
- Unchanged subtrees keep the same reference.
- Persistent data structures generalize this idea.
Why it pays off
Because unchanged branches keep their identity, change detection becomes a cheap reference comparison. If the reference is the same, nothing inside changed, so memoized components and selectors can skip work.
Key idea
Structural sharing makes immutable updates cheap by copying only the changed path, which turns change detection into a fast reference comparison.