diff --git a/docs/adr/0132-memory-and-frame-time-stay-flat.md b/docs/adr/0132-memory-and-frame-time-stay-flat.md index 91d49a53..764a3405 100644 --- a/docs/adr/0132-memory-and-frame-time-stay-flat.md +++ b/docs/adr/0132-memory-and-frame-time-stay-flat.md @@ -16,13 +16,13 @@ after drawing with the Brush (#477). An earlier fix cut the web build's picture We measured before changing anything (`docs/performance.md` has the tables): -* **Drawing a stage tile costs the same at every zoom.** A 1600 × 900 view takes 8 to 10 ms on - the CPU oracle from 100 % to 6400 %, also for a drawing of 64 merged brush strokes. The - cost is the pixels. So "re-tessellation at deep zoom" was not the stutter on a fast machine. +* **On many threads, drawing a stage view costs about the same at every zoom.** A 1600 × 900 + view takes 6 to 9 ms on the CPU oracle from 100 % to 6400 % on a 32-thread machine, also for + a drawing of 64 merged brush strokes: there the cost is the pixels. * **But the work per tile grew with the zoom and with the whole drawing.** A tile prepared - every edge of every item that touched it: 42,000 edges for the view at 100 %, 306,000 at - 3200 %, all but a few off the tile. For a drawing of hundreds of strokes that term overtakes - the pixels. + every edge of every item that touched it: 42,700 edges for the view at 100 %, 281,300 at + 6400 %, all but a few off the tile. On one thread, as the browser draws, the view took + 9.0 ms at 100 % and 33.5 ms at 6400 %. * **The cache filled with pictures nobody could ask for again.** A drag makes a new document state on every pointer move; each state's tiles were kept until the least recently used fell out of a 768 MB budget (384 MB more on the GPU, 192 tile textures in the shell). A @@ -112,9 +112,10 @@ scenes cut and whole at five zooms and fourteen tile positions each and compares pixmaps for equality. The GPU stage starts from the same prepared fills (ADR 0019), so it bins fewer edges too; its parity tests are unchanged. -What is left is linear in the path per tile (transforming each segment and testing its hull), -about a tenth of the old cost at deep zoom. A spatial index over a path's segments would make -it follow the visible part alone; not yet. +What is left is linear in the path per tile (transforming each segment and testing its hull): +preparing a view at 6400 % of a 64-stroke drawing went from 3.3 ms to 1.3 ms, and drawing it +on one thread from 33.5 ms to 13.0 ms. A spatial index over a path's segments would make it +follow the visible part alone; not yet. ## Consequences diff --git a/docs/performance.md b/docs/performance.md index e7169d6c..b4f78b8e 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -47,6 +47,51 @@ The default `bench` scenario: 50 layers × 200 shapes × 240 frames, 200k elemen | GPU stage, 50k shapes at 4K, one texture | < 33.3 ms | 22.5–23.8 ms ✅ | `gpu_bench --check` | | GPU stage, onion ±5 outlines / tinted at 1080p, stage tiles | ≤ 1.25 | 1.03–1.06 ✅ | `gpu_bench --check` | +**Memory and frame time stay flat (2026-11-23, P-004, ADR 0132; #314, #477).** Measured +before changing anything, then after, on the same machine (release, 32 threads). + +*What the picture cache holds.* A drag makes a new document state on every pointer move, a +zoom gesture a new zoom level on every frame, and each one's tiles used to stay until the +768 MB budget (256 MB in the web build) was full. + +| Scenario | Before | After | +|---|---|---| +| Web build in Node (`tests/wasm.rs`): WebAssembly memory over a drag of 120 moves, a 1024 × 512 view | 27 MB to 255 MB (the cache at 240 MB) | 27 MB throughout (the cache at 4 MB) | +| Desktop, Ctrl+wheel from fit to 6400 % (84 frames): pictures cached | 147 pictures, 136 MB | 44 pictures, 44 MB (the view and the ring around it, at this zoom and the one before) | +| Desktop, a drag of 300 moves in a 1600 × 940 window: pictures cached, textures, process memory | not run; by the sizes below a move adds a view of about 12 MB, so the 768 MB budget is full after some 60 moves | 42 pictures (38 MB), 12 textures, the process at 102 MB | +| Desktop, the sample's 48 frames played five times in that window | the budget | the same: 768 MB of pictures after the first lap and after the fifth (the movie at this size is larger than the budget), 192 textures, the process at 814 to 826 MB | + +*A stage view at each zoom*, 1600 × 900 in 512 px tiles on the CPU oracle, a drawing of 64 +brush strokes merged into three shapes +(`cargo test --release -p anicraft-engine --lib stage_timings -- --ignored --nocapture`): + +| Zoom | Tiles | Edges walked, before | after | Prepare, before | after | One thread (as the browser draws), before | after | 32 threads, before | after | +|---|---|---|---|---|---|---|---|---|---| +| 100 % | 6 | 42,708 | 21,935 | 1.27 ms | 1.41 ms | 9.0 ms | 8.1 ms | 2.8 ms | 2.9 ms | +| 400 % | 12 | 133,288 | 31,317 | 2.94 ms | 2.08 ms | 31.7 ms | 23.3 ms | 8.0 ms | 8.3 ms | +| 1600 % | 12 | 226,884 | 22,901 | 3.67 ms | 2.14 ms | 34.4 ms | 20.1 ms | 8.7 ms | 7.9 ms | +| 6400 % | 8 | 281,304 | 13,416 | 3.34 ms | 1.32 ms | 33.5 ms | 13.0 ms | 6.7 ms | 6.2 ms | + +Before, a tile walked every edge of every shape that touched it, cut finer the deeper the +zoom; now the parts of a fill above, below and right of the tile are left out, and the +pictures are the same to the last bit (`render::cut_tests` compares the float pixmaps). On one +thread a tile at 6400 % costs what a tile at 100 % costs (1.6 ms against 1.4 ms; it was 4.2 ms +against 1.5 ms). With 512 strokes the same view went from 25.1 ms to 12.0 ms on one thread. + +*Frame time during a zoom gesture.* The stage asks for nothing while the zoom is changing, so +a frame of the gesture costs the interface alone (0.7 ms on the desktop, at every zoom up to 6400 %). In the +browser each of those frames used to draw the whole view on the interface's thread: 9 to +34 ms for the drawing above. + +Playing is bounded by the budget, not by this change: uncompressed, a 1600 × 940 view is +about 12 MB a frame, so a movie of some 60 frames fills 768 MB. Storing flat and repeated +tiles once is the next step (P-004 in the roadmap). + +The checks are relations, not timings (`engine::render_budget_tests`, +`stage_budget_tests`, `render::cut_tests`, `tests/wasm.rs`): a long drag or zoom holds what a +short one holds, playing longer adds nothing, a deep tile walks fewer edges than the whole +drawing has at 100 %, and what the screen needs is drawn before look-ahead. + **1080p render, back under budget (2026-11-06).** It had drifted to 19.4–20.2 ms (v0.1.0 measured 18.0–18.9 ms on the same machine; the 16.5 ms of 2026-10-28 didn't reproduce). Timing each step of a frame showed the time was outside the drawing itself: diff --git a/docs/roadmap.md b/docs/roadmap.md index 2c61edd0..3d8b8bce 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -46,7 +46,7 @@ the changelog. | P-001 | AniCraft starts on every supported machine: the launch failures on Windows and Linux graphics drivers ([#164](https://github.com/storytold/anicraft/issues/164), [#158](https://github.com/storytold/anicraft/issues/158), [#207](https://github.com/storytold/anicraft/issues/207), [#268](https://github.com/storytold/anicraft/issues/268), [#421](https://github.com/storytold/anicraft/issues/421), [#342](https://github.com/storytold/anicraft/issues/342); duplicates [#488](https://github.com/storytold/anicraft/issues/488), [#448](https://github.com/storytold/anicraft/issues/448), [#412](https://github.com/storytold/anicraft/issues/412), [#313](https://github.com/storytold/anicraft/issues/313), [#286](https://github.com/storytold/anicraft/issues/286), [#285](https://github.com/storytold/anicraft/issues/285)) each end in a window or a message that says what to do | Preferences, platforms | M | reports' logs | platform | | P-002 | Nested symbols can't exhaust memory or hang: a work budget on evaluation and bounds (outside PR [#13](https://github.com/storytold/anicraft/issues/13)) | Symbols | S | | doc | | P-003 | What is left of "a long Brush stroke never freezes the app" ([#519](https://github.com/storytold/anicraft/issues/519)) after [ADR 0129](adr/0129-a-long-brush-stroke-never-holds-the-window.md) bounded the trace, took it off the window's thread and fixed the selection overlay: on one raw shape of ten thousand points and more, the Subselection tool's click (seconds, once), the Paint Bucket in a gap (about a second) and the shape tools' snapping (slow frames); and the merge of such a shape (75 to 220 ms) still runs on the window's thread | Tools | S each | | stage | -| P-004 | Memory and frame time stay flat, what is left ([ADR 0132](adr/0132-memory-and-frame-time-stay-flat.md) did the picture cache, zoom gestures, look-ahead order and off-tile edges for [#314](https://github.com/storytold/anicraft/issues/314) and [#477](https://github.com/storytold/anicraft/issues/477), each with a budget test): in the web build a drag still redraws the whole view on every pointer move (key tiles by what they show, so only the tiles the dragged thing touches are drawn again); a tile's preparation still visits every segment of a path it touches (a spatial index); deep-zoom timings of the GPU stage on more graphics cards | Workspace | M | | render | +| P-004 | Memory and frame time stay flat, what is left ([ADR 0132](adr/0132-memory-and-frame-time-stay-flat.md) did the picture cache, zoom gestures, look-ahead order and off-tile edges for [#314](https://github.com/storytold/anicraft/issues/314) and [#477](https://github.com/storytold/anicraft/issues/477), each with a budget test): in the web build a drag still redraws the whole view on every pointer move (key tiles by what they show, so only the tiles the dragged thing touches are drawn again); a tile's preparation still visits every segment of a path it touches (a spatial index); played frames are kept uncompressed, about 12 MB a frame of a 1600 × 940 view, so a short movie fills the 768 MB budget (store flat and repeated tiles once, and decide the budget); deep-zoom timings of the GPU stage on more graphics cards | Workspace | M | | render | | P-005 | Free Transform works everywhere: rotation on Windows and FreeBSD ([#479](https://github.com/storytold/anicraft/issues/479)), which did not reproduce on Windows 10 (the curved pointer shows outside a corner in the real window; the headless press-and-drag tests pass) and needs the reporter's build number and steps. Done: handles on a skewed symbol ([#117](https://github.com/storytold/anicraft/issues/117), tested end to end), and [#193](https://github.com/storytold/anicraft/issues/193) decided by [ADR 0111](adr/0111-the-transformation-point-a-turning-box-and-layer-opacity.md) with the rule in the guide | Tools | S | the reporter's answer | stage | | P-006 | Animate files open right: lines missing or filled in ([#498](https://github.com/storytold/anicraft/issues/498)), a `.fla` refused on macOS ([#347](https://github.com/storytold/anicraft/issues/347)); each fixed file joins the corpus | Import | M | the reporters' files | xfl | | P-007 | The web build is usable: import, export and save ([#55](https://github.com/storytold/anicraft/issues/55)), preferences kept ([#56](https://github.com/storytold/anicraft/issues/56)), a web asset on each release ([#316](https://github.com/storytold/anicraft/issues/316), [#210](https://github.com/storytold/anicraft/issues/210)), a run in a real browser in CI | Preferences, platforms | M | | platform |