LibWeb: Enable partial layout tree update in a bunch of cases

These common cases now cause us to invalidate the layout tree starting
at the relevant parent node instead of invalidating the entire tree.

- DOM node insertion
- DOM node removal
- innerHTML setter
- textContent setter

This makes a lot of dynamic content much faster. For example, demos
on shadertoy.com go from ~18 fps to ~28 fps on my machine.
This commit is contained in:
Andreas Kling 2025-01-16 00:44:35 +01:00 committed by Andreas Kling
commit e5d521bef8
Notes: github-actions[bot] 2025-01-18 20:01:59 +00:00
2 changed files with 5 additions and 6 deletions

View file

@ -228,7 +228,7 @@ void Node::set_text_content(Optional<String> const& maybe_content)
if (is_connected()) {
invalidate_style(StyleInvalidationReason::NodeSetTextContent);
document().invalidate_layout_tree();
set_needs_layout_tree_update(true);
}
document().bump_dom_tree_version();
@ -727,7 +727,7 @@ void Node::insert_before(GC::Ref<Node> node, GC::Ptr<Node> child, bool suppress_
if (is_connected()) {
// FIXME: This will need to become smarter when we implement the :has() selector.
invalidate_style(StyleInvalidationReason::ParentOfInsertedNode);
document().invalidate_layout_tree();
set_needs_layout_tree_update(true);
}
document().bump_dom_tree_version();
@ -835,9 +835,8 @@ void Node::remove(bool suppress_observers)
// 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 (layout_node()) {
document().invalidate_layout_tree();
}
if (layout_node())
parent->set_needs_layout_tree_update(true);
}
// 11. Remove node from its parents children.