Skip to content

Truly independent web browser

LibWeb: Commit an unchanged childless box like a reused subtree

Andreas Klingb3b69c57f0ff
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index 570da6c513f..4f07c021f3e 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -88,6 +88,19 @@ 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 {
+ let data = arena.data(node);
+ data.first_child.get().is_invalid()
+ && node_facts::kind_is_box(data.kind.get())
+ && arena.paintable_row_is_populated(node)
+ && arena
+ .with_current_committed_fragment(node, |committed| std::sync::Arc::ptr_eq(committed, &link.fragment))
+ .unwrap_or(false)
+}
+
fn commit_subtree(
node: Node,
messages: &mut Vec<FfiCommitMessage>,
@@ -98,7 +111,8 @@ fn commit_subtree(
) {
let slot_index = node.slot_index();
let entry = links_by_slot.get(&slot_index).copied();
- let reuses_committed_subtree = pass_fragments.subtree_was_reused(slot_index);
+ let reuses_committed_subtree = 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());
if !reuses_committed_subtree {
paintables.arena().forget_committed_out_of_flow_facts(node);
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 534b8e6a9b7..a6dc4ddf0d2 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -4340,6 +4340,11 @@ impl LayoutNodeArena {
self.remove_layout_update_flag_node(id);
}
data.set_flags(updated);
+ // A box that becomes a flex or grid item can lay out to the fragment it committed before, but orders its
+ // painting differently, so its committed geometry no longer lets its commit be skipped.
+ if matches!(flag, NodeFlag::IsFlexItem | NodeFlag::IsGridItem) && updated != previous {
+ self.paintable_rows.invalidate_committed_geometry(id.slot_index());
+ }
// Retaining compositor-animated content decides whether a non-invertible transform
// still records its stacking context.
if flag == NodeFlag::HasAnimatedOpacityOrTransform && updated != previous {
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index ab00576d859..e910697a2a2 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -233,7 +233,8 @@ impl<'a> PaintableCommit<'a> {
old_link.map_or((0, used_values::FfiCssPixelSize::default()), |old_link| {
let previous = &old_link.fragment;
if reuses_committed_subtree || previous.identity == fragment.identity {
- root_box_unchanged = fragment.has_same_box_properties(previous);
+ 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;