Repository navigation
Add memo_on for caching a section by an explicit input - #96
Merged
Merged
Conversation
memo_on(input, f) caches the layout and accessibility nodes of the view f builds from input. f is a function pointer, so input is the only data that reaches it from the views around it. Inside a memo_on, writes to the enclosing states don't invalidate anything unless input changed; reads of states above it through handles in the input count as foreign reads, so they're still followed. StateHandle gets PartialEq so a handle can be part of an input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A list caches each item on the item's node, whatever its root. With a memo_on at an item's root, the list overwrote the memo_on's cache there with reads filtered for the list, which dropped reads of enclosing states through handles in the input, and with a stamp older than the input's generation. memo_on now keeps its input and cached results on its child node and builds its view under that one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The orders card was a memo reading the whole App state, so every write to it, such as a live update tick every 100 ms, laid the card out again and made the list compare all its keys. The card is now a memo_on of what it shows (the rows, the shown ids, the sort), so those writes leave it alone. profile_hover gets a tick case for such a write: 0.49 ms to 0.018 ms per update with 1M rows, 0.061 ms to 0.017 ms with 3000. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A list inside a memo_on now keeps its keys without comparing them when the memo_on's input, the states its last layout read from outside it, and everything under it but the list's items are unchanged since the list was synced in that layout. In gui_bench with 1M rows, the hover event after a live update tick drops from 0.41 ms to 0.0075 ms. Also from review: - The list's written-items check ignores reads above the memo_on. - memo_on's input must be Eq, so a NaN can't make it miss every walk. - A new input seen after layout sets dirty, so a layout follows. - profile_hover gets a hover_tick case; the README lists tick and hover_tick. - Tests for the redraw on a new input and the anim pass in memo_on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wtholliday
added a commit
to audulus/gui-bench
that referenced
this pull request
Nov 28, 2026
rui's memo-on branch (audulus/rui#96) is main after audulus/rui#95, which caches each list item and adds memo, plus memo_on. The app is synced with rui's examples/gui_bench: the orders card is a memo_on of what it shows, so a live update's write to the app state no longer lays it out or makes the list compare all its keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
memo_on(input, f)caches the layout and accessibility nodes of the viewfbuilds frominput, apart from whatever the enclosing views read.fis a function pointer, soinputis the only data that reaches it from the views around it; anything else it uses comes through theContext, whose reads are tracked. A write to an enclosing state leaves it alone unlessinputchanged, even when the enclosing function read that whole state.How it works
Eq) and the function's address are kept on a child node of thememo_on, so a list caching an item on the item's node can't overwrite them. A different input or function bumpswrite_genwithout writing anything, making the results cached under it stale, and sets dirty.memo_on,ancestor_genstarts at the input's generation, and a read of a state above it (through a handle in the input, say) is a foreign read, so it's still followed.memo_ondon't depend on what was read above it: the written-items check skips those reads, and the key sync keeps the keys without comparing them when nothing thememo_ondepends on changed and every write under it was in the list's items.StateHandlegetsPartialEq/Eq(by id), so a handle can be part of an input.gui_bench
The orders card is now a
memo_onof what it shows (the rows, the shown ids by pointer, the sort).profile_hovergetstick(a live update's write to the app state) andhover_tickcases. Per update, release build:idle,hoverandinvalidate_allare unchanged. The gui-bench repo's copy of the app (apps/rui) still has the old orders card.Tests
Unit tests in
src/node_tests.rscover: writes the input doesn't see, a new input, an enclosing state read through a handle in the input (directly and from a nestedstate), writes under it, accessibility, amemo_onas a list item root, switching functions, lists inside it (written items only, keys kept, keys from the input or a state under it), the redraw on a new input, the anim pass, and a new input first seen after layout. The boundary checks were mutation-tested: removing each makes a test fail. The app hasn't been run in a window.🤖 Generated with Claude Code