SimonSapin · GitHub

@SimonSapin

mrobinson

24 => 8 bytes
Signed-off-by: Simon Sapin <simon@igalia.com>
16 => 8 for the struct field itself. However, for rare data _is_ present,
the allocated box is 8 bytes bigger, so overall memory use is unchanged
for these nodes.
Additionally, it is no longer possible to deallocate the rare data box
for a given node, although this was never done anyway.
Signed-off-by: Simon Sapin <simon@igalia.com>
…for size
24 => 16 bytes
Signed-off-by: Simon Sapin <simon@igalia.com>
32 => 17 bytes
Signed-off-by: Simon Sapin <simon@igalia.com>
Signed-off-by: Simon Sapin <simon@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Simon Sapin <simon@igalia.com>
Signed-off-by: Simon Sapin <simon@igalia.com>
Signed-off-by: Simon Sapin <simon@igalia.com>

@SimonSapin

@SimonSapin

@SimonSapin

@SimonSapin

niyabits pushed a commit to niyabits/servo that referenced this pull request

Jun 11, 2026
The size of the `BoxFragment` struct went from 288 bytes to 240 bytes
(about -17%) according to rust-analyzer. I’m not confident in either of
those exact value because of
rust-lang/rust-analyzer#22468, but the
improvement should still be of similar order of magnitude.
* `spatial_tree_node: AtomicRefCell<Option<ScrollTreeNodeId>>` (24
bytes) → `AtomicUsize` wrapper (8 bytes)
* `cumulative_containing_block_rect: AtomicRefCell<PhysicalRect<Au>>`
(24 bytes) → `Rect<AtomicI32>` wrapper (16 bytes)
* `scrollable_overflow: AtomicRefCell<Option<PhysicalRect<Au>>>` (32
bytes) → `Rect<AtomicI32>` wrapper (16 bytes) + `AtomicBool` (1 byte)
* `rare_data: AtomicRefCell<Option<Box<BoxFragmentRareData>>>` (16
bytes) → `OnceBox<AtomicRefCell<BoxFragmentRareData>>` (8 bytes).
When (rarely) present, the box allocates 8 more bytes than before, so
total memory use is unchanged for nodes with rare data. Additionally, it
is no longer possible to deallocate the box if a node no longer has rare
data, but we were never doing this anyway.
`OnceBox` is a single-pointer-sized type analogous to
`OnceLock<Box<_>>`, from the `once_cell` library which was already in
our dependency graph
Testing: no behavior change expected, so existing tests should have
unchanged outcomes.
---------
Signed-off-by: Simon Sapin <simon@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>

Read the original on github.com ↗