View Evaluation and Memoization
Build owned candidate descriptions and reuse eligible subtrees without confusing evaluation with drawing.
A scheduled Kit update normally starts evaluation at the root and builds a candidate description of the interface. Explicit memo wrappers can reuse eligible subtrees during that traversal. Reading state alone does not yet create an independently scheduled body computation for every view.
View Body Evaluation
Evaluation enters through an internal build hook that establishes the view's concrete type scope and creates its ViewContext. The hook invokes the authored body, recursively builds the returned description, and attaches its mounted values and inherited environment to the resulting client node.
Backend primitives implement lower-level construction directly. Application views use View::body, view_fn, or #[view]; the macro changes syntax rather than introducing another runtime lifecycle.
Candidate Input Ownership
A candidate tree includes scene properties, layout descriptions, callbacks, environment scopes, and mounted values. Callbacks can outlive a body invocation, so returned descriptions must own their inputs rather than borrow temporary body data.
Keep bodies free of I/O and external side effects. Evaluation can repeat, be skipped through memo reuse, or produce a candidate that the server rejects.
Memo Dependencies
While a .memo(key, props) subtree is being evaluated, the runtime records the attributes and environment mappings that it reads. A later traversal can reuse the subtree if both the explicit props and those recorded dependencies remain unchanged, avoiding eligible body construction.
For environment reads, a value revision alone is insufficient because a nearer provider can change which attribute a key resolves to. Tracking therefore includes the key-to-attribute mapping as well as revisions. Equal providers at the same path can reuse their leases, while a changed provider or object identity can invalidate the cached result.
Nonreactive Inputs
If a closure captures an ordinary changing value, include it in memo props. The runtime cannot discover changes to plain fields that were never observed through state or environment tracking.
The distinction between bindings and plain captures also affects what a cached description or accepted action can observe. A captured binding continues to access live state, while a captured ordinary value remains the snapshot taken during evaluation. Include changes to those ordinary inputs in memo props so the cache can respond to them.
Memoization Costs and Remaining Work
Reusing a subtree saves eligible body construction, but the tree still needs layout synchronization and reconciliation. Conversely, evaluating a body can produce no wire changes, and a small wire diff can still cause substantial GPU work. Performance measurements need to distinguish those phases before attributing a saving to memoization.
Use performance measurement to attribute cost to the correct phase.
Source Reference
The following files in the Hera checkout define the behavior described on this page.
crates/kit/src/view/mod.rscrates/kit/src/view/modifiers.rscrates/kit/src/ag/reactive.rscrates/kit/src/app/mod.rs