Repository navigation
Memory: undo steps share picture and macro bytes instead of copying them - #1629
Merged
Merged
Conversation
Every edit copies the workbook for its undo step (copy-on-write: sheets and 64-row bands of cells are shared). A floating picture's bytes (Image.data) and the VBA project (Workbook.vba_project) were plain Vec<u8>, so each edit on a sheet with a picture, and every edit in a workbook with macros, kept another full copy of them, up to the 100 steps of the history. They are Arc<Vec<u8>> now, as cell pictures already are, with base64 helpers for serde (b64::shared, b64::opt). JSON and XLSX are unchanged. Measured on macOS 27 (Apple M3 Max), gridcraft-cli, kernel peak footprint: a 19 MB picture and 50 cell edits on its sheet, 992 -> 22 MB; 10 edits, 215 -> 21 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
arcanii
added a commit
to arcanii/DevCraft
that referenced
this pull request
Oct 16, 2026
…old#1629, storytold#1630 and storytold#1631 (aniefork) The sister fork's memory work on WordCraft, done for GridCraft: upstream bb685e3 measured through the CLI and the offscreen snapshot with wordcraft's sampler and a new generator (docs/memory-aniefork/), and the code traced. Findings in docs/memory-aniefork.md. Offered upstream from branches cut from upstream/main: undo steps share picture and macro bytes (storytold#1629), interface fonts shared with egui (storytold#1630), floating pictures' textures bounded and kept per workbook (storytold#1631). Docs and tools only on the fork's main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified against
Correct, mechanically thorough (every call site updated, not just the hot ones), and the measured numbers' mechanism checks out structurally even without re-running the macOS memory profiling. Good to merge. |
aiongg
added a commit
to aiongg/gridcraft
that referenced
this pull request
Oct 22, 2026
…ter storytold#1629) shared_media.rs predates the Arc change; literals and comparisons use .into() and to_vec().
arcanii
added a commit
to arcanii/DevCraft
that referenced
this pull request
Oct 22, 2026
…rk's hooks kept Upstream a1c8454, 610 commits since the merge before (68e58a2), 345 of them not merges, with release 0.10.0 and the fork's memory pull requests storytold#1629, storytold#1630 and storytold#1631. Conflicts: - README.md: the fork's kept (upstream added its app icon and fixed a link). - crates/ui-egui/src/grid.rs, the cell editor: upstream's wrapping editor for a Wrap Text cell, the fork's growth a whole cell at a time for any other; paint_editor gets the wrapped width there. - crates/ui-egui/src/lib.rs: upstream's autosave, then the fork's field, in UiState and its Default; aniefork::poll right after control::poll, then upstream's guard_window_close. - crates/ui-egui/src/ribbon.rs: upstream paints a title cut to fit between the controls; the fork's window_title goes through it, so the unsaved dot follows the application's name. The fork's own code follows upstream: vba_project is an Arc (storytold#1629) in the macros tests, and the panels' batch estimates its undo step's retained_bytes (storytold#1227) as the engine does. Upstream fixed the clippy lint the fork had patched in desktop_theme.rs: the patch is gone. Two upstream tests that measure the editor's painting, which the fork replaces, are ignored (tests/in_cell_editor_size.rs). Cargo.lock takes the fork's crate to 0.10.0. Every hook in ROADMAP-aniefork.md's table is present; docs/brand/ holds only LICENSE-brand.txt. cargo xtask ci on macOS: all eight steps, 2,456 tests, 3 ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What it does
Each undo step keeps the workbook as it was before the edit. Sheets and their 64-row bands of cells are shared between steps (copy-on-write), but two byte blobs were not:
Image.data), copied with its sheet at every edit on that sheet;Workbook.vba_project), copied with the workbook at every edit.So one 20 MB picture cost another 20 MB for every cell typed on its sheet, up to the 100 steps of the history (2 GB). Both are now
Arc<Vec<u8>>, as cell pictures (Arc<CellPicture>) already are, so the steps share one payload.How
Image.dataandWorkbook.vba_projectareArc<Vec<u8>>.gridcraft_model::b64::shared(new) andb64::opt(now forOption<Arc<Vec<u8>>>) keep their JSON exactly as before: base64 text. XLSX reading and writing are unchanged..into()where aVecbecomes the field,.to_vec()where the XLSX writer copied the bytes into a part before.How it was measured:
main(bb685e3) and of this branch.proc_pid_rusage: the kernel's lifetime peak forgridcraft-cli run --script.insert.picture, then Ncell.seton the same sheet:Not in this pull request
Arcwould be a larger change.Arc.Checks
On macOS 27.0.1 with Rust 1.98.1,
cargo xtask cipasses: fmt, clippy, test, assets, layers, wasm, parity and keytips, 1,612 tests. Not run on Windows or Linux.New test in
crates/engine/src/tests.rs:undo_steps_share_picture_and_macro_bytes. It inserts a picture withinsert.picture, sets a VBA project and types three cells. It then checks that every undo step's picture bytes and VBA project are the same allocation as the live ones (Arc::ptr_eq), and that undo and redo give the picture back.🤖 Generated with Claude Code