Skip to content

Truly independent web browser

LibWeb: Stop deriving layout facts before each layout stage

Aliaksandr Kalenikfda48dc21c6c
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 7521c8b50cf..ef2bb2a18a7 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -3519,7 +3519,7 @@ impl LayoutStageJob {
/// committing them owes the host.
fn run(self, state: &mut super::ArenaHandle) -> commit::CommitNotifications {
let Self { kind, root, stage } = self;
- prepare_layout_stage(state, kind, root);
+ prepare_layout_stage(state, kind);
let input = LayoutStageInput {
arena: state.arena(),
scratch: state.layout_scratch(),
@@ -3655,27 +3655,12 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
})
}
-/// Brings the arena up to date for a stage before the stage borrows it: derives the facts its runs read, marks the
-/// flex and grid items of the nodes marked for layout, and applies the arena's memo invalidations to the stage's
-/// memos.
-fn prepare_layout_stage(state: &mut super::ArenaHandle, kind: LayoutStageKind, root: NodeSlotId) {
+/// Brings the arena up to date for a stage before the stage borrows it: a root stage covers whatever kept pending
+/// updates from a partial relayout, and the stage's memos take the arena's memo invalidations.
+fn prepare_layout_stage(state: &mut super::ArenaHandle, kind: LayoutStageKind) {
let (arena, scratch) = state.arena_mut_and_layout_scratch();
- match kind {
- LayoutStageKind::Root { .. } => {
- // NB: Boxes take their facts as they are attached. Unclassified invalidations require deriving
- // them for the entire tree instead.
- if arena.pending_updates_escape_partial_relayout {
- arena.derive_facts_in_subtree(root);
- arena.clear_partial_relayout_escape();
- }
- arena.mark_flex_and_grid_items_of_nodes_marked_for_layout();
- }
- LayoutStageKind::Boundary { .. } => {
- // The boundary can be wider than the rebuilt roots that led to it, and laying it out may
- // re-enter intrinsic sizing for descendants outside those roots, including anonymous boxes
- // the incremental tree build created; derive the facts of the whole subtree.
- arena.derive_facts_in_subtree(root);
- }
+ if matches!(kind, LayoutStageKind::Root { .. }) {
+ arena.clear_partial_relayout_escape();
}
scratch.apply_memo_invalidations(arena);
scratch.layout_trace.take_over_from(&mut arena.layout_trace);
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 8e8a3279a7e..22531c024f2 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -4005,9 +4005,7 @@ impl LayoutNodeArena {
first_styled_child = self.data(first_styled_child).next_sibling.get();
}
if !first_styled_child.is_invalid()
- && super::node_facts::has_ancestor_fact(self.data(first_styled_child), AncestorFact::ParentLaysOutInColumns)
- != super::node_facts::node_style_view(self.data(slot))
- .is_some_and(|style| super::node_facts::node_lays_out_in_columns(self.data(slot), style))
+ && self.ancestor_facts_from_parent(first_styled_child) != self.data(first_styled_child).ancestor_facts
{
let mut child = first_styled_child;
while !child.is_invalid() {
@@ -4019,23 +4017,6 @@ impl LayoutNodeArena {
}
}
- /// Marks the flex and grid items among the nodes marked for layout and their children, ahead of the layout that
- /// lays them out: a style change can make a box, or the children of a box, items without rebuilding them.
- pub(crate) fn mark_flex_and_grid_items_of_nodes_marked_for_layout(&mut self) {
- let nodes = self.nodes_with_layout_update_flags.clone();
- for node in nodes {
- if !self.slot_is_live(node) {
- continue;
- }
- self.derive_flex_or_grid_item_flags(node);
- let mut child = self.data(node).first_child.get();
- while !child.is_invalid() {
- self.derive_flex_or_grid_item_flags(child);
- child = self.data(child).next_sibling.get();
- }
- }
- }
-
pub(crate) fn enroll_text_node_for_content_sync(&mut self, node: NodeSlotId) {
self.text_nodes_enrolled_for_content_sync.insert(node);
}
@@ -4705,6 +4686,11 @@ impl LayoutNodeArena {
/// Returns whether the node's ancestor facts changed.
fn derive_ancestor_facts_for_node(&mut self, node: NodeSlotId) -> bool {
+ let facts = self.ancestor_facts_from_parent(node);
+ std::mem::replace(self.unpublished_facts_mut(node).ancestor_facts, facts) != facts
+ }
+
+ fn ancestor_facts_from_parent(&self, node: NodeSlotId) -> u8 {
let data = self.data(node);
let parent = data.parent.get();
let mut facts = 0;
@@ -4744,7 +4730,7 @@ impl LayoutNodeArena {
}
}
}
- std::mem::replace(self.unpublished_facts_mut(node).ancestor_facts, facts) != facts
+ facts
}
/// A style change reaches the anonymous boxes below the node without rebuilding them, and
@@ -4762,20 +4748,6 @@ impl LayoutNodeArena {
}
}
- /// Derives what the nodes in the inclusive subtree of `root` take from their ancestors: whether they
- /// establish containing blocks, and their ancestor facts, which the pre-order walk finds already derived
- /// for the parent. Out-of-flow boxes in the subtree also mark the ancestors they escape.
- pub(crate) fn derive_facts_in_subtree(&mut self, root: NodeSlotId) {
- let mut cursor = Some(root);
- while let Some(node) = cursor {
- self.derive_containing_block_establishment_flags(node);
- self.mark_nodes_escaped_by_attached_out_of_flow_box(node);
- self.derive_ancestor_facts_for_node(node);
- self.derive_flex_or_grid_item_flags(node);
- cursor = self.next_node_in_layout_subtree_in_pre_order(root, node);
- }
- }
-
fn derive_facts_of_attached_node(&mut self, node: NodeSlotId) {
self.derive_containing_block_establishment_flags(node);
let brings_children = !self.data(node).first_child.get().is_invalid();
diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
index b862547ba39..447726011cd 100644
--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs
@@ -283,7 +283,7 @@ impl LayoutNodeArena {
/// Selects the boundary subtrees to relay out after the layout tree build. Consumes the
/// escape bit either way: a refusal here is followed by a full layout pass in the same
- /// update, which re-derives every fact the bit stands in for.
+ /// update.
pub(crate) fn plan_partial_relayout(
&mut self,
root: NodeSlotId,