Skip to content

fix(memo): flatten-reuse memos holding LiveText without reshaping unchanged values - #2105

Merged
Hona merged 1 commit into
devfrom
fix/2084-memo-reuse-live-text
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
fix/2084-memo-reuse-live-text

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Refs #2084

Root cause

  • el_flatten_reusable in crates/rune/src/memo/built.rs required t.cold.live.is_none(), preventing any memo holding a LiveText from flatten-reusing its nodes across commits. Every unrelated commit rebuilt the memo's static tags and containers with fresh paint epochs, leaving PaintKeep with 0 copied nodes on commit frames.
  • try_reuse_memo (crates/rune/src/runtime/commit/memo_reuse.rs), relayout, and remount also cleared text_layout: None and elided: None on reused nodes, which would cause solve to re-shape latched LiveText content into the shared commit layout cache during commit and then shape again in latch_live.

What changed

  • crates/rune/src/memo/built.rs: removed t.cold.live.is_none() from el_flatten_reusable.
  • crates/rune/src/runtime/commit/memo_reuse.rs, relayout.rs, remount.rs: preserved text_layout and elided across reuse for LiveText nodes.
  • crates/rune/src/runtime/commit/relayout.rs, measure.rs, remount.rs: passed reused spans into Measurement::solve. For reused LiveText nodes whose layout is still valid (not width-sensitive, or unchanged content width at the same scale), solve skips lay_out_text; when width changes or layout was cleared, latched LiveText nodes re-lay out via lay_out_text_inner(..., true) and bump node.epoch without polluting the commit layout or elision caches.
  • crates/rune/src/runtime/commit/text_layout.rs: in compute_layout, reused non-wrapped un-elided LiveText layouts directly and routed latched LiveText measurement through layout_live_spec.
  • crates/rune/src/runtime/memo_reuse_live_text_tests.rs: added regression tests covering flatten reuse, static sibling epoch preservation, single-shape tick commits, wrapped/truncated/clamped same-width reuse, container resize relayout, rebased (!same_path) reuse, and accessibility tree parity.
  • changelog/unreleased/2026-11-25-memo-reuse-live-text.md: changelog entry.

Headless --profile perf measurement (500 LiveText cells, 5 paired alternating runs, 240 frames)

Headless Runtime CPU only (excludes GPU upload and presentation); measured against baseline without Part 2 to isolate Part 1.

Tick (commit) frame Before After
Nodes copied (RUNE_PAINT_KEEP_LOG=1) 0 / 1,537 (1,028 rebuilt) 500 / 1,537 (2 rebuilt)
Texts shaped p50 500 500
Paint CPU p50 (median of 5 pairs) 6.640 ms 5.791 ms
Text CPU p50 (median of 5 pairs) 5.132 ms 4.473 ms
Frame CPU p50 (median of 5 pairs) 16.372 ms 13.424 ms

Verification

  • Windows: cargo test -p rune --lib -- memo_reuse memo::tests relayout remount live_latch live_text (93 passed, 0 failed).
  • scripts/file-size.sh: 0 errors.
  • macOS arm64 (on top of dev including fix(paint): allow paint keep to copy unchanged LiveText nodes across frames #2094): cargo test -p rune --lib -- memo_reuse::live_text_tests runtime::paint::keep (3 passed, 0 failed) and cargo clippy -p rune --lib --bins --tests (0 errors).
  • Linux aarch64: cargo check -p rune -p rune-kit --tests (exit 0).
  • Not checked on this machine: interactive window / GPU presentation (headless runtime only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant