Skip to main content

Module cache

Module cache 

Source
Expand description

Layout memoization keyed by (WidgetId, input Size, content hash).

Re-laying out an unchanged subtree every frame is wasteful. LayoutCache stores the computed Rect for a node keyed by the inputs that determine it: the node’s WidgetId, the available Size it was laid out into, and a u64 content hash the caller supplies (a digest of whatever else affects the result — text, font, child sizes, …). A lookup hits only when all three match, so any change in available space or content misses and recomputes.

Entries can also be invalidated explicitly via a per-node dirty flag, which a tree mutation (resize, child add/remove) sets. The cache tracks hit and miss counts so callers can measure effectiveness.

f32 sizes are not Hash/Eq, so the size is quantised to its raw bits (to_bits) for the key; this treats 0.0 and -0.0 as equal and is exact for finite values, which is what we want for cache identity.

Structs§

LayoutCache
A memoizing cache of computed layout rectangles.