Optimize the undo queue for storage and playback.