pub struct LayoutCache {
pub tree: Option<LayoutTree>,
pub calculated_positions: PositionVec,
pub viewport: Option<LogicalRect>,
pub scroll_ids: HashMap<usize, u64>,
pub scroll_id_to_node_id: HashMap<u64, NodeId>,
pub counters: HashMap<(usize, String), i32>,
pub float_cache: HashMap<usize, FloatingContext>,
pub cache_map: LayoutCacheMap,
pub previous_positions: PositionVec,
pub cached_display_list: Option<(SubtreeHash, LogicalRect, DisplayList)>,
pub prev_dom_ptr: usize,
pub prev_viewport: LogicalRect,
}Expand description
The persistent cache that holds the layout state between frames.
Fields§
§tree: Option<LayoutTree>The fully laid-out tree from the previous frame. This is our primary cache.
calculated_positions: PositionVecThe final, absolute positions of all nodes from the previous frame.
viewport: Option<LogicalRect>The viewport size from the last layout pass, used to detect resizes.
scroll_ids: HashMap<usize, u64>Stable scroll IDs computed from node_data_hash (layout index -> scroll ID)
scroll_id_to_node_id: HashMap<u64, NodeId>Mapping from scroll ID to DOM NodeId for hit testing
counters: HashMap<(usize, String), i32>CSS counter values for each node and counter name.
Key: (layout_index, counter_name), Value: counter value
This stores the computed counter values after processing counter-reset and
counter-increment.
float_cache: HashMap<usize, FloatingContext>Cache of positioned floats for each BFC node (layout_index -> FloatingContext).
This persists float positions across multiple layout passes, ensuring IFC
children always have access to correct float exclusions even when layout is
recalculated.
cache_map: LayoutCacheMapPer-node multi-slot cache (inspired by Taffy’s 9+1 architecture).
External to LayoutTree — indexed by node index for O(1) lookup.
Persists across frames; resized after reconciliation.
previous_positions: PositionVecSnapshot of calculated_positions from the previous frame, used by the
compositor to compute damage rects (old bounds vs new bounds).
cached_display_list: Option<(SubtreeHash, LogicalRect, DisplayList)>Cached display list keyed by (root_subtree_hash, viewport).
When the reconciled tree has the same root subtree_hash AND
the same viewport as the cached one, the display list is
returned as-is — skipping layout, positioning, and
display-list generation entirely. Cleared whenever
mark_dirty fires on any node (since the root’s upstream
invalidation chain clears its ancestors).
prev_dom_ptr: usizeRaw pointer of the StyledDom from the previous layout pass. When the
same &StyledDom reference is passed again AND the viewport is unchanged,
skip reconcile entirely and return the cached display list (saves ~0.8 ms).
prev_viewport: LogicalRectImplementations§
Source§impl LayoutCache
impl LayoutCache
Sourcepub fn reset_incremental(&mut self)
pub fn reset_incremental(&mut self)
Drop all incremental-reuse state so the next layout_document lays the
DOM out from scratch (cold path), as if no previous frame existed.
Required before laying out a DOM whose NodeIds are NOT a stable evolution
of whatever this (shared) cache last held — namely VirtualView / iframe
child DOMs, which their callbacks rebuild wholesale on every invocation.
Incremental reconciliation matches/reuses subtrees by NodeId + subtree
hash; on a wholesale rebuild those NodeIds are reassigned, so reusing the
prior tree can graft NodeIds that no longer exist in the new StyledDom
(panic: out-of-bounds node_data index when the DOM shrinks — e.g. the map
dropping tiles on zoom-out).
Sourcepub fn memory_report(&self) -> Solver3CacheMemoryReport
pub fn memory_report(&self) -> Solver3CacheMemoryReport
Approximate heap bytes retained by this LayoutCache.
Trait Implementations§
Source§impl Clone for LayoutCache
impl Clone for LayoutCache
Source§fn clone(&self) -> LayoutCache
fn clone(&self) -> LayoutCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LayoutCache
impl Debug for LayoutCache
Source§impl Default for LayoutCache
impl Default for LayoutCache
Source§fn default() -> LayoutCache
fn default() -> LayoutCache
Auto Trait Implementations§
impl !RefUnwindSafe for LayoutCache
impl !UnwindSafe for LayoutCache
impl Freeze for LayoutCache
impl Send for LayoutCache
impl Sync for LayoutCache
impl Unpin for LayoutCache
impl UnsafeUnpin for LayoutCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more