Repository navigation
perf(editor): bound the memory each document's undo history holds - #4584
Merged
Merged
Conversation
The undo and redo stacks together hold at most a byte budget, 32 MiB by default, charged with the UTF-16 text each mutation and its inverse keep. A new step that goes over it drops the oldest steps first, then the redo step furthest from the text; the newest step always stays. A history restored into the editor, as a hidden query tab's is, is trimmed the same way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
CEUndoManagernow holds at mostmaximumHistoryBytes(32 MiB by default) across the undo and redo stacks. Each step is charged the UTF-16 text its mutations and their inverses keep, plus the mutation itself.levelsOfUndomeasured in bytes, so one Format Query cannot outweigh thousands of keystrokes.restore(_:)trims to the same budget, so a hidden query tab's history is bounded the same way when it comes back.History.bytesreports the charge, for the app-wide budget once perf(memory): one app-wide budget for results held off screen #4556 lands.Measured with a local Swift Testing probe (debug build, not committed): 30 whole-document replaces of a 1.9M-character script, as 30 Format Query runs.
phys_footprintgrowthTest plan
UndoBudgetTests(new): steps past the budget drop the oldest and the newest still undo in order with the bytes under the budget; a step larger than the budget is kept and undoes; a whole-document replace is charged both texts; the redo stack counts and a restored history is trimmed to the budget; a budget of zero keeps every step.verify.sh package TableProEditor 'Undo|Composition|TextViewController|SourceEditor': 163 passed.Closes #4538