Vixen
dd8b0a81
csharp
public readonly record struct StyleSharingKey

What makes two elements able to share one ComputedStyle.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

⚠ The parent is the parent element, not the parent's computed style. [Doc 09](../../docs/plan/09-ui-framework.md) specifies the key as (tag, class set, inline style, parent computed style, pseudo state) and that is not sound. Two parents can hold the same computed style and still be told apart by a selector: given .a { color: red } and .b { color: red }, an .a and a .b intern to one identical style — and then .a .row { color: blue } matches one of their children and not the other's. Keyed on the parent style, both children share, and one of them is wrong.

Keyed on the parent element, sharing happens between siblings, and every descendant and child combinator is sound for free because the two elements have literally the same ancestor chain. This is what Gecko does and for this reason.

It is a narrower key, and the thing worth being clear about is what that does and does not cost. Interning is what gives every identical grid cell the same ComputedStyle reference, and it is unaffected: ten thousand cells across a thousand rows still hold one object, so the reference-compared invalidation doc 09 is really after still works. Sharing is what lets the cascade be skipped, and that now happens per row rather than per grid. Cheaper than being wrong.

What the key still cannot carry is where an element sits among its siblings, or what its attributes are — which is what SharingIsSound is for.

⚠ The media scope is in the key even though the parent very nearly makes it redundant, and the exception is exactly the case per-surface media exists for. Two elements with the same parent are in the same surface by construction, so for every ordinary element the scope adds nothing. Surface roots are the elements that break it: UiDocument.CreateSurface hangs them all off one owner, and two torn-off windows are then the same tag with no id and no classes under the same parent — the perfect sharing key, for two elements whose whole difference is which window's breakpoints they answer. One integer, and the case it covers is the headline feature.

Fields and properties (9)

  • public StyleNodeId Parent

    The parent element. See the remarks — this is not what doc 09 says.

  • public int Tag

    The element's interned tag name.

  • public int Id

    Its interned id, or None.

  • public int ClassHash

    An order-independent hash of its class list.

  • public int ClassCount

    How many classes it has, so a hash collision needs a second coincidence.

  • public ElementState State

    Its pseudo state.

  • public InlineStyleId? Inline

    A handle on its inline declarations.

  • public int Scope

    Which surface's @media answers it reads.

  • public int Container

    Which container chain's @container answers it reads. ⚠ Not redundant with the parent, and the case is the ordinary one rather than an edge case. Two siblings are in the same container by construction — but a scope is interned on the chain's boxes (see ContainerScopes), so two rows of a list that happen to be the same width get the same id and share, and the moment one of them holds a container that has resized they do not. Leaving it out would let a row keep the style it computed at the other width.

Methods (1)

  • public StyleSharingKey(StyleNodeId Parent, int Tag, int Id, int ClassHash, int ClassCount, ElementState State, InlineStyleId? Inline, int Scope, int Container)

    What makes two elements able to share one ComputedStyle.

Used by (1)

  • StyleResolverVixen.Ui.Styling