LibWeb: Cache is_body() on layout nodes

Cache the result of the body element check as a bool set once during
NodeWithStyle construction, instead of calling document().body() (which
walks the children of <html>) on every call. This is called from
PaintableBox::paint_background() for every box on every frame.

This was 0.9% of CPU time while playing a YouTube video.
This commit is contained in:
Andreas Kling
2026-02-21 01:54:45 +01:00
committed by Andreas Kling
parent a0768e9bac
commit 1b41c9109d
Notes: github-actions[bot] 2026-02-21 14:54:58 +00:00
2 changed files with 4 additions and 6 deletions

View File

@@ -560,6 +560,7 @@ NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, GC::Ref<C
, m_computed_values(make<CSS::ComputedValues>())
{
m_has_style = true;
m_is_body = node && node == document.body();
apply_style(computed_style);
}
@@ -568,6 +569,7 @@ NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullOw
, m_computed_values(move(computed_values))
{
m_has_style = true;
m_is_body = node && node == document.body();
}
void NodeWithStyle::visit_edges(Visitor& visitor)
@@ -1133,11 +1135,6 @@ void NodeWithStyle::transfer_table_box_computed_values_to_wrapper_computed_value
reset_table_box_computed_values_used_by_wrapper_to_init_values();
}
bool NodeWithStyle::is_body() const
{
return dom_node() && dom_node() == document().body();
}
bool overflow_value_makes_box_a_scroll_container(CSS::Overflow overflow)
{
switch (overflow) {