Expand description
CSS property cache for efficient per-node style resolution. CSS property cache for efficient style resolution and animation.
This module implements a cache layer between the raw CSS stylesheet and the rendered DOM. It resolves CSS properties for each node, handling:
- Cascade resolution: Computes final values from CSS rules, inline styles, and inheritance
- Pseudo-class states: Caches styles for
:hover,:active,:focus, etc. - Animation support: Tracks animating properties for smooth interpolation
- Performance: Avoids re-parsing and re-resolving unchanged properties
§Architecture
The cache is organized per-node and per-property-type. Each property has a dedicated getter method that:
- Checks if the property is cached
- If not, resolves it from CSS rules + inline styles
- Caches the result for subsequent frames
§Thread Safety
Not thread-safe. Each window has its own cache instance.
Structs§
- CssProperty
Cache - CssProperty
Cache Breakdown - Heap-size breakdown of a
CssPropertyCache, produced byCssPropertyCache::memory_breakdown. All values in bytes. - CssProperty
Cache Ptr - CssProperty
With Origin - A CSS property with its origin tracking.
- Flat
VecVec - A flat, cache-friendly replacement for
Vec<Vec<T>>. - Stateful
CssProperty - A CSS property tagged with its pseudo-state and property type.
Replaces the per-pseudo-state BTreeMap approach: instead of 6 BTreeMaps
per node (Normal/Hover/Active/Focus/Dragging/DragOver), we store one Vec
per node and tag each property with its state. Lookups use
.iter().find().
Enums§
- CssProperty
Origin - Tracks the origin of a CSS property value. Used to correctly implement the CSS cascade and inheritance rules.
Functions§
- drain_
css_ prop_ counts - Drain the per-thread CSS cascade-walk counter populated by
CssPropertyCache::get_propertywhenAZ_PROP_COUNT=1is set in the environment. Returns(property_label, count)pairs sorted by count descending. Layout-side instrumentation calls this after eachlayout_documentto print which properties drove the most cascade walks.