Store operations as plain JS objects in History #1576
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey! This PR is a suggested mitigation for #1402 and reduces the memory overhead of keeping a large undo stack by converting the
Operation
objects inHistory
to plain JS (and stripping the__cache
field used for memoization.)In order to make this change, I removed the selection
paths
from the JSON representation in favor of thekeys
in the underlyingRange
. I'm not sure what the motivation is for storing them as paths (maybe an experiment toward #1408? maybe support for collaborative editing?) Because the serialized and deserialized Selection objects no longer havevalue.document
, they can't perform the coercion from path to key and vice versa.To implement this and keep the added benefits of using
paths
, I think the best move (long term at least) is to fully implement #1408, since using paths everywhere would also eliminate the need forvalue.document
and the conversion.Outcomes
Test Scenario:
Note that in both results below the memory usage is growing because we haven't hit the undo limit, so we're storing more and more data with every keystroke. It's just that in the after scenario we're storing so little it appears it's not growing.
Before:
After: