LibWeb: Avoid copying large MatchingRule objects inside StyleComputer

Instead of creating and passing around Vector<MatchingRule> inside
StyleComputer (internally, not exposed in API), we now use vectors
of pointers/references instead.

Note that we use pointers in case we want to quick_sort() the vectors.

Knocks 4 seconds of loading time off of https://wpt.fyi/
This commit is contained in:
Andreas Kling 2025-01-24 15:47:42 +01:00 committed by Andreas Kling
commit 055f07d742
Notes: github-actions[bot] 2025-01-24 16:55:34 +00:00
2 changed files with 52 additions and 64 deletions

View file

@ -87,7 +87,6 @@ struct MatchingRule {
bool contains_pseudo_element { false };
bool can_use_fast_matches { false };
bool must_be_hovered { false };
bool skip { false };
// Helpers to deal with the fact that `rule` might be a CSSStyleRule or a CSSNestedDeclarations
PropertyOwningCSSStyleDeclaration const& declaration() const;
@ -148,7 +147,7 @@ public:
[[nodiscard]] GC::Ptr<ComputedProperties> compute_pseudo_element_style_if_needed(DOM::Element&, Optional<CSS::Selector::PseudoElement::Type>) const;
Vector<MatchingRule> const& get_hover_rules() const;
Vector<MatchingRule> collect_matching_rules(DOM::Element const&, CascadeOrigin, Optional<CSS::Selector::PseudoElement::Type>, bool& did_match_any_hover_rules, FlyString const& qualified_layer_name = {}) const;
[[nodiscard]] Vector<MatchingRule const*> collect_matching_rules(DOM::Element const&, CascadeOrigin, Optional<CSS::Selector::PseudoElement::Type>, bool& did_match_any_hover_rules, FlyString const& qualified_layer_name = {}) const;
InvalidationSet invalidation_set_for_properties(Vector<InvalidationSet::Property> const&) const;
bool invalidation_property_used_in_has_selector(InvalidationSet::Property const&) const;
@ -233,12 +232,12 @@ private:
struct LayerMatchingRules {
FlyString qualified_layer_name;
Vector<MatchingRule> rules;
Vector<MatchingRule const*> rules;
};
struct MatchingRuleSet {
Vector<MatchingRule> user_agent_rules;
Vector<MatchingRule> user_rules;
Vector<MatchingRule const*> user_agent_rules;
Vector<MatchingRule const*> user_rules;
Vector<LayerMatchingRules> author_rules;
};
@ -246,7 +245,7 @@ private:
CascadedProperties&,
DOM::Element&,
Optional<CSS::Selector::PseudoElement::Type>,
Vector<MatchingRule> const&,
Vector<MatchingRule const*> const&,
CascadeOrigin,
Important,
Optional<FlyString> layer_name) const;