Skip to content

fix(rune-kit): display math wakes and rebuilds only what a finished render changes - #1317

Merged
Hona merged 2 commits into
devfrom
ws3/math-rest-loop
Nov 21, 2026
Merged

Hona merged 2 commits into
devfrom
ws3/math-rest-loop

Conversation

@Hona

@Hona Hona commented Nov 21, 2026

Copy link
Copy Markdown
Member

Display math no longer wakes and rebuilds every math row each time any equation finishes. It rebuilds only the row that drew that equation, and the cache never evicts what is on screen or still rendering.

What was wrong (READER-11, notes/review-rd-session.md)

  • A finished render bumped one process-wide GENERATION. Every math row (rune-desktop's timeline/mod.rs) and every settled Markdown block holding math (markdown/memo.rs) put it in its memo key.
  • Past the cache's caps (128 entries, 8 MiB; a wide equation at 1.5x is 2.6-3.1 MB), finishing equation N evicted equation 1. Every math row then rebuilt, the evicted equation missed, rendered again, evicted the next one, and so on.
  • set_waker kept one global waker: a second window took the first window's wake. rest() cleared every window's bitmaps whenever any window rested.

What it does now

  • Per row: math::collect(key, build) notes the sources a row drew while they were still rendering, and math::version(key) moves only when one of those finishes. Eviction never moves a version and never wakes anyone. A row showing a bitmap keeps its pixels; only a row that builds again asks for it anew.
  • Eviction: what is still rendering, and what the last 16 commits drew or finished, is never evicted. The caps (256 entries, 32 MiB) bound only what no view shows.
  • Full worker queue: a refused render waits its turn (up to 1,024) instead of showing code until something else happens to rebuild the row.
  • math::Client, one per window: its own waker and its own seen state. changed() returns true once per batch of finishes, for the host's poll. rest() clears bitmaps only once every window rests, and hold() undoes it.
  • Markdown: a block holding display math no longer memoises, so each row build asks the cache. The equation's own element is still memoised (settled_math_card_digest).
  • API: math::set_waker, math::generation and math::rest are removed. Client, collect and version replace them. rune-desktop is the only user, and its PR follows.

Measured (rune-desktop with this change, --profile perf, not PGO: not gate numbers; blade, Intel Iris Xe, 240 Hz, 1.5x)

Fixture session, 15 s after opening, CPU (µs) and thread wakes per 5 s at rest, two rounds:

Session Before (dev d525338c) After
200 display equations in two replies 445,520 / 6,105 µs first sample; most equations still raw LaTeX 14,878–16,994 first sample, then 5,091–5,801 µs; all rendered
The same replies with the fences as text 16,832–23,829 µs first sample 22,852–28,042 µs first sample
8 wide equations (2.6-3.1 MB each, about 23 MB in total) 130,644–160,794 µs first sample 13,762–14,180 µs first sample

Not proved here

  • The published-build spin REFERENCE measured (50 equations, 6,484 ms of CPU per 5 s on dev-459): rune-desktop's PR carries the re-measure.
  • No tests were added or changed.

Checks

  • tools/cargo.ps1 check -p rune-kit --features markdown,math --all-targets (farm): clean, on e9d3159e and on the merge with dev (8283dca5).
  • cargo check --target wasm32-unknown-unknown -p rune-kit --features markdown,math (farm): clean on e9d3159e.

Hona added 2 commits November 21, 2026 18:04
…ender changes

A finished render bumped one process-global generation that every math row and block put in its memo key, and woke one global waker. Past the cache's caps, finishing equation N evicted equation 1, every math row rebuilt, the evicted one missed and rendered again, and so on. A second window took the first one's waker, and any window at rest cleared every window's bitmaps.

- Per row: math::collect notes the sources a row drew while they were still rendering, and math::version moves only when one of those finishes. Eviction never moves a version or wakes anyone.
- The cache never evicts what is still rendering or what the last 16 commits drew; the caps (256 entries, 32 MiB) bound only what no view shows.
- A full worker queue keeps the render waiting (up to 1,024) instead of showing code until something else rebuilds.
- math::Client per window: its own waker and seen state; Client::rest clears bitmaps only once every window rests.
- Markdown blocks holding display math no longer memoise (the equation's own element still does), so each row build asks the cache.
@Hona
Hona merged commit b39e1b4 into dev Nov 21, 2026
1 check passed
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