LibWeb: Don't invalidate layout tree on all DOM node removals

DOM nodes that didn't have a layout node before being removed from the
DOM are not going to change the shape of the layout tree after being
removed.

Observing this, we can avoid a full layout tree rebuild on some DOM node
removals.

This avoids a bunch of tree building work when loading https://x.com/

(cherry picked from commit 6f34758947852abae773798ba3ffa8e903fdc3d0)
This commit is contained in:
Andreas Kling authored and Nico Weber committed 2024-11-04 13:17:01 -05:00
1 parent 5c4c048195
commit da526bac92
1 file changed
+7 -1
+7 -1
View File
@@ -714,6 +714,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Node>> Node::append_child(JS::NonnullGCPtr<
void Node::remove(bool suppress_observers)
{
bool was_connected = is_connected();
bool had_layout_node = layout_node();
// 1. Let parent be node’s parent
auto* parent = this->parent();
@@ -855,7 +856,12 @@ void Node::remove(bool suppress_observers)
// Since the tree structure has changed, we need to invalidate both style and layout.
// In the future, we should find a way to only invalidate the parts that actually need it.
document().invalidate_style(StyleInvalidationReason::NodeRemove);
document().invalidate_layout_tree();
// NOTE: If we didn't have a layout node before, rebuilding the layout tree isn't gonna give us one
// after we've been removed from the DOM.
if (had_layout_node) {
document().invalidate_layout_tree();
}
}
document().bump_dom_tree_version();