Skip to content

Truly independent web browser

LibWeb: Decide at commit which subtrees stay as they were committed

Aliaksandr Kalenik88d30033ecd0
diff --git a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
index 242d26d4d3b..bcba1ecc502 100644
--- a/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/block_formatting_context.rs
@@ -3294,10 +3294,7 @@ impl<'pass> BlockFormattingContext<'pass> {
.with_in_flow_box_insets(insets),
content_offset,
None,
- Some(fragment_tree::ChildFragmentArrival::CommittedFragment {
- fragment,
- reuses_committed_subtree: true,
- }),
+ Some(fragment_tree::ChildFragmentArrival::CommittedFragment(fragment)),
);
self.block_offset_of_current_block_container
.set(Some(flow_position + entry.flow_position_advance));
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index d2e7106bdce..e90e7774efa 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -111,16 +111,26 @@ impl CommitNotifications {
}
}
-/// A box without children whose new fragment is the one it committed last has nothing a recommit would write, so it is
-/// committed like the root of a reused subtree. Its committed geometry must still be current: a layout-affecting change
-/// since that commit can keep the fragment while changing the facts a recommit gathers, such as its paint order inputs.
-fn keeps_committed_childless_box(arena: &LayoutNodeArena, node: Node, link: &FragmentLink) -> bool {
+/// Whether a box whose new fragment holds the lines and child fragments it committed last keeps its committed subtree,
+/// which then has nothing a recommit would write, so that only the box itself is committed. A stored run hit at another
+/// unobserved block size gives the box such a fragment around the committed contents. The box's committed geometry must
+/// still be current: every layout invalidation inside the box moves that epoch on, and a layout-affecting change since
+/// that commit can keep the fragment while changing the facts a recommit gathers, such as paint order inputs. The
+/// fragment shows every box inside it, except an absolutely positioned one whose containing block is outside, and
+/// boxes whose links a fragment around it holds (see CompletedPassFragments::links_by_slot). A box broken into several
+/// fragments is recommitted.
+fn keeps_committed_subtree(arena: &LayoutNodeArena, link: &FragmentLink) -> bool {
+ let node = link.fragment.node;
let data = arena.data(node);
- data.first_child.get().is_invalid()
- && node_facts::kind_is_box(data.kind.get())
+ node_facts::kind_is_box(data.kind.get())
+ && !node_facts::has_flag(data, NodeFlag::AbsposDescendantEscapes)
+ && !link.fragment.continues_from_previous_fragment
+ && !link.fragment.continues_in_next_fragment
&& arena.paintable_row_is_populated(node)
&& arena
- .with_current_committed_fragment(node, |committed| std::sync::Arc::ptr_eq(committed, &link.fragment))
+ .with_current_committed_fragment(node, |committed| {
+ std::sync::Arc::ptr_eq(committed, &link.fragment) || link.fragment.holds_same_contents_as(committed)
+ })
.unwrap_or(false)
}
@@ -129,7 +139,6 @@ fn commit_subtree(
messages: &mut Vec<FfiCommitMessage>,
paintables: &mut crate::painting::paintable_build::PaintableCommit<'_>,
links_by_slot: &fragment_tree::LinksBySlot<'_>,
- pass_fragments: &fragment_tree::CompletedPassFragments,
enclosing_line_root_changes: crate::painting::paintable_build::LineRootChanges,
) {
let slot_index = node.slot_index();
@@ -153,12 +162,10 @@ fn commit_subtree(
first => first.map(|fragment| fragment.link),
};
let has_more_fragments = fragments.len() > 1;
- let reuses_committed_subtree = !has_more_fragments
- && (pass_fragments.subtree_was_reused(slot_index)
- || entry.is_some_and(|link| keeps_committed_childless_box(paintables.arena(), node, link)));
- debug_assert!(!reuses_committed_subtree || entry.is_some());
- // A reused subtree whose root committed this very link already, in geometry that is still current, has nothing left
- // to commit. A box placing an absolutely positioned box, or a navigable's viewport, notes itself on every commit, and
+ let reuses_committed_subtree = links_by_slot.keeps_committed_subtree(slot_index);
+ debug_assert!(!reuses_committed_subtree || (entry.is_some() && !has_more_fragments));
+ // A box that keeps its committed subtree and committed this very link already, in geometry that is still current,
+ // has nothing left to commit. A box placing an absolutely positioned box, or a navigable's viewport, notes itself on every commit, and
// a link without a containing block leaves the commit to find it among ancestors that may have changed.
if reuses_committed_subtree
&& let Some(link) = entry
@@ -216,7 +223,6 @@ fn commit_subtree(
let replaced = paintables.replace_committed_fragment_link(
node,
link,
- reuses_committed_subtree,
enclosing_line_root_changes,
prepared.previous_offset,
);
@@ -264,10 +270,12 @@ fn commit_subtree(
paintables.arena_mut().gather_layout_style_snapshot_geometry(node);
paintables.stamp_containing_block(node, entry);
+ // NB: A link can change what orders the painting of a box that keeps its fragment, such as whether collapsed
+ // columns hide it.
+ paintables.arena_mut().refresh_paint_order_inputs(node);
if reuses_committed_subtree {
return;
}
- paintables.arena_mut().refresh_paint_order_inputs(node);
let mut child = paintables.arena().data(node).first_child.get();
while !child.is_invalid() {
@@ -277,7 +285,6 @@ fn commit_subtree(
messages,
&mut *paintables,
links_by_slot,
- pass_fragments,
line_root_changes_for_children,
);
child = next;
@@ -318,18 +325,15 @@ pub(crate) fn commit_replacing(
arena.note_layout_commit();
// NB: A partial relayout commits a subtree its ancestors' committed subtrees hold.
arena.note_subtrees_of_self_and_ancestors_committed_anew(root);
- let links_by_slot = pass_fragments.links_by_slot();
+ let links_by_slot = pass_fragments.links_by_slot(
+ root,
+ |node| arena.data(node).parent.get(),
+ |link| keeps_committed_subtree(arena, link),
+ );
let mut paintables = crate::painting::paintable_build::PaintableCommit::new(arena, root);
paintables.begin_commit();
let mut messages = Vec::new();
- commit_subtree(
- root,
- &mut messages,
- &mut paintables,
- &links_by_slot,
- pass_fragments,
- Default::default(),
- );
+ commit_subtree(root, &mut messages, &mut paintables, &links_by_slot, Default::default());
paintables.discard_absolute_rects_memoized_during_commit();
for &viewport in paintables.committed_navigable_container_viewports() {
if let Some(style_node) = paintables.arena().commit_message_style_node(viewport) {
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 79433b8d84d..e71a3cec401 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -291,9 +291,6 @@ pub(super) struct FcRunCacheEntry {
/// Whether the run is a table cell's that did not observe the intrinsic block padding its table hands it (see
/// run_observes_root_block_padding), so that it stands for runs with any such padding.
table_cell_intrinsic_block_padding_unobserved: bool,
- /// How many layouts the arena had committed when the run was stored. The subtrees the run took from the cache as
- /// they were committed are only known to be so while no layout was committed since.
- layout_commits_when_stored: u64,
/// The committed subtree token of the box when its committed fragments were found to be the stored ones, which
/// they stay while the token does.
committed_subtree_token_when_found_committed: Option<u32>,
@@ -357,14 +354,10 @@ impl FcRunCacheEntry {
}
}
- /// Whether the stored fragments can be replayed. Those of the subtrees the stored run took from the cache are the
- /// committed ones, so such a run is replayed only before anything else is committed.
- fn can_be_replayed(&self, callbacks: &LayoutPass<'_>) -> bool {
+ /// Whether a hit may replay the stored fragments. An entry found committed answers only while it describes the
+ /// committed subtree.
+ fn can_be_replayed(&self) -> bool {
self.committed_subtree_token_when_found_committed.is_none()
- && self.outputs.root.as_ref().is_none_or(|root| {
- root.reused_subtree_roots.is_empty()
- || callbacks.arena().layout_commit_count() == self.layout_commits_when_stored
- })
}
/// This entry as the one whose fragments the box committed, while its committed subtree token is `token`.
@@ -372,9 +365,8 @@ impl FcRunCacheEntry {
Self {
key: self.key,
validity: self.validity,
- outputs: self.outputs_reusing_committed_subtree(),
+ outputs: self.outputs.clone(),
table_cell_intrinsic_block_padding_unobserved: self.table_cell_intrinsic_block_padding_unobserved,
- layout_commits_when_stored: self.layout_commits_when_stored,
committed_subtree_token_when_found_committed: Some(token),
last_used_at_layout_commit: std::sync::atomic::AtomicU64::new(self.last_used_at_layout_commit()),
structural_epoch_bumps_when_stored: self.structural_epoch_bumps_when_stored,
@@ -392,19 +384,6 @@ impl FcRunCacheEntry {
}
}
- /// The outputs of a hit that keeps the committed subtree. Commit stops at the reused root, so the reuse markers of
- /// the subtrees below it never enter its scopes.
- fn outputs_reusing_committed_subtree(&self) -> formatting_context::RunOutputs {
- formatting_context::RunOutputs {
- root: self
- .outputs
- .root
- .as_ref()
- .map(fragment_tree::RunRootFragment::without_reused_subtree_roots),
- ..self.outputs_without_fragments()
- }
- }
-
fn last_used_at_layout_commit(&self) -> u64 {
self.last_used_at_layout_commit
.load(std::sync::atomic::Ordering::Relaxed)
@@ -440,12 +419,8 @@ impl FcRunCacheEntry {
}
/// The outputs a hit absorbs.
- pub(super) fn outputs_to_replay(&self, reuses_committed_subtree: bool) -> formatting_context::RunOutputs {
- if reuses_committed_subtree {
- self.outputs_reusing_committed_subtree()
- } else {
- self.outputs.clone()
- }
+ pub(super) fn outputs_to_replay(&self) -> formatting_context::RunOutputs {
+ self.outputs.clone()
}
}
@@ -856,7 +831,7 @@ impl FcRunCacheAttempt {
return false;
}
reuses_committed_subtree = entry.describes_committed_subtree(callbacks.arena(), box_);
- reuses_committed_subtree || entry.can_be_replayed(callbacks)
+ reuses_committed_subtree || entry.can_be_replayed()
}) {
if !reuses_committed_subtree {
// NB: Once the replayed fragments are committed, the entry can drop them.
@@ -905,7 +880,6 @@ impl FcRunCacheAttempt {
validity,
outputs: outputs.clone(),
table_cell_intrinsic_block_padding_unobserved: false,
- layout_commits_when_stored: callbacks.arena().layout_commit_count(),
committed_subtree_token_when_found_committed: None,
last_used_at_layout_commit: std::sync::atomic::AtomicU64::new(
callbacks.arena().layout_commit_count(),
@@ -922,13 +896,7 @@ impl FcRunCacheAttempt {
};
// Release the probed entry so that store() can replace it in place.
drop(structurally_damaged_entry);
- let Some(root) = &outputs.root else {
- return;
- };
- // Commit stops at the subtrees a run reused. Do not store a run that reused one and exports an
- // out-of-flow descendant: replaying the parent has to commit the subtree again so the freshly
- // laid-out descendant can commit.
- if !root.propagated_pending_abspos.is_empty() && !root.reused_subtree_roots.is_empty() {
+ if outputs.root.is_none() {
return;
}
let entry = FcRunCacheEntry {
@@ -942,7 +910,6 @@ impl FcRunCacheAttempt {
.is_some()
&& outputs.root_outcome.parent_owns_root_input_cells()
&& !run_observes_root_block_padding(callbacks, box_, outputs),
- layout_commits_when_stored: callbacks.arena().layout_commit_count(),
committed_subtree_token_when_found_committed: None,
last_used_at_layout_commit: std::sync::atomic::AtomicU64::new(callbacks.arena().layout_commit_count()),
structural_epoch_bumps_when_stored: 0,
@@ -1085,7 +1052,6 @@ mod tests {
laid_out_abspos_contained_by_root: false,
},
table_cell_intrinsic_block_padding_unobserved: false,
- layout_commits_when_stored: layout_commit_count,
committed_subtree_token_when_found_committed: None,
last_used_at_layout_commit: std::sync::atomic::AtomicU64::new(layout_commit_count),
structural_epoch_bumps_when_stored: 0,
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 37e386141fe..cba822bff6a 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -470,11 +470,8 @@ pub(crate) fn place_child(
.is_none_or(|arrival| arrival.node() == node && !fragments.left_child_unplaced(node)),
"a box is placed with fragments handed to it for another box, or after it was left unplaced"
);
- let child_root = fragment_arrival.map(fragment_tree::ChildFragmentArrival::into_root);
- match child_root {
- Some((root, reuses_committed_subtree)) => {
- fragments.take_in_child_root_at_placement(node, root, reuses_committed_subtree, callbacks);
- }
+ match fragment_arrival.map(fragment_tree::ChildFragmentArrival::into_root) {
+ Some(root) => fragments.take_in_child_root_at_placement(node, root, callbacks),
None => fragments.open_fragment_of_placed_box(node),
}
let mut abspos_boxes_placed_with_it = Vec::new();
@@ -1976,16 +1973,7 @@ pub(super) fn run_formatting_context(
table_inline_layout,
None,
);
- return child_run_outcome_from_outputs(
- &callbacks,
- parent_fragments,
- box_,
- &input,
- root_cells,
- outputs,
- false,
- false,
- );
+ return child_run_outcome_from_outputs(&callbacks, parent_fragments, box_, &input, root_cells, outputs, false);
}
let cache_key = fc_run_cache::FcRunCacheKey::new(fc_type, input, root_cells);
let cache_attempt = match fc_run_cache::FcRunCacheAttempt::probe(
@@ -1999,17 +1987,16 @@ pub(super) fn run_formatting_context(
) {
Ok(attempt) => attempt,
Err(hit) => {
- let reuses_committed_subtree = hit.reuses_committed_subtree;
let action = if !builds_fragments {
"READ RESULT"
- } else if reuses_committed_subtree {
+ } else if hit.reuses_committed_subtree {
"REUSE SUBTREE"
} else {
"REPLAY FRAGMENTS"
};
let _trace = callbacks.layout_trace().run(box_, fc_type, || action);
let outputs = if builds_fragments {
- hit.entry.outputs_to_replay(reuses_committed_subtree)
+ hit.entry.outputs_to_replay()
} else {
hit.entry.outputs_without_fragments()
};
@@ -2020,7 +2007,6 @@ pub(super) fn run_formatting_context(
&input,
root_cells,
outputs,
- reuses_committed_subtree,
true,
);
}
@@ -2060,7 +2046,7 @@ pub(super) fn run_formatting_context(
None,
);
if let Some(discarded_outputs) = &discarded_outputs {
- run_repeatability::verify_repeated_run(&callbacks, box_, discarded_outputs, &outputs);
+ run_repeatability::verify_repeated_run(box_, discarded_outputs, &outputs);
}
if cache_attempt.stores_outputs() {
run_repeatability::verify_run_ignores_its_unobserved_own_block_size_and_block_margins(
@@ -2088,16 +2074,7 @@ pub(super) fn run_formatting_context(
);
}
cache_attempt.conclude(&callbacks, box_, cache_key, &outputs);
- child_run_outcome_from_outputs(
- &callbacks,
- parent_fragments,
- box_,
- &input,
- root_cells,
- outputs,
- false,
- false,
- )
+ child_run_outcome_from_outputs(&callbacks, parent_fragments, box_, &input, root_cells, outputs, false)
}
fn keep_inline_margins_resolved_now_where_unobserved(
@@ -2905,10 +2882,7 @@ pub(crate) fn layout_inside_child_with_input_cells(
// OPTIMIZATION: A box that took its metrics from its committed fragment hands that fragment to its placement.
let fragment_arrival = committed_fragment
.filter(|fragment| run.fragments.is_some() && fragment.is_plain_box())
- .map(|fragment| fragment_tree::ChildFragmentArrival::CommittedFragment {
- fragment,
- reuses_committed_subtree: false,
- });
+ .map(fragment_tree::ChildFragmentArrival::CommittedFragment);
let laid_out_box =
run_state::LaidOutChildBox::sized_here(cells_of_this_layout.get(), DerivedBaselines::default());
return ChildLayout {
@@ -3190,7 +3164,7 @@ pub(crate) fn lay_out_shape_for_its_result(callbacks: LayoutPass<'_>, shape: Chi
run_repeatability::lay_out_discarded_run(&callbacks, |callbacks| lay_out(callbacks, root_cells, input, None));
let outputs = lay_out(callbacks, root_cells, input, previous_line_data);
if let Some(discarded_outputs) = &discarded_outputs {
- run_repeatability::verify_repeated_run(&callbacks, node, discarded_outputs, &outputs);
+ run_repeatability::verify_repeated_run(node, discarded_outputs, &outputs);
}
if cache_attempt.stores_outputs() {
run_repeatability::verify_run_ignores_its_unobserved_own_block_size_and_block_margins(
@@ -3326,7 +3300,6 @@ pub(super) fn content_block_size_adopted_after_run(
.then_some(automatic_content_block_size))
}
-#[expect(clippy::too_many_arguments)]
fn child_run_outcome_from_outputs(
callbacks: &LayoutPass<'_>,
parent_fragments: Option<&fragment_tree::RunFragmentBuilder>,
@@ -3334,7 +3307,6 @@ fn child_run_outcome_from_outputs(
input: &LayoutInput,
root_cells: used_values::RootInputCells,
outputs: RunOutputs,
- reuses_committed_subtree: bool,
outputs_are_stored_ones: bool,
) -> ChildRunOutcome {
let RunOutputs {
@@ -3363,10 +3335,7 @@ fn child_run_outcome_from_outputs(
{
root.fragment = committed;
}
- fragment_tree::ChildFragmentArrival::RunRoot {
- root,
- reuses_committed_subtree,
- }
+ fragment_tree::ChildFragmentArrival::RunRoot(root)
});
ChildRunOutcome {
result,
@@ -3803,14 +3772,10 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
);
// The retained offset already includes relative positioning. Publish it directly instead
// of applying placement adjustments a second time.
- let Some(fragment_tree::ChildFragmentArrival::RunRoot {
- root: run_root_fragment,
- reuses_committed_subtree,
- }) = fragment_arrival
- else {
+ let Some(fragment_tree::ChildFragmentArrival::RunRoot(run_root_fragment)) = fragment_arrival else {
panic!("the root of a partial relayout is laid out by a run of its own");
};
- fragments.take_in_child_root_at_placement(root, run_root_fragment, reuses_committed_subtree, callbacks);
+ fragments.take_in_child_root_at_placement(root, run_root_fragment, callbacks);
fragments.build_fragment_for_placed_box(
callbacks,
root,
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index bd6c3013872..8fd40cfd88e 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -97,15 +97,18 @@ impl PayloadComparison {
impl Fragment {
fn builds_identically_to(&self, previous: &Fragment) -> bool {
- std::ptr::eq(self, previous)
- || self.has_same_box_properties(previous)
- && same_allocation(self.line_data.as_ref(), previous.line_data.as_ref())
- && self.children.len() == previous.children.len()
- && self
- .children
- .iter()
- .zip(&previous.children)
- .all(|(link, previous_link)| link.places_same_fragment_identically_to(previous_link))
+ std::ptr::eq(self, previous) || self.has_same_box_properties(previous) && self.holds_same_contents_as(previous)
+ }
+
+ /// Whether the fragment holds the very lines and child fragments `previous` holds, placed the same way.
+ pub(crate) fn holds_same_contents_as(&self, previous: &Fragment) -> bool {
+ same_allocation(self.line_data.as_ref(), previous.line_data.as_ref())
+ && self.children.len() == previous.children.len()
+ && self
+ .children
+ .iter()
+ .zip(&previous.children)
+ .all(|(link, previous_link)| link.places_same_fragment_identically_to(previous_link))
}
/// Whether the fragment holds nothing beyond a plain box's metrics, line data and children: no table, grid, flex,
@@ -764,7 +767,6 @@ struct ChildLeftUnplaced {
pub(crate) struct UnplacedRootFragment {
pub(crate) node: crate::layout::node_data::NodeSlotId,
pub(crate) scoped_descendants: Vec<FragmentLink>,
- pub(crate) reused_subtree_roots: HashSet<u32>,
pub(crate) propagated_pending_abspos: Vec<abspos_inputs::PendingAbsposChild>,
pub(crate) propagated_anchor_candidates: Vec<AnchorCandidate>,
pub(crate) propagated_inline_containing_block_rects: Vec<InlineContainingBlockRect>,
@@ -783,7 +785,6 @@ impl UnplacedRootFragment {
let Self {
node,
scoped_descendants,
- reused_subtree_roots,
propagated_pending_abspos,
propagated_anchor_candidates,
propagated_inline_containing_block_rects,
@@ -799,7 +800,6 @@ impl UnplacedRootFragment {
run_state::FragmentFactsDecidedByParent::default(),
root_payloads,
),
- reused_subtree_roots,
propagated_pending_abspos,
propagated_anchor_candidates,
propagated_inline_containing_block_rects,
@@ -808,12 +808,10 @@ impl UnplacedRootFragment {
}
}
-/// What a run hands its parent of its root: the root's fragment, the subtrees the run took from the cache as they
-/// were committed, and what goes past the run toward boxes outside it.
+/// What a run hands its parent of its root: the root's fragment, and what goes past the run toward boxes outside it.
#[derive(Clone)]
pub(crate) struct RunRootFragment {
pub(crate) fragment: std::sync::Arc<Fragment>,
- pub(crate) reused_subtree_roots: HashSet<u32>,
pub(crate) propagated_pending_abspos: Vec<abspos_inputs::PendingAbsposChild>,
pub(crate) propagated_anchor_candidates: Vec<AnchorCandidate>,
pub(crate) propagated_inline_containing_block_rects: Vec<InlineContainingBlockRect>,
@@ -825,7 +823,6 @@ impl RunRootFragment {
pub(crate) fn propagating_nothing(fragment: std::sync::Arc<Fragment>) -> Self {
Self {
fragment,
- reused_subtree_roots: HashSet::default(),
propagated_pending_abspos: Vec::new(),
propagated_anchor_candidates: Vec::new(),
propagated_inline_containing_block_rects: Vec::new(),
@@ -833,18 +830,6 @@ impl RunRootFragment {
}
}
- /// This root without the subtrees its run took from the cache as they were committed.
- pub(crate) fn without_reused_subtree_roots(&self) -> Self {
- Self {
- fragment: self.fragment.clone(),
- reused_subtree_roots: HashSet::default(),
- propagated_pending_abspos: self.propagated_pending_abspos.clone(),
- propagated_anchor_candidates: self.propagated_anchor_candidates.clone(),
- propagated_inline_containing_block_rects: self.propagated_inline_containing_block_rects.clone(),
- propagated_abspos_containing_block_info: self.propagated_abspos_containing_block_info.clone(),
- }
- }
-
/// Whether the root hands its ancestors no payload.
pub(crate) fn propagates_nothing(&self) -> bool {
self.propagated_pending_abspos.is_empty()
@@ -859,21 +844,15 @@ impl RunRootFragment {
/// as placed.
#[must_use = "a child's fragments are lost unless its placement takes them"]
pub(crate) enum ChildFragmentArrival {
- RunRoot {
- root: RunRootFragment,
- reuses_committed_subtree: bool,
- },
- CommittedFragment {
- fragment: std::sync::Arc<Fragment>,
- reuses_committed_subtree: bool,
- },
+ RunRoot(RunRootFragment),
+ CommittedFragment(std::sync::Arc<Fragment>),
}
impl ChildFragmentArrival {
pub(crate) fn fragment(&self) -> &std::sync::Arc<Fragment> {
match self {
- Self::RunRoot { root, .. } => &root.fragment,
- Self::CommittedFragment { fragment, .. } => fragment,
+ Self::RunRoot(root) => &root.fragment,
+ Self::CommittedFragment(fragment) => fragment,
}
}
@@ -881,18 +860,11 @@ impl ChildFragmentArrival {
self.fragment().node
}
- /// The child's fragment as the root fragment of a run, and whether it keeps the committed subtree. Nothing goes past
- /// a committed fragment.
- pub(crate) fn into_root(self) -> (RunRootFragment, bool) {
+ /// The child's fragment as the root fragment of a run. Nothing goes past a committed fragment.
+ pub(crate) fn into_root(self) -> RunRootFragment {
match self {
- Self::RunRoot {
- root,
- reuses_committed_subtree,
- } => (root, reuses_committed_subtree),
- Self::CommittedFragment {
- fragment,
- reuses_committed_subtree,
- } => (RunRootFragment::propagating_nothing(fragment), reuses_committed_subtree),
+ Self::RunRoot(root) => root,
+ Self::CommittedFragment(fragment) => RunRootFragment::propagating_nothing(fragment),
}
}
}
@@ -909,9 +881,15 @@ pub(crate) type SlotFragments<'tree> = SmallVec<[SlotFragment<'tree>; 1]>;
pub(crate) struct LinksBySlot<'tree> {
in_first_containing_block_fragment: HashMap<u32, &'tree FragmentLink>,
other: HashMap<u32, (SlotFragments<'tree>, usize)>,
+ kept_subtree_roots: HashSet<u32>,
}
impl<'tree> LinksBySlot<'tree> {
+ /// Whether the box in `slot` keeps its committed subtree, which commit then leaves as it is below the box.
+ pub(crate) fn keeps_committed_subtree(&self, slot: u32) -> bool {
+ self.kept_subtree_roots.contains(&slot)
+ }
+
pub(crate) fn fragments(&self, slot: u32) -> SlotFragments<'tree> {
if let Some(link) = self.in_first_containing_block_fragment.get(&slot) {
return smallvec::smallvec![SlotFragment {
@@ -964,15 +942,61 @@ impl<'tree> LinksBySlot<'tree> {
pub(crate) struct CompletedPassFragments {
pub(crate) roots: Vec<FragmentLink>,
- pub(crate) reused_subtree_roots: HashSet<u32>,
}
impl CompletedPassFragments {
- pub(crate) fn links_by_slot(&self) -> LinksBySlot<'_> {
+ /// The links of the pass by the slot of their box, below `pass_root`. A box keeps its committed subtree where
+ /// `keeps_committed_subtree` holds for its link and the fragment of no box around it holds the link of a box inside
+ /// it, which the box's own fragment would then not show. Commit looks up nothing below such a box.
+ pub(crate) fn links_by_slot(
+ &self,
+ pass_root: crate::layout::node_data::NodeSlotId,
+ parent_of: impl Fn(crate::layout::node_data::NodeSlotId) -> crate::layout::node_data::NodeSlotId,
+ keeps_committed_subtree: impl Fn(&FragmentLink) -> bool,
+ ) -> LinksBySlot<'_> {
+ struct KeptSubtrees<ParentOf, KeepsCommittedSubtree> {
+ parent_of: ParentOf,
+ keeps_committed_subtree: KeepsCommittedSubtree,
+ boxes_around_links_held_outside_them: HashSet<u32>,
+ kept_subtree_roots: HashSet<u32>,
+ }
+ impl<ParentOf, KeepsCommittedSubtree> KeptSubtrees<ParentOf, KeepsCommittedSubtree>
+ where
+ ParentOf: Fn(crate::layout::node_data::NodeSlotId) -> crate::layout::node_data::NodeSlotId,
+ KeepsCommittedSubtree: Fn(&FragmentLink) -> bool,
+ {
+ /// Decides which of `links`, held by the fragment of `holder`, keep their committed subtrees, and answers
+ /// how many links commit looks up among them.
+ fn decide(&mut self, links: &[FragmentLink], holder: crate::layout::node_data::NodeSlotId) -> usize {
+ for link in links {
+ if link.fragment.node == holder {
+ continue;
+ }
+ let mut ancestor = (self.parent_of)(link.fragment.node);
+ while !ancestor.is_invalid() && ancestor != holder {
+ self.boxes_around_links_held_outside_them.insert(ancestor.slot_index());
+ ancestor = (self.parent_of)(ancestor);
+ }
+ }
+ links
+ .iter()
+ .map(|link| {
+ let node = link.fragment.node;
+ if !self.boxes_around_links_held_outside_them.contains(&node.slot_index())
+ && (self.keeps_committed_subtree)(link)
+ {
+ self.kept_subtree_roots.insert(node.slot_index());
+ return 1;
+ }
+ 1 + self.decide(&link.fragment.children, node)
+ })
+ .sum()
+ }
+ }
fn insert_links<'tree>(
links: &'tree [FragmentLink],
parent: Option<(crate::layout::node_data::NodeSlotId, u32, usize)>,
- reused_subtree_roots: &HashSet<u32>,
+ kept_subtree_roots: &HashSet<u32>,
links_by_slot: &mut LinksBySlot<'tree>,
) {
for link in links {
@@ -994,44 +1018,33 @@ impl CompletedPassFragments {
containing_block_line_index_offset,
},
);
- // NB: Commit stops at a reused subtree's root, so nothing looks up the links below it.
- if !reused_subtree_roots.contains(&slot) {
+ if !kept_subtree_roots.contains(&slot) {
insert_links(
&link.fragment.children,
Some((link.fragment.node, fragment_index, line_index_offset)),
- reused_subtree_roots,
+ kept_subtree_roots,
links_by_slot,
);
}
}
}
- fn count_links(links: &[FragmentLink], reused_subtree_roots: &HashSet<u32>) -> usize {
- links
- .iter()
- .map(|link| {
- let slot = link.fragment.node.slot_index();
- 1 + if reused_subtree_roots.contains(&slot) {
- 0
- } else {
- count_links(&link.fragment.children, reused_subtree_roots)
- }
- })
- .sum()
- }
+ let mut kept_subtrees = KeptSubtrees {
+ parent_of,
+ keeps_committed_subtree,
+ boxes_around_links_held_outside_them: HashSet::default(),
+ kept_subtree_roots: HashSet::default(),
+ };
+ let link_count = kept_subtrees.decide(&self.roots, pass_root);
+ let kept_subtree_roots = kept_subtrees.kept_subtree_roots;
let mut links_by_slot = LinksBySlot {
- in_first_containing_block_fragment: HashMap::with_capacity_and_hasher(
- count_links(&self.roots, &self.reused_subtree_roots),
- Default::default(),
- ),
+ in_first_containing_block_fragment: HashMap::with_capacity_and_hasher(link_count, Default::default()),
other: HashMap::default(),
+ kept_subtree_roots: HashSet::default(),
};
- insert_links(&self.roots, None, &self.reused_subtree_roots, &mut links_by_slot);
+ insert_links(&self.roots, None, &kept_subtree_roots, &mut links_by_slot);
+ links_by_slot.kept_subtree_roots = kept_subtree_roots;
links_by_slot
}
-
- pub(crate) fn subtree_was_reused(&self, slot: u32) -> bool {
- self.reused_subtree_roots.contains(&slot)
- }
}
struct PendingFragment {
@@ -1076,7 +1089,6 @@ struct RunFragmentBuilderInner {
/// How many abspos containing block info contributions the run has received, whether or not they are still listed.
abspos_containing_block_info_contributions_received: u64,
top_scope_links: Vec<FragmentLink>,
- reused_subtree_roots: HashSet<u32>,
/// What the layouts of children the run laid out but never placed handed their placements, which close() links at
/// the top of the run's fragments.
children_left_unplaced: Vec<ChildLeftUnplaced>,
@@ -1489,7 +1501,6 @@ impl RunFragmentBuilder {
"a fragmentainer run's root is the box of the run that adopts it"
);
let mut inner = self.inner.borrow_mut();
- inner.reused_subtree_roots.extend(root.reused_subtree_roots);
for mut link in root.scoped_descendants {
link.committed_offset = formatting_context::point_add(link.committed_offset, offset);
if link.containing_block == self.root_node
@@ -1535,20 +1546,8 @@ impl RunFragmentBuilder {
&self,
node: crate::layout::node_data::NodeSlotId,
root: RunRootFragment,
- reuses_committed_subtree: bool,
callbacks: &LayoutPass<'_>,
) {
- {
- let mut inner = self.inner.borrow_mut();
- inner
- .reused_subtree_roots
- .extend(root.reused_subtree_roots.iter().copied());
- if reuses_committed_subtree {
- inner.reused_subtree_roots.insert(node.slot_index());
- } else {
- inner.reused_subtree_roots.remove(&node.slot_index());
- }
- }
self.merge_child_root_into_pending_fragment(node, root, callbacks);
}
@@ -1575,7 +1574,6 @@ impl RunFragmentBuilder {
let mut inner = self.inner.borrow_mut();
let slot = node.slot_index();
let mut payloads_of_box = arrived_payloads;
- inner.reused_subtree_roots.remove(&slot);
if let Some(pending_fragment) = inner.pending_fragments.remove(&slot) {
payloads_of_box = payloads_of_box.or(pending_fragment.payloads);
}
@@ -1814,7 +1812,6 @@ impl RunFragmentBuilder {
let root = self.close(callbacks);
CompletedPassFragments {
roots: root.scoped_descendants,
- reused_subtree_roots: root.reused_subtree_roots,
}
}
@@ -1839,30 +1836,18 @@ impl RunFragmentBuilder {
pending_fragment.node
);
}
- // NB: A child run's root or a reused subtree root that the run never placed keeps its fragment at the top of the
- // run's fragments, as its subtree goes with it. An empty box that was never placed has no fragment here.
+ // NB: A child run's root that the run never placed keeps its fragment at the top of the run's fragments, as its
+ // subtree goes with it. A box whose parent sized it from its committed fragment and never placed has no
+ // fragment here.
for ChildLeftUnplaced {
arrival,
unplaced_child,
} in std::mem::take(&mut inner.children_left_unplaced)
{
- if matches!(
- arrival,
- ChildFragmentArrival::CommittedFragment {
- reuses_committed_subtree: false,
- ..
- }
- ) {
+ let ChildFragmentArrival::RunRoot(root) = arrival else {
continue;
- }
- let (root, reuses_committed_subtree) = arrival.into_root();
- inner
- .reused_subtree_roots
- .extend(root.reused_subtree_roots.iter().copied());
+ };
let node = root.fragment.node;
- if reuses_committed_subtree {
- inner.reused_subtree_roots.insert(node.slot_index());
- }
let placement = PlacementData::of_unplaced_child(&unplaced_child, callbacks.frame);
inner.top_scope_links.push(link_fragment(
fragment_of_placed_box(
@@ -1900,7 +1885,6 @@ impl RunFragmentBuilder {
UnplacedRootFragment {
node: self.root_node,
scoped_descendants: inner.top_scope_links,
- reused_subtree_roots: inner.reused_subtree_roots,
propagated_pending_abspos,
propagated_anchor_candidates,
propagated_inline_containing_block_rects,
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index c4a549f9e15..c8d19190215 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1060,7 +1060,7 @@ impl<'context> InlineFormattingContext<'context> {
None => arrivals.remove(&node),
};
debug_assert!(
- !matches!(previous, Some(fragment_tree::ChildFragmentArrival::RunRoot { .. })),
+ !matches!(previous, Some(fragment_tree::ChildFragmentArrival::RunRoot(_))),
"an atomic inline is laid out once by a run before its placement"
);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index 4a6e4bbf532..111e13866c5 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -52,7 +52,6 @@ pub(super) fn lay_out_discarded_run(
/// Checks that the run of `box_` that produced `used` repeated what the discarded run that produced `discarded` did.
pub(super) fn verify_repeated_run(
- callbacks: &LayoutPass<'_>,
box_: Node,
discarded: &formatting_context::RunOutputs,
used: &formatting_context::RunOutputs,
@@ -61,7 +60,7 @@ pub(super) fn verify_repeated_run(
checked: &format!("the run of {box_:?}"),
reference: "its discarded repetition",
}
- .verify(callbacks, box_, used, discarded);
+ .verify(box_, used, discarded);
}
fn unobserved_own_block_size_verification_is_enabled() -> bool {
@@ -170,7 +169,7 @@ pub(super) fn verify_run_ignores_its_unobserved_own_block_size_and_block_margins
checked: &checked,
reference: &reference,
}
- .verify(callbacks, box_, outputs, &reference_outputs);
+ .verify(box_, outputs, &reference_outputs);
}
}
@@ -182,7 +181,6 @@ struct ComparedLayouts<'a> {
impl ComparedLayouts<'_> {
fn verify(
&self,
- callbacks: &LayoutPass<'_>,
box_: Node,
checked_outputs: &formatting_context::RunOutputs,
reference_outputs: &formatting_context::RunOutputs,
@@ -217,10 +215,6 @@ impl ComparedLayouts<'_> {
(Some(checked_root), Some(reference_root)) => (checked_root, reference_root),
_ => panic!("{checked} and {reference} do not both build fragments"),
};
- assert!(
- reference_root.reused_subtree_roots.is_empty(),
- "{checked}: {reference} reused a subtree"
- );
assert!(
fragment_tree::FragmentPayloads::of_fragment(&checked_root.fragment)
== fragment_tree::FragmentPayloads::of_fragment(&reference_root.fragment),
@@ -242,19 +236,9 @@ impl ComparedLayouts<'_> {
),
"{checked} propagates payloads {reference} does not"
);
- let mut nodes_laid_out_afresh = HashSet::default();
- collect_nodes_of_fragment_subtrees(&reference_root.fragment.children, &mut nodes_laid_out_afresh);
- let comparison = FreshDescendantComparison {
- callbacks,
- reused_subtree_roots: &checked_root.reused_subtree_roots,
- nodes_laid_out_afresh,
- };
- if let Err(difference) = comparison.compare_children(
- box_,
- &checked_root.fragment.children,
- &reference_root.fragment.children,
- false,
- ) {
+ if let Err(difference) =
+ compare_children(box_, &checked_root.fragment.children, &reference_root.fragment.children)
+ {
panic!("{checked} lays out descendants unlike {reference}: {difference}");
}
}
@@ -282,170 +266,59 @@ fn host_findings_match(left: Option<&run_state::HostFindings>, right: Option<&ru
&& left.document_svg_root_natural_size == right.document_svg_root_natural_size
}
-fn collect_nodes_of_fragment_subtrees(links: &[fragment_tree::FragmentLink], nodes: &mut HashSet<u32>) {
- for link in links {
- nodes.insert(link.fragment.node.slot_index());
- collect_nodes_of_fragment_subtrees(&link.fragment.children, nodes);
- }
-}
-
-/// Compares the descendant fragments a run produced with those a fresh layout of its root produced. Where the run
-/// reused a committed subtree, the committed fragments stand for the ones it did not lay out again.
-struct FreshDescendantComparison<'comparison, 'pass> {
- callbacks: &'comparison LayoutPass<'pass>,
- reused_subtree_roots: &'comparison HashSet<u32>,
- nodes_laid_out_afresh: HashSet<u32>,
-}
-
-impl FreshDescendantComparison<'_, '_> {
- fn compare_children(
- &self,
- parent: Node,
- expected: &[fragment_tree::FragmentLink],
- fresh: &[fragment_tree::FragmentLink],
- expected_is_committed: bool,
- ) -> Result<(), String> {
- if expected.is_empty() && expected_is_committed {
- return self.compare_with_committed_fragments_of_descendants(parent, fresh);
- }
- // NB: Below a subtree the run reused, the run holds the committed fragments, whose children a commit that
- // reused them left out.
- if !expected_is_committed && self.reused_subtree_roots.contains(&parent.slot_index()) {
- return self.compare_with_committed_descendants(parent, fresh);
- }
- if expected.len() != fresh.len() {
- return Err(format!(
- "{parent:?} has children {:?} where the fresh layout has {:?}",
- nodes_of(expected),
- nodes_of(fresh)
- ));
- }
- for (index, fresh_link) in fresh.iter().enumerate() {
- let node = fresh_link.fragment.node;
- let expected_link = if expected[index].fragment.node == node {
- &expected[index]
- } else {
- let occurrence = fresh[..index].iter().filter(|link| link.fragment.node == node).count();
- expected
- .iter()
- .filter(|link| link.fragment.node == node)
- .nth(occurrence)
- .ok_or_else(|| {
- format!(
- "{parent:?} has children {:?} where the fresh layout has {:?}",
- nodes_of(expected),
- nodes_of(fresh)
- )
- })?
- };
- self.compare_links(expected_link, fresh_link, expected_is_committed)?;
- }
- Ok(())
- }
-
- fn compare_with_committed_descendants(
- &self,
- parent: Node,
- fresh: &[fragment_tree::FragmentLink],
- ) -> Result<(), String> {
- let committed_children = self
- .callbacks
- .arena()
- .with_current_committed_fragment(parent, |fragment| fragment.children.clone())
- .unwrap_or_default();
- if !committed_children.is_empty() {
- return self.compare_children(parent, &committed_children, fresh, true);
- }
- self.compare_with_committed_fragments_of_descendants(parent, fresh)
+/// Compares the descendant fragments a run produced with those a fresh layout of its root produced.
+fn compare_children(
+ parent: Node,
+ expected: &[fragment_tree::FragmentLink],
+ fresh: &[fragment_tree::FragmentLink],
+) -> Result<(), String> {
+ if expected.len() != fresh.len() {
+ return Err(format!(
+ "{parent:?} has children {:?} where the fresh layout has {:?}",
+ nodes_of(expected),
+ nodes_of(fresh)
+ ));
}
-
- fn compare_with_committed_fragments_of_descendants(
- &self,
- parent: Node,
- fresh: &[fragment_tree::FragmentLink],
- ) -> Result<(), String> {
- self.ensure_every_committed_descendant_is_laid_out_afresh(parent)?;
- for (index, fresh_link) in fresh.iter().enumerate() {
- let node = fresh_link.fragment.node;
- let fragment_index = fresh[..index].iter().filter(|link| link.fragment.node == node).count();
- let Some(committed_link) = self.committed_fragment_link(node, fragment_index) else {
- return Err(format!(
- "{node:?}, a child of the reused subtree of {parent:?}, has no committed fragment {fragment_index}"
- ));
- };
- self.compare_links(&committed_link, fresh_link, true)?;
- let is_last_fresh_fragment = !fresh[index + 1..].iter().any(|link| link.fragment.node == node);
- if is_last_fresh_fragment && self.committed_fragment_link(node, fragment_index + 1).is_some() {
- return Err(format!(
- "{node:?}, a child of the reused subtree of {parent:?}, has more committed fragments than the {} of \
- the fresh layout",
- fragment_index + 1
- ));
- }
- }
- Ok(())
+ for (index, fresh_link) in fresh.iter().enumerate() {
+ let node = fresh_link.fragment.node;
+ let expected_link = if expected[index].fragment.node == node {
+ &expected[index]
+ } else {
+ let occurrence = fresh[..index].iter().filter(|link| link.fragment.node == node).count();
+ expected
+ .iter()
+ .filter(|link| link.fragment.node == node)
+ .nth(occurrence)
+ .ok_or_else(|| {
+ format!(
+ "{parent:?} has children {:?} where the fresh layout has {:?}",
+ nodes_of(expected),
+ nodes_of(fresh)
+ )
+ })?
+ };
+ compare_links(expected_link, fresh_link)?;
}
+ Ok(())
+}
- fn ensure_every_committed_descendant_is_laid_out_afresh(&self, subtree_root: Node) -> Result<(), String> {
- let mut committed_descendant_missing_from_fresh_layout = None;
- self.callbacks
- .arena()
- .for_each_node_in_layout_subtree_in_pre_order(subtree_root, |node| {
- if node != subtree_root
- && committed_descendant_missing_from_fresh_layout.is_none()
- && self.callbacks.has_committed_fragment_link(node)
- && !self.nodes_laid_out_afresh.contains(&node.slot_index())
- {
- committed_descendant_missing_from_fresh_layout = Some(node);
- }
- });
- match committed_descendant_missing_from_fresh_layout {
- None => Ok(()),
- Some(node) => Err(format!(
- "{node:?}, a descendant of the reused subtree of {subtree_root:?}, has a committed fragment where the \
- fresh layout has none"
- )),
- }
+fn compare_links(expected: &fragment_tree::FragmentLink, fresh: &fragment_tree::FragmentLink) -> Result<(), String> {
+ let node = fresh.fragment.node;
+ if !expected.has_same_placement(fresh) {
+ return Err(format!(
+ "{node:?} is placed at {} where the fresh layout places it at {}",
+ describe_placement(expected),
+ describe_placement(fresh)
+ ));
}
-
- fn committed_fragment_link(&self, node: Node, fragment_index: usize) -> Option<fragment_tree::FragmentLink> {
- if fragment_index == 0 {
- return self.callbacks.committed_fragment_link(node);
- }
- let arena = self.callbacks.arena();
- if !arena.paintable_row_is_populated(node) {
- return None;
- }
- arena
- .committed_side_data(node)
- .box_fragments()
- .get(fragment_index - 1)
- .map(|later_fragment| later_fragment.link.clone())
+ let (expected, fresh) = (&expected.fragment, &fresh.fragment);
+ if !expected.has_same_box_properties_comparing_payloads_by_value(fresh) {
+ return Err(format!("{node:?} has box properties unlike the fresh layout"));
}
-
- fn compare_links(
- &self,
- expected: &fragment_tree::FragmentLink,
- fresh: &fragment_tree::FragmentLink,
- expected_is_committed: bool,
- ) -> Result<(), String> {
- let node = fresh.fragment.node;
- if !expected.has_same_placement(fresh) {
- return Err(format!(
- "{node:?} is placed at {} where the fresh layout places it at {}",
- describe_placement(expected),
- describe_placement(fresh)
- ));
- }
- let (expected, fresh) = (&expected.fragment, &fresh.fragment);
- if !expected.has_same_box_properties_comparing_payloads_by_value(fresh) {
- return Err(format!("{node:?} has box properties unlike the fresh layout"));
- }
- if expected.line_data.as_deref() != fresh.line_data.as_deref() {
- return Err(format!("{node:?} has line data unlike the fresh layout"));
- }
- self.compare_children(node, &expected.children, &fresh.children, expected_is_committed)
+ if expected.line_data.as_deref() != fresh.line_data.as_deref() {
+ return Err(format!("{node:?} has line data unlike the fresh layout"));
}
+ compare_children(node, &expected.children, &fresh.children)
}
fn nodes_of(links: &[fragment_tree::FragmentLink]) -> Vec<Node> {
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index a46c54954d9..c7d26a62de5 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -2267,10 +2267,7 @@ impl<'pass> SvgFormattingContext<'pass> {
formatting_context::PlacedChild::laid_out_here(cells.get(), None, &self.run),
committed_offset.x,
committed_offset.y,
- Some(fragment_tree::ChildFragmentArrival::CommittedFragment {
- fragment,
- reuses_committed_subtree: false,
- }),
+ Some(fragment_tree::ChildFragmentArrival::CommittedFragment(fragment)),
);
Some(LaidOutSvgElement {
cells: cells.get(),
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index 9e83b4a41f5..58208035e03 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -220,7 +220,6 @@ impl<'a> PaintableCommit<'a> {
&mut self,
node: formatting_context::Node,
link: &fragment_tree::FragmentLink,
- reuses_committed_subtree: bool,
enclosing_line_root_changes: LineRootChanges,
previous_offset: Option<used_values::FfiCssPixelPoint>,
) -> ReplacedCommittedFragmentLink {
@@ -246,57 +245,48 @@ impl<'a> PaintableCommit<'a> {
};
let mut content_size_change = None;
let mut own_paint_unchanged = false;
- let mut root_box_unchanged = false;
let mut child_placements_unchanged = false;
let mut inline_content_unchanged = false;
let mut inline_item_order_unchanged = false;
let mut child_sequence_unchanged = false;
let mut link_shows_box_the_same = true;
- let (old_identity, old_content_size, old_content_inline_size) =
- self.arena().with_committed_fragment_link(node, |old_link| {
- old_link.map_or((0, used_values::FfiCssPixelSize::default(), None), |old_link| {
- let previous = &old_link.fragment;
- if reuses_committed_subtree || previous.identity == fragment.identity {
- root_box_unchanged =
- std::sync::Arc::ptr_eq(fragment, previous) || fragment.has_same_box_properties(previous);
- own_paint_unchanged = root_box_unchanged;
- child_placements_unchanged = true;
- inline_content_unchanged = true;
- inline_item_order_unchanged = true;
- child_sequence_unchanged = true;
- } else {
- inline_content_unchanged = same_inline_content(fragment, previous);
- inline_item_order_unchanged = inline_content_unchanged
- || match (&fragment.line_data, &previous.line_data) {
- (Some(left), Some(right)) => left.has_same_item_order(right),
- _ => false,
- };
- own_paint_unchanged = inline_content_unchanged
- && fragment.has_same_box_properties(previous)
- && !has_descendant_dependent_paint(self.arena(), node);
- child_placements_unchanged = fragment.has_same_child_placements(previous);
- child_sequence_unchanged = fragment.has_same_child_sequence(previous);
- }
- own_paint_unchanged &= old_link.has_same_placement(link);
- link_shows_box_the_same = link.shows_box_as(old_link);
- (
- old_link.fragment.identity,
- frame.size_to_physical(
- old_link.fragment.content_inline_size,
- old_link.fragment.content_block_size,
- ),
- Some(old_link.fragment.content_inline_size),
- )
- })
- });
+ let (old_identity, old_content_size) = self.arena().with_committed_fragment_link(node, |old_link| {
+ old_link.map_or((0, used_values::FfiCssPixelSize::default()), |old_link| {
+ let previous = &old_link.fragment;
+ if previous.identity == fragment.identity {
+ own_paint_unchanged = true;
+ child_placements_unchanged = true;
+ inline_content_unchanged = true;
+ inline_item_order_unchanged = true;
+ child_sequence_unchanged = true;
+ } else {
+ inline_content_unchanged = same_inline_content(fragment, previous);
+ inline_item_order_unchanged = inline_content_unchanged
+ || match (&fragment.line_data, &previous.line_data) {
+ (Some(left), Some(right)) => left.has_same_item_order(right),
+ _ => false,
+ };
+ own_paint_unchanged = inline_content_unchanged
+ && fragment.has_same_box_properties(previous)
+ && !has_descendant_dependent_paint(self.arena(), node);
+ child_placements_unchanged = fragment.has_same_child_placements(previous);
+ child_sequence_unchanged = fragment.has_same_child_sequence(previous);
+ }
+ own_paint_unchanged &= old_link.has_same_placement(link);
+ link_shows_box_the_same = link.shows_box_as(old_link);
+ (
+ old_link.fragment.identity,
+ frame.size_to_physical(
+ old_link.fragment.content_inline_size,
+ old_link.fragment.content_block_size,
+ ),
+ )
+ })
+ });
if old_content_size != new_content_size {
if self.arena().data(node).kind.get() == NodeKind::Viewport {
self.arena_mut().set_needs_full_scrollable_overflow_recalculation();
}
- assert!(
- !reuses_committed_subtree || old_content_inline_size == Some(fragment.content_inline_size),
- "a reused committed subtree changed its content inline size"
- );
content_size_change = Some((old_content_size, new_content_size));
}
let committed_fragment_identity_changed = old_identity != fragment.identity;
@@ -312,11 +302,9 @@ impl<'a> PaintableCommit<'a> {
let fragment_content_changed = committed_fragment_identity_changed
|| (enclosing_line_root_changes.fragment_changed && painted_geometry_lives_in_enclosing_line_root);
// Keep fragment identity as the conservative signal for overflow and visual contexts.
- // A reused run root can have a new identity while its box and subtree are unchanged.
// The fragment stays the same when only the link's margins or parent-decided facts change, but margin-box clip
// paths, line clamp clips and overflow read those.
- let fragment_content_unchanged = link_shows_box_the_same
- && ((reuses_committed_subtree && root_box_unchanged) || (old_identity != 0 && !fragment_content_changed));
+ let fragment_content_unchanged = link_shows_box_the_same && old_identity != 0 && !fragment_content_changed;
let offset_unchanged = previous_offset == Some(new_offset);
let enclosing_inline_paint_changed = painted_geometry_lives_in_enclosing_line_root
&& (enclosing_line_root_changes.inline_content_changed
diff --git a/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.txt b/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree.txt
similarity index 71%
rename from Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.txt
rename to Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree.txt
index 578483045f2..62df3a9b2ef 100644
--- a/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.txt
+++ b/Tests/LibWeb/Text/expected/layout-run-cache-measurement-replay-of-recommitted-subtree.txt
@@ -2,4 +2,4 @@ PASS: a pass that leaves the button alone (work)
PASS: another pass that leaves the button alone, after which its stored measurements age out (work)
PASS: measuring the button reuses the inline-block committed in an earlier pass (work)
PASS: a narrower button commits the inline-block anew (work)
-PASS: the stored measurement misses once the inline-block it reused was committed anew (work + checks)
+PASS: the stored measurement replays the inline-block it laid out, though it was committed anew since (work + checks)
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.html b/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.html
index 5d97af414d8..8de1a125ddc 100644
--- a/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.html
+++ b/Tests/LibWeb/Text/input/layout-run-cache-measured-content-committed-by-replay.html
@@ -90,8 +90,7 @@
BlockContainer(anonymous)/flex RUN (cache=miss)
BlockContainer(anonymous) MEASURE max-content block (cache=hit)
BlockContainer(anonymous) MEASURE max-content block (cache=hit)
- BlockContainer(anonymous)/block RUN (cache=miss)
- BlockContainer<DIV>#marker.marker/block REUSE SUBTREE
+ BlockContainer(anonymous)/block REPLAY FRAGMENTS
BlockContainer(anonymous)/flex REPLAY FRAGMENTS
BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE
`,
diff --git a/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.html b/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree.html
similarity index 93%
rename from Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.html
rename to Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree.html
index af710aa3ea1..807780bc3dc 100644
--- a/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree-misses.html
+++ b/Tests/LibWeb/Text/input/layout-run-cache-measurement-replay-of-recommitted-subtree.html
@@ -102,7 +102,7 @@
`,
},
{
- name: "the stored measurement misses once the inline-block it reused was committed anew",
+ name: "the stored measurement replays the inline-block it laid out, though it was committed anew since",
mutate: () => {
button.style.width = "180px";
button.style.minHeight = "0px";
@@ -116,10 +116,7 @@
BlockContainer(anonymous)/flex RUN (cache=miss)
BlockContainer(anonymous) MEASURE max-content block (cache=hit)
BlockContainer(anonymous) MEASURE max-content block (cache=hit)
- BlockContainer(anonymous)/block RUN (cache=miss)
- BlockContainer<DIV>#marker.marker/block RUN (cache=miss)
- BlockContainer<DIV>#marker.marker MEASURE max-content inline (cache=hit)
- BlockContainer<DIV>#marker.marker MEASURE min-content inline (cache=hit)
+ BlockContainer(anonymous)/block REPLAY FRAGMENTS
BlockContainer(anonymous)/flex REPLAY FRAGMENTS
BlockContainer<DIV>#spacer REUSE IN-FLOW SUBTREE
`,