Skip to content

LibWeb: Hand layout a Rust-owned style container instead of a mirror - #10945

Merged
kalenikaliaksandr merged 1 commit into
LadybirdBrowser:masterfrom
kalenikaliaksandr:avoid-groups-copy
Jul 31, 2026
Merged

LibWeb: Hand layout a Rust-owned style container instead of a mirror#10945
kalenikaliaksandr merged 1 commit into
LadybirdBrowser:masterfrom
kalenikaliaksandr:avoid-groups-copy

Conversation

@kalenikaliaksandr

Copy link
Copy Markdown
Member

Layout read style through a per-node side table in the node arena that mirrored all 23 group payload pointers, copied out of ComputedValues on every style application. The mirror was 184 bytes per node of duplicated pointers whose validity rested on the rewrite-on-set protocol alone: nothing owned the payloads on the Rust side, and the generation-keyed side table existed only to keep stale copies from being read after slot reuse.

Every built ComputedValues now lazily creates a style container on first request: a Rust-owned refcounted allocation, using the same header-before-payload scheme as the group payloads themselves, holding the group pointer array and retaining every group. NodeData.style points at the container's array, which the layout side reads in place as the payload array, so style application shrinks to publishing one pointer and the side table, its generation keying, and the per-set 23-pointer copy are deleted. The container is created after group adoption has settled (adopt_identical_group_payloads now asserts it runs first) and released with its ComputedValues, making payload ownership explicit where the mirror only had it by protocol. It also gives the style a single identity usable for future retention from paintables and for input-keyed layout caching.

Layout read style through a per-node side table in the node arena that
mirrored all 23 group payload pointers, copied out of ComputedValues on
every style application. The mirror was 184 bytes per node of duplicated
pointers whose validity rested on the rewrite-on-set protocol alone:
nothing owned the payloads on the Rust side, and the generation-keyed
side table existed only to keep stale copies from being read after slot
reuse.

Every built ComputedValues now lazily creates a style container on
first request: a Rust-owned refcounted allocation, using the same
header-before-payload scheme as the group payloads themselves, holding
the group pointer array and retaining every group. NodeData.style
points at the container's array, which the layout side reads in place
as the payload array, so style application shrinks to publishing one
pointer and the side table, its generation keying, and the per-set
23-pointer copy are deleted. The container is created after group
adoption has settled (adopt_identical_group_payloads now asserts it
runs first) and released with its ComputedValues, making payload
ownership explicit where the mirror only had it by protocol. It also
gives the style a single identity usable for future retention from
paintables and for input-keyed layout caching.
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 88a9a328-19c6-461f-a8bf-b52b16867c8a

📥 Commits

Reviewing files that changed from the base of the PR and between 6e068c8 and b72d5a3.

📒 Files selected for processing (9)
  • Libraries/LibWeb/CSS/ComputedProperties.cpp
  • Libraries/LibWeb/CSS/ComputedValues.cpp
  • Libraries/LibWeb/CSS/ComputedValues.h
  • Libraries/LibWeb/Layout/Node.cpp
  • Libraries/LibWeb/Layout/Node.h
  • Libraries/LibWeb/Rust/src/css/computed_values.rs
  • Libraries/LibWeb/Rust/src/layout/formatting_context.rs
  • Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
  • Libraries/LibWeb/Rust/src/layout/node_data.rs

📝 Walkthrough

Walkthrough

Changes

Style container migration

Layer / File(s) Summary
Style container lifecycle
Libraries/LibWeb/CSS/ComputedValues.*, Libraries/LibWeb/CSS/ComputedProperties.cpp, Libraries/LibWeb/Rust/src/css/computed_values.rs
ComputedValues lazily creates and caches a Rust style container. Rust retains and releases group payloads through reference counting.
Node style publication
Libraries/LibWeb/Layout/Node.*
Node construction and computed-style updates publish the style container to node data.
Layout container consumption
Libraries/LibWeb/Rust/src/layout/*
Layout reads payloads from the published node style pointer. The layout arena no longer maintains a payload side table.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ComputedValues
  participant NodeData
  participant LayoutNodeArena
  participant FormattingContext
  ComputedValues->>ComputedValues: create and cache style container
  ComputedValues->>NodeData: publish style container
  FormattingContext->>LayoutNodeArena: request style payloads
  LayoutNodeArena->>NodeData: read published style pointer
  NodeData-->>FormattingContext: return style payload array
Loading

Possibly related PRs

Suggested reviewers: awesomekling

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description accurately explains the style-container ownership change, removal of the per-node mirror, and related layout updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kalenikaliaksandr
kalenikaliaksandr merged commit fead442 into LadybirdBrowser:master Jul 31, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant