Skip to content

Truly independent web browser

LibWeb: Skip committing a reused subtree whose link is already committed

Andreas Kling9ab95a4972d8
diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rs
index 4f07c021f3e..2c630c0dccf 100644
--- a/Libraries/LibWeb/Rust/src/layout/commit.rs
+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs
@@ -114,6 +114,18 @@ fn commit_subtree(
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());
+ // 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
+ // 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
+ && link.abspos_layout_inputs.is_none()
+ && !link.containing_block.is_invalid()
+ && paintables.arena().data(node).kind.get() != NodeKind::NavigableContainerViewport
+ && paintables.arena().holds_current_committed_fragment_link(node, link)
+ {
+ return;
+ }
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 56fe19276d9..12f02bfea8e 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -4869,6 +4869,20 @@ impl LayoutNodeArena {
(!self.fragment_cache_epoch_changed_during_layout_pass.get()).then(|| data.fragment_cache_epoch.get())
}
+ /// Whether `id` committed `link` already, placed the same way, in a layout its geometry is still current for.
+ pub(crate) fn holds_current_committed_fragment_link(
+ &self,
+ id: NodeSlotId,
+ link: &super::fragment_tree::FragmentLink,
+ ) -> bool {
+ self.paintable_rows.holds_current_committed_fragment_link(
+ id.slot_index(),
+ id.generation(),
+ self.data(id).fragment_cache_epoch.get(),
+ link,
+ )
+ }
+
pub(crate) fn with_current_committed_fragment<R>(
&self,
node: NodeSlotId,
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
index 5309d4354aa..06e73715982 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs
@@ -578,6 +578,26 @@ impl PaintableRowStore {
Some(read(&slot.link.as_ref()?.fragment))
}
+ /// Whether the slot holds `link` already, placed the same way, with geometry current for `geometry_epoch`.
+ pub(crate) fn holds_current_committed_fragment_link(
+ &self,
+ layout_slot_index: u32,
+ layout_slot_generation: u8,
+ geometry_epoch: u32,
+ link: &fragment_tree::FragmentLink,
+ ) -> bool {
+ let slots = self.committed_fragment_links.borrow();
+ slots.get(layout_slot_index as usize).is_some_and(|slot| {
+ slot.layout_slot_generation == layout_slot_generation
+ && slot.geometry_is_current
+ && slot.geometry_epoch == geometry_epoch
+ && slot
+ .link
+ .as_ref()
+ .is_some_and(|committed| link.places_same_fragment_identically_to(committed))
+ })
+ }
+
pub(crate) fn invalidate_committed_geometry(&self, layout_slot_index: u32) {
if let Some(mut slot) = RowMut::new(self.committed_fragment_links.borrow_mut(), layout_slot_index as usize) {
slot.geometry_is_current = false;