Currently, ve.dm.TransactionProcessor modifies DM tree structure by rebuilding tree branches afresh (i.e. calling ve.dm.Document#rebuildNodes on the parts of the tree that it determines need to change).
It would be nicer for many purposes to restructure the tree in a way that preserves existing nodes where possible (whereby, for instance, removing a surrounding <div>...</div> grafted its erstwhile child node objects into their erstwhile grandparent without recreating them).
However it may cause breakage where existing code assumes DM/CE node ancestry will not change.
The tree restructuring can be done with a single pass through the transaction operations, and two pointers that walk the tree in document order, one inserting nodes and the other removing them. I'll add further details.