Note: There are a few cases of duplicates in user autocompletion which are being worked on.

stylo: Consider preloading the style sharing cache with styled siblings during incremental restyle

NEW
Unassigned

Status

()

Core
CSS Parsing and Computation
P2
normal
2 months ago
a month ago

People

(Reporter: bholley, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

During today's call, bz pointed out that the style sharing cache only works within a single traversal, so sharing will progressively decrease (and memory usage will progressively increase) over successive restyle generations.

An obvious solution to this is just to insert styled siblings into the cache when we determine that they don't need any other processing. The key point is that our reliance on flags set by rust-selectors to determine whether to put something in the cache is gone after [1]. There's still AFFECTED_BY_PSEUDO_ELEMENTS, but we can determine whether a style has pseudos by just examining the ElementStyes, and that check will go away anyway in bug 1369952. So this means that the cost of insertion is just the refcounting overhead of sticking the ComputedStyle in the cache.

We'd want to be careful to only insert elements with a different ComputedValues identity from anything already in-cache (so that we don't insert 50 entries for 50 siblings that all shared styles). And even then, we'd want to measure how this impacts traversal time over elements that don't need styling (i.e. what happens if we post a RESTYLE_SELF to some single leaf element deep in a tree with 10k elements).

[1] https://github.com/servo/servo/pull/17055
(In reply to Bobby Holley (:bholley) (busy with Stylo) from comment #0)
> We'd want to be careful to only insert elements with a different
> ComputedValues identity from anything already in-cache (so that we don't
> insert 50 entries for 50 siblings that all shared styles).

Oh, and we can implement this cheaply by storing a raw/opaque ComputedValues pointer (for comparison purposes only) in the style sharing cache alongside the element. This allows us to check against previous values without either borrowing their element data or storing strong ComputedValues pointers in the cache (either of which would cost an atomic operation).
Priority: -- → P2
You need to log in before you can comment on or make changes to this bug.