I've had a thought: if I have an update function that modifies and optimizes a data structure in one branch, but doesn't need to modify it in another branch, should the second branch still apply the optimization?
The trade-off is returning a reference to the unmodified data structure vs building a semantically-equivalent structure that will have faster lookups on subsequent queries.