VisualEditor uses arrays of consecutive transactions in various places (for instance ve.dm.Document#completeHistory , an ordered list of every transaction ever applied or reverted). It would be useful for many purposes to be able to compact multiple consecutive transactions into a single transasction: e.g. auto-saving; undo/redo; rebasing conflicting edits; and reducing memory footprint.
The "squashed" transaction will have the same effect on a document as applying the original transactions in turn, but it need not include certain "transient" changes such as an insertion that is then reverted. As such, it can have a lower memory footprint than the original transaction list (but note it may cause rebase conflicts where the original transaction list would not have). Note the following important properties:
- Squashing the entire document history (from an initial empty document) results in a single insertion that is equivalent to the current document's linmod.
- Squashing the entire history of an edit session (on a pre-existing document) gives an intent-preserving diff (as opposed to the heuristic diff you get by comparing the start and end states).
- Squashing an insertion followed by a removal results in the content being removed entirely from the transaction.
- Rebasing over the squashed transaction, if it does not cause conflicts, will give the same result as rebasing over the original transaction list.
It would be most useful to squash "in-place", i.e. squash( tx1, tx2 ) modifies tx1 by incorporating tx2. That way, new transactions can be squashed consecutively onto an existing (large) transaction as the editing session proceeds, without large amounts of copying. (New-object semantics can be achieved where useful by squashing tx2 onto a clone of tx1).