Skip to content

The window's memory: UI trees kept only for a reader, once per run; the page's code handed over once - #185

Merged
shinyobjectz merged 1 commit into
mainfrom
window-trees
Nov 18, 2026
Merged

shinyobjectz merged 1 commit into
mainfrom
window-trees

Conversation

@shinyobjectz

@shinyobjectz shinyobjectz commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Why. raea's window ran at about 3 GB. This is the last of three pieces; the others are #184 (pictures decoded at the size their URL asks) and shinyobjectz/raea-feed#97 (the feed asks for that size and lets far cards go).

The finding. A malloc stack log of the window at the end of a 120-card feed (raea-feed's e2e/memory.spec.ts, MEM_STACKS) put 315 MB of the live heap in tree::answer. Every frame, the page host built the UI tree and kept the last 240 copies (TREES) for the MCP ui tool. That happened in the person's app too, where the MCP server is off (RAEA_PAGE_MCP_PORT=0) and nothing reads them. A tree grows with the page, so in a long feed this looked like each card costing 2.9 MB.

Changes

  • tree.rs. Trees are kept only once the MCP server serves (KEEP, set in mcp::serve). LATEST, which BRP's ui method reads, is unchanged.
  • Frames the MCP reader was handed already (SEEN, moved here from mcp.rs) are let go, since its next ask is always for a later frame.
  • Frames in a row with the same tree are kept once as a run (Kept). tree_after hands out what frame N showed, with frame N, so readers get exactly what they got before.
  • main.rs. The page's code goes to the mount once instead of being cloned and kept for the process's life. The feed's bundle is 21 to 26 MB.

Size. The crate stays under tools/size.sh's 2000-line limit (1992).

Measured. raea-feed's memory spec, 60 stills of 2560×1440, with all three PRs:

Stage 0.1.8-rc3 Now
Feed open 1131 MB 757 MB
End of feed 2032 MB 904 MB
Back at the top 2049 MB 918 MB
After opening and closing 8 items 2526 MB 1317 MB

At 120 stills the end of the feed is 1019 MB. Before this PR it was 1294 MB with the other two fixes in.

Tests. cargo test --release -p raea-page-host --features window --lib tree::: two tests covering

  • a run of identical frames kept once and handed out frame by frame;
  • what was handed out let go;
  • a run part-way through kept;
  • the 240 cap.

The memory spec drives the page host through MCP throughout, so it also exercised the ui tool's frame-in-turn reads on this build.

🤖 Generated with Claude Code

…he page's code handed over once

raea's page host kept the last 240 frames' UI trees (tree.rs TREES) for the MCP ui tool. It did that in the person's
app too, where the MCP server is off and nothing reads them: 315 MB of serde_json trees with a feed of 120 cards open,
found by MallocStackLogging in raea-feed's e2e/memory.spec.ts (MEM_STACKS).

- The trees are kept only once the MCP server serves (tree::KEEP, set by mcp::serve). LATEST, which BRP's ui method
  reads, is kept as before.
- The frames the MCP reader was handed already (tree::SEEN) are let go: its next ask is always for a later frame.
- Frames in a row whose trees are the same are kept once, with their first frame, and handed out as each frame. A page
  at rest is one tree however long it rests, and every reader gets what it got before.

The page host's main also hands the page's code to the mount once instead of keeping it for the app's whole life: the
feed's bundle is 21 to 26 MB.

raea-feed's memory spec, 60 stills of 2560x1440, with raea #184 and raea-feed #97:

| Stage | 0.1.8-rc3 | Now |
|---|---|---|
| Feed open | 1131 MB | 757 MB |
| End of feed | 2032 MB | 904 MB |
| After opening items | 2526 MB | 1317 MB |

Unit tests (tree::tests) cover:
- a run handed out frame by frame;
- what was handed out let go;
- a run part-way through kept;
- the 240 cap.
@shinyobjectz
shinyobjectz merged commit 12870b2 into main Nov 18, 2026
4 checks 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