mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
LibWeb: Don't rebuild rule cache so eagerly to check for :has/:defined
Instead, change the APIs from "has :foo" to "may have :foo" and return true if we don't have a valid rule cache at the moment. This allows us to defer the rebuilding of the rule cache until a later time, for the cost of a wider invalidation at the moment. Do note that if our rule cache is invalid, the whole document has invalid style anyway! So this is actually always less work. :^) Knocks ~1 second of loading time off of https://wpt.fyi/
This commit is contained in:
parent
3b3f06ca68
commit
4bef0d0aea
Notes:
github-actions[bot]
2025-01-24 16:55:43 +00:00
Author: https://github.com/awesomekling
Commit: 4bef0d0aea
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3356
5 changed files with 13 additions and 12 deletions
|
@ -2530,7 +2530,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
|
||||||
|
|
||||||
void StyleComputer::build_rule_cache_if_needed() const
|
void StyleComputer::build_rule_cache_if_needed() const
|
||||||
{
|
{
|
||||||
if (m_author_rule_cache && m_user_rule_cache && m_user_agent_rule_cache)
|
if (has_valid_rule_cache())
|
||||||
return;
|
return;
|
||||||
const_cast<StyleComputer&>(*this).build_rule_cache();
|
const_cast<StyleComputer&>(*this).build_rule_cache();
|
||||||
}
|
}
|
||||||
|
@ -3077,19 +3077,19 @@ size_t StyleComputer::number_of_css_font_faces_with_loading_in_progress() const
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyleComputer::has_has_selectors() const
|
bool StyleComputer::may_have_has_selectors() const
|
||||||
{
|
{
|
||||||
if (!document().is_active())
|
if (!has_valid_rule_cache())
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
build_rule_cache_if_needed();
|
build_rule_cache_if_needed();
|
||||||
return m_selector_insights->has_has_selectors;
|
return m_selector_insights->has_has_selectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyleComputer::has_defined_selectors() const
|
bool StyleComputer::may_have_defined_selectors() const
|
||||||
{
|
{
|
||||||
if (!document().is_active())
|
if (!has_valid_rule_cache())
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
build_rule_cache_if_needed();
|
build_rule_cache_if_needed();
|
||||||
return m_selector_insights->has_defined_selectors;
|
return m_selector_insights->has_defined_selectors;
|
||||||
|
|
|
@ -153,6 +153,7 @@ public:
|
||||||
InvalidationSet invalidation_set_for_properties(Vector<InvalidationSet::Property> const&) const;
|
InvalidationSet invalidation_set_for_properties(Vector<InvalidationSet::Property> const&) const;
|
||||||
bool invalidation_property_used_in_has_selector(InvalidationSet::Property const&) const;
|
bool invalidation_property_used_in_has_selector(InvalidationSet::Property const&) const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool has_valid_rule_cache() const { return m_author_rule_cache; }
|
||||||
void invalidate_rule_cache();
|
void invalidate_rule_cache();
|
||||||
|
|
||||||
Gfx::Font const& initial_font() const;
|
Gfx::Font const& initial_font() const;
|
||||||
|
@ -176,8 +177,8 @@ public:
|
||||||
};
|
};
|
||||||
void collect_animation_into(DOM::Element&, Optional<CSS::Selector::PseudoElement::Type>, GC::Ref<Animations::KeyframeEffect> animation, ComputedProperties&, AnimationRefresh = AnimationRefresh::No) const;
|
void collect_animation_into(DOM::Element&, Optional<CSS::Selector::PseudoElement::Type>, GC::Ref<Animations::KeyframeEffect> animation, ComputedProperties&, AnimationRefresh = AnimationRefresh::No) const;
|
||||||
|
|
||||||
[[nodiscard]] bool has_has_selectors() const;
|
[[nodiscard]] bool may_have_has_selectors() const;
|
||||||
[[nodiscard]] bool has_defined_selectors() const;
|
[[nodiscard]] bool may_have_defined_selectors() const;
|
||||||
|
|
||||||
size_t number_of_css_font_faces_with_loading_in_progress() const;
|
size_t number_of_css_font_faces_with_loading_in_progress() const;
|
||||||
|
|
||||||
|
|
|
@ -1617,7 +1617,7 @@ void Document::invalidate_style_for_elements_affected_by_hover_change(Node& old_
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& invalidation_root = [&] -> Node& {
|
auto& invalidation_root = [&] -> Node& {
|
||||||
if (style_computer().has_has_selectors())
|
if (style_computer().may_have_has_selectors())
|
||||||
return old_new_hovered_common_ancestor;
|
return old_new_hovered_common_ancestor;
|
||||||
return old_new_hovered_common_ancestor;
|
return old_new_hovered_common_ancestor;
|
||||||
}();
|
}();
|
||||||
|
|
|
@ -2328,7 +2328,7 @@ void Element::set_custom_element_state(CustomElementState state)
|
||||||
return;
|
return;
|
||||||
m_custom_element_state = state;
|
m_custom_element_state = state;
|
||||||
|
|
||||||
if (document().style_computer().has_defined_selectors())
|
if (document().style_computer().may_have_defined_selectors())
|
||||||
invalidate_style(StyleInvalidationReason::CustomElementStateChange);
|
invalidate_style(StyleInvalidationReason::CustomElementStateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -408,7 +408,7 @@ void Node::invalidate_style(StyleInvalidationReason reason)
|
||||||
|
|
||||||
// FIXME: This is very not optimal! We should figure out a smaller set of elements to invalidate,
|
// FIXME: This is very not optimal! We should figure out a smaller set of elements to invalidate,
|
||||||
// but right now the :has() selector means we have to invalidate everything.
|
// but right now the :has() selector means we have to invalidate everything.
|
||||||
if (!is_document() && document().style_computer().has_has_selectors()) {
|
if (!is_document() && document().style_computer().may_have_has_selectors()) {
|
||||||
document().invalidate_style(reason);
|
document().invalidate_style(reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue