chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
---
title: Memory
section: Operations
order: 101
summary: What HUD holds in memory and how to measure it.
---
What HUD holds is bounded by what's on screen. What's open doesn't grow it.
## Server
Every in-memory cache is bounded by entries and by bytes. `HUD_CACHE_MEMORY_BYTES` is shared out like this:
- joins' records get nine 32nds
- lexicons get three sixteenths
- DID documents and queries' answers get an eighth each
- counts get five 32nds
- the rest get a 32nd each
HUD weighs each value as it keeps it. It doesn't keep a value that weighs more than a quarter of its cache's share.
HUD keeps audio and video on disk (`HUD_BLOB_CACHE_BYTES`). It streams images through and never holds them whole. Sign-in's pending requests and client documents are capped by count.
`hud serve` logs each cache's entries and bytes as it stops (`caches at shutdown`).
## Workspace
A tile keeps what it read, and never makes it deeply reactive. It draws it only while its column is within a screen's width of what's in view on the tab on screen. Farther away, or on a tab out of sight, the tile's body is empty and its scroll is kept. As it comes near, the tile draws again from what it read, without asking again. The iOS app keeps a tile's scroll the same way when its view is made again, as switching canvases does (iOS 18 and later).
A player's music goes on in the page's one `<audio>`, apart from the tiles. It holds only the tracks it plays. A video, or an audio field, stops as its tile stops drawing.
## Renderer
A long list (rows or cards, past 24 items) draws only the items within two screens of its scroller's view. It draws each item as it comes that near, using an IntersectionObserver and never reading where items are while scrolling. Once scrolling stops, it lets go of items past four screens and holds each at its measured height. The browser skips drawing those out of view (`content-visibility`).
In a frame (the MCP App's view), a list draws every item and the browser draws them all. A frame from another origin isn't told where its host's screen is, so either technique would leave posts blank as they scroll in.
The renderer keeps what a person did to an item (a like, a warning seen through, a text opened) by the item's data. So it draws the item again as it was.
A picture drawn small (an avatar, a gallery's tile, a link card's thumbnail) loads a blob's `thumb`, which is the image CDN's thumbnail (128 px for an avatar). A trusted view's `thumbnails` load the AppView's avatars as their CDN's thumbnails. Both load these instead of full size. Pictures load lazily and decode off the main thread. Video and audio load nothing until played.
An app's clients (Grain's) keep the last skeleton of each screen, up to 40, the least recently drawn let go first ([while a screen loads](views.md#while-a-screen-loads)). A skeleton is the tree's shape alone, with a list's first few items. Grain's feed's is ~4 KB as JSON and a gallery's ~1 KB (measured), so all 40 stay well under 200 KB.
HUDKit's last trees (`LastTree`, [while a screen loads](views.md#while-a-screen-loads)) are limited to 40 and to 8 MB of JSON in all, the least recently used let go first. They're held in memory alone, so none outlive the app.
## Measuring
- `just memory [label]` runs a session against the release build (harness/e2e/memory.spec.mjs). It prints per stage the page's heap, DOM nodes, pictures and image memory, and the server's RSS.
- `just scroll` measures a long feed scrolled in a column (harness/scroll.mjs). It reports long tasks, layouts, frame times, blank frames, heap and nodes.