Skip to content

css: Respect @layer priority#2983

Merged
karlseguin merged 1 commit into
mainfrom
layer-ordering
Jul 24, 2026
Merged

css: Respect @layer priority#2983
karlseguin merged 1 commit into
mainfrom
layer-ordering

Conversation

@karlseguin

Copy link
Copy Markdown
Collaborator

Builds ontop of #2719 and adds the missing layer-priority.

This can be broken down into two parts. The first is the hot read path. This code is unchanged...same buckets and same u64 priority comparison.

What has changed is the build/rebuild step and how / what the VisibilityRule.priority means. priority used to be 32bits for specificity and 32bits for doc order (specificity tie-breaker). Priority is now 12bits for layer rank, 30bits for specificity and 22bits for doc order. Specificity was only using 30bits, and the smaller doc order means we can now only represent 4 million rules (Facebook, which has a lot of rules, has ~50K and like 95% of those are not visibility rules..so we have plenty of space still).

But layer ordering is complicated because you need to parse everything before you know the final order. So our build now accumulates intermediary results and does a final iteration through the VisibilityRule to |= the rank_layer bits of their priority. This is no-op if there are no layers (common case for now). Because of this intermediary work, I've added a build_arena that is build/ rebuild specific. Possibly overkill since we don't expect sites to have thousands of layers, but it's cheap to add (except now you need to think: should I use the build_arena or self.arena).

Builds ontop of #2719 and adds
the missing layer-priority.

This can be broken down into two parts. The first is the hot read path. This
code is unchanged...same buckets and same u64 priority comparison.

What has changed is the build/rebuild step and how / what the
VisibilityRule.priority means. priority used to be 32bits for specificity and
32bits for doc order (specificity tie-breaker). Priority is now 12bits for
layer rank, 30bits for specificity and 22bits for doc order. Specificity was
only using 30bits, and the smaller doc order means we can now only represent
4 million rules (Facebook, which has _a lot_ of rules, has ~50K and like 95% of
those are not visibility rules..so we have plenty of space still).

But layer ordering is complicated because you need to parse everything before
you know the final order. So our build now accumulates intermediary results and
does a final iteration through the VisibilityRule to |= the rank_layer bits of
their priority. This is no-op if there are no layers (common case for now).
Because of this intermediary work, I've added a build_arena that is build/
rebuild specific. Possibly overkill since we don't expect sites to have
thousands of layers, but it's cheap to add (except now you need to think: should
I use the build_arena or self.arena).
@krichprollsch
krichprollsch requested a review from arrufat July 20, 2026 10:49
@karlseguin
karlseguin merged commit 76e2e7e into main Jul 24, 2026
24 checks passed
@karlseguin
karlseguin deleted the layer-ordering branch July 24, 2026 00:03
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant