Skip to content

Commit

Permalink
LibWeb: Avoid unnecessary style recomputation during traversal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awesomekling committed Nov 6, 2024
1 parent 0de9818 commit 5431db8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,9 @@ void Document::update_layout()
bool is_display_none = false;

if (is<Element>(node)) {
invalidation |= static_cast<Element&>(node).recompute_style();
if (needs_full_style_update || node.needs_style_update()) {
invalidation |= static_cast<Element&>(node).recompute_style();
}
is_display_none = static_cast<Element&>(node).computed_css_values()->display().is_none();
}
node.set_needs_style_update(false);
Expand Down

0 comments on commit 5431db8

Please sign in to comment.