From c3059701b0563f127c127d986ad3a2f51b4bce79 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 13 Jan 2024 11:38:30 +0100 Subject: [PATCH] LibWeb: Avoid style invalidation when entire document has invalid style If the entire document is invalidated, we know a full style update is coming soon, and there's no need to try and invalidate a smaller part. This avoids a *lot* of work on some pages. As an example, we are able to skip ~1.5 million style invalidations on https://html.spec.whatwg.org/ --- Userland/Libraries/LibWeb/DOM/Node.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index f935ab6148..cf31ce0d90 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -261,6 +261,11 @@ void Node::invalidate_style() return; } + // If the document is already marked for a full style update, there's no need to do anything here. + if (document().needs_full_style_update()) { + return; + } + for_each_in_inclusive_subtree([&](Node& node) { node.m_needs_style_update = true; if (node.has_children())