Repository navigation
Done
Labels
Description
Problem
The SQL editor's undo history has no bound. Every edit group stays until the document is replaced, and hidden query tabs keep their whole history while another tab is shown. A Format Query or another whole-document replace keeps the entire old text as one undo step. Over a long session with large scripts, undo is memory that only grows. No session footprint is measured for it yet.
Cause
CEUndoManagerkeepsundoStackandredoStackas plain arrays with no level or byte limit;pushappends a group or a mutation and nothing ever trims the front (apple/Packages/TableProEditor/Sources/TableProTextEngine/Utils/CEUndoManager.swift:49-51,:262-277). The editor never setslevelsOfUndo, unlike the structure and principal change managers (apple/TablePro/Core/SchemaTracking/StructureChangeManager.swift:85).- Each mutation stores its inverse with the replaced text (
CEUndoManager.swift:228-234). Format Query replaces the whole document when nothing is selected (apple/TablePro/Views/Editor/SQLEditorCoordinator.swift:547), and so doesreplaceDocumentText(apple/Packages/TableProEditor/Sources/TableProEditorKit/Controller/TextViewController+UndoHistory.swift:35-53); each keeps the whole old document as one inverse. - On a tab switch,
takeUndoHistorymoves the stacks out of the editor together with a copy of the text (TextViewController+UndoHistory.swift:16-22), andEditorUndoHistorieskeeps one entry per open tab until the tab closes (apple/TablePro/Views/Editor/EditorUndoHistories.swift:19-38).
Change
- Give each document's undo history a byte budget, charged with the inserted and inverse text of every mutation. When a new group goes over it, drop the oldest groups first. This is the same model as
NSUndoManager.levelsOfUndo, measured in bytes instead of steps, so one large replace cannot outweigh thousands of small edits. - Charge the histories of hidden tabs to the same per-document budget, and to the app-wide memory budget once perf(memory): one app-wide budget for results held off screen #4556 lands.
- Keep the redo stack under the same budget.
Measure
- Unit test: push groups past the budget and check the oldest are dropped, the newest still undo in order, and the bytes held stay under the budget.
- Allocations after 30 Format Query runs on a 1.9M-character script and after a long typing session: persistent bytes held by undo groups, before and after.
phys_footprintwith 20 query tabs of 1 MB each that each saw a Format Query, before and after.
Part of the performance plan.
Activity