mrobinson · GitHub

@mrobinson

@mrobinson

Instead of storing an `ArcRefCell` to the inner type of a `Fragment`,
store an `Arc`. This effectively gives the `FragmentTree` exterior
immutability. There are still several situations where layout needs to
mutate an existing fragment:
 - Layout modes adjusting the final position of a fragment
 - Calculating the accumulated containing block
 - Calculating scrollable overflow
 - Repair of the the style of a preserved fragment
In all of those situations, interior mutability is used. The `borrow()`
/ `borrow_mut()` on an `ArcRefCell` has a small cost due to the use of
atomic primitives. The idea here is to try to only pay the cost of using
those atomic primitives when accessing or modifying the mutable parts of
each fragment. The real world layout performance difference of this
change is likely small, but it makes the cost of various layout
operations easier to reason about and the `FragmentTree` conceptually
simpler.
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

@mrobinson

SimonSapin

In addition, add a custom implementation of `Debug` to avoid dumping the
entire style of the `BaseFragment`.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

@mrobinson

SimonSapin

@SimonSapin

Loirooriol

Merged

mrobinson added a commit to mrobinson/servo that referenced this pull request

May 13, 2026
This change responds to some review comments that came in to servo#44849
after it landed.
Testing: These are mainly stylistic changes so shouldn't change any
behavior. Existing tests suffice.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>

Read the original on github.com ↗