From 5431db8c1c9d366d0a27959cfbf0f146bf4be20d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 Nov 2024 19:49:08 +0100 Subject: [PATCH] LibWeb: Avoid unnecessary style recomputation during traversal While traversing the DOM tree, looking for nodes that need a style update, we were recomputing style for every node visited along the way, even nodes that didn't themselves need a style update (but one of their descendants did). This avoids a bunch of completely unnecessary style recomputation on basically every website. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f22d272868d..83dd9cdc94e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1258,7 +1258,9 @@ void Document::update_layout() bool is_display_none = false; if (is(node)) { - invalidation |= static_cast(node).recompute_style(); + if (needs_full_style_update || node.needs_style_update()) { + invalidation |= static_cast(node).recompute_style(); + } is_display_none = static_cast(node).computed_css_values()->display().is_none(); } node.set_needs_style_update(false);