Skip to content

Truly independent web browser

LibWeb: Skip gathering container geometry when no container is held

Andreas Kling6e7c74bb5dac
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index fce113c0115..1c71b6f8ead 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -1307,6 +1307,12 @@ impl RetainedState {
self.layout_style_snapshots.get(&node).copied()
}
+ /// Whether any container's box is held. Size and scroll-state containers get rows, and an element that stops being
+ /// one keeps its row until it goes.
+ pub(crate) fn has_layout_style_snapshots(&self) -> bool {
+ !self.layout_style_snapshots.is_empty()
+ }
+
/// Take the box geometry a completed layout commit gathered, keeping each row's scroll state.
pub(crate) fn apply_layout_style_snapshot_commit(
&mut self,
diff --git a/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs b/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs
index 896a796561c..14e77ffdd02 100644
--- a/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs
+++ b/Libraries/LibWeb/Rust/src/layout/style_snapshot.rs
@@ -37,21 +37,15 @@ pub(crate) struct CommittedGeometry {
}
impl LayoutNodeArena {
- /// The style node a node's row is for, and whether the node's style makes it a size container;
- /// `None` for a node whose box the style engine takes no row of.
- fn snapshot_target(&self, node: NodeSlotId) -> Option<(StyleNodeID, bool)> {
+ /// The style node a node's row is for; `None` for a node whose box the style engine takes no row of.
+ fn snapshot_target(&self, node: NodeSlotId) -> Option<StyleNodeID> {
let style_node = self
.node_style_node(node)
.filter(|style_node| style_node.element_index().is_some())?;
if !self.has_style_engine() || self.bound_row(style_node) != node {
return None;
}
- let style = crate::layout::node_facts::node_style_view(self.data(node));
- let is_size_container = style.is_some_and(|style| {
- let box_values = style.box_values();
- box_values.is_size_container || box_values.is_inline_size_container
- });
- Some((style_node, is_size_container))
+ Some(style_node)
}
fn committed_geometry(&self, node: NodeSlotId, style_node: StyleNodeID) -> CommittedGeometry {
@@ -74,7 +68,15 @@ impl LayoutNodeArena {
/// and about scroll-state containers, whose rows the scroll state makes; an element that
/// stops being one keeps its row up to date until it goes.
pub(crate) fn gather_layout_style_snapshot_geometry(&self, node: NodeSlotId) {
- let Some((style_node, is_size_container)) = self.snapshot_target(node) else {
+ let is_size_container = node_is_size_container(self, node);
+ // OPTIMIZATION: Most committed boxes are no size container, and while no container is held, none is gathered.
+ if !is_size_container
+ && self.has_style_engine()
+ && !self.with_style_store(|engine| engine.has_layout_style_snapshots())
+ {
+ return;
+ }
+ let Some(style_node) = self.snapshot_target(node) else {
return;
};
if !is_size_container && !self.with_style_store(|engine| engine.layout_style_snapshot(style_node).is_some()) {
@@ -88,7 +90,10 @@ impl LayoutNodeArena {
/// container, which the last commit gathered no row for. Until the next commit, a size query
/// on it reads that box, as the host's evaluation reads the box it holds.
pub(crate) fn publish_new_size_container_geometry(&self, node: NodeSlotId) {
- let Some((style_node, true)) = self.snapshot_target(node) else {
+ if !node_is_size_container(self, node) {
+ return;
+ }
+ let Some(style_node) = self.snapshot_target(node) else {
return;
};
if self.with_style_store(|engine| engine.layout_style_snapshot(style_node).is_some()) {
@@ -161,3 +166,10 @@ mod tests {
assert_eq!((row.content_width_raw, row.stuck), (11, 0));
}
}
+
+fn node_is_size_container(arena: &LayoutNodeArena, node: NodeSlotId) -> bool {
+ crate::layout::node_facts::node_style_view(arena.data(node)).is_some_and(|style| {
+ let box_values = style.box_values();
+ box_values.is_size_container || box_values.is_inline_size_container
+ })
+}