Repository navigation
Memory: floating pictures' textures are bounded, sized to what is drawn, and dropped with their workbook - #1631
Merged
Conversation
…wn, and dropped with their workbook Floating pictures were decoded at full size, with no limits, into one process-wide map of textures that never let go, not even when their workbook closed. Its key was the picture's id and byte length, and ids are per workbook, so a second open workbook could show the first one's picture. The new floating_pictures module, built like cell_pictures, keeps a cache per egui context keyed by workbook, picture id and size: - bounded at 128 MB, least recently drawn first, never evicting a picture drawn in the last frame, so none turns into a placeholder; - a workbook's textures go when it closes (checked every frame); - a picture's header is read first (16,384 px a side, 64 MP at most), it is decoded with limits, and to the next size step of what is drawn (a power of two or three quarters of one, up to 4,096 px or the GPU's limit); it is decoded again only when drawn larger; - a picture that can't be decoded is remembered, not retried each frame. Measured on macOS 27 (Apple M3 Max): 12 pictures of 2600 x 2600 opened from an .xlsx and scrolled through, textures held by egui 258 -> 40 MB, settled footprint 738 -> 509 MB; after closing the workbook, textures 258 -> 0 MB, footprint 504 -> 236 MB. 24 pictures: textures 490 -> 76 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
Didn't re-run the macOS memory profiling, but the mechanism (per-context cache keyed by workbook+id+size, replacing a process-wide id+length key) is a sound, directly verifiable fix for the described leak, and the new test proves the specific bug it targets rather than just asserting the refactor "works." Good to merge. |
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
Floating pictures (Insert › Pictures) were drawn from
TEXTURESinchartview.rs, one process-wide map of textures that:to_rgba8, thenColorImage);main;A new
crates/ui-egui/src/floating_pictures.rs, built the waycell_pictures.rsis, replaces it.How
DocState::uid), picture id and size.SheetApp::logic, so it works even when no sheet is painted.image::Limits.max_texture_side. It is decoded again only when drawn larger than that, so zooming in re-decodes at most every half or third larger.How it was measured:
main(bb685e3) and from this branch.snapshotexample's harness. It opens an.xlsxwith 12 or 24 copies of a 2600 × 2600 picture (each drawn 640 points square) beside a blank workbook. It scrolls to each picture in turn, rendering at each, holds, then closes the workbook and holds again.tex_manager). "Footprint" is the settled physical footprint withMallocLargeCache=0. Opening a 243–487 MB file otherwise leaves freed buffers in the footprint; with the cache on, the savings were the same or larger.Not in this pull request
Arc<Vec<u8>>. Either can land first: this module takes&[u8]. Once both are in, the key could be the picture'sArc, as cell pictures use, instead of its id and size.ROADMAP.md, so whichever land later need that merged.print.rsdecode_image), once for every page they appear on.Checks
On macOS 27.0.1 with Rust 1.98.1,
cargo xtask cipasses: fmt, clippy, test, assets, layers, wasm, parity and keytips, 1,616 tests. Not run on Windows or Linux.New tests:
crates/ui-egui/src/floating_pictures.rs:pictures_are_decoded_at_about_the_size_drawn: the size steps, re-decoding only when drawn larger, the old texture's bytes given back, and the GPU's limit and the source size respected.the_cache_stays_within_its_budget_but_keeps_what_is_on_screen: 40 pictures of 2048 × 2048 stay within the budget, and 12 on screen at once, over the budget, keep their textures frame after frame.a_closed_workbook_takes_its_pictures_with_it: closing drops a workbook's textures, and two workbooks' picture 1s get separate textures.broken_and_oversized_pictures_are_refused_once: garbage is remembered and not retried, and a PNG whose header says 20,000 × 20,000 is refused before decoding.crates/ui-egui/tests/floating_pictures.rs,each_workbook_shows_its_own_picture: two workbooks, each with a picture 1 of the same byte length, render with different textures, and closing one leaves the other's picture as it was. Onmainit fails: the second workbook shows the first one's picture.🤖 Generated with Claude Code