mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-04 15:19:16 +00:00
LibWeb: Invalidate less elements affected by CSS custom properties
Before this change, whenever element's attributes changed, we would add a flag to "pending invalidation", indicating that all descendants whose style uses CSS custom properties needed to be recomputed. This resulted in severe overinvalidation, because we would run invalidation regardless of whether any custom property on affected element actually changed. This change takes another approach, and now we decide whether descendant's style needs to be recomputed based on whether ancestor's style recomputation results in a change of custom properties, though this approach adds a little overhead to style computation as now we have to compare old vs new hashmap of custom properties. This brings substantial improvement on discord and x.com where, before this change, advantage of using invalidation sets was lost and we had to recompute all descendants, because almost all of them use custom properties.
This commit is contained in:
parent
cbe4ba60c3
commit
d1fbb7b51e
Notes:
github-actions[bot]
2025-07-30 09:07:23 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: d1fbb7b51e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5618
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/tcl3
13 changed files with 71 additions and 67 deletions
|
@ -2454,17 +2454,17 @@ GC::Ref<ComputedProperties> StyleComputer::create_document_style() const
|
|||
return style;
|
||||
}
|
||||
|
||||
GC::Ref<ComputedProperties> StyleComputer::compute_style(DOM::Element& element, Optional<CSS::PseudoElement> pseudo_element) const
|
||||
GC::Ref<ComputedProperties> StyleComputer::compute_style(DOM::Element& element, Optional<CSS::PseudoElement> pseudo_element, Optional<bool&> did_change_custom_properties) const
|
||||
{
|
||||
return *compute_style_impl(element, move(pseudo_element), ComputeStyleMode::Normal);
|
||||
return *compute_style_impl(element, move(pseudo_element), ComputeStyleMode::Normal, did_change_custom_properties);
|
||||
}
|
||||
|
||||
GC::Ptr<ComputedProperties> StyleComputer::compute_pseudo_element_style_if_needed(DOM::Element& element, Optional<CSS::PseudoElement> pseudo_element) const
|
||||
GC::Ptr<ComputedProperties> StyleComputer::compute_pseudo_element_style_if_needed(DOM::Element& element, Optional<CSS::PseudoElement> pseudo_element, Optional<bool&> did_change_custom_properties) const
|
||||
{
|
||||
return compute_style_impl(element, move(pseudo_element), ComputeStyleMode::CreatePseudoElementStyleIfNeeded);
|
||||
return compute_style_impl(element, move(pseudo_element), ComputeStyleMode::CreatePseudoElementStyleIfNeeded, did_change_custom_properties);
|
||||
}
|
||||
|
||||
GC::Ptr<ComputedProperties> StyleComputer::compute_style_impl(DOM::Element& element, Optional<CSS::PseudoElement> pseudo_element, ComputeStyleMode mode) const
|
||||
GC::Ptr<ComputedProperties> StyleComputer::compute_style_impl(DOM::Element& element, Optional<CSS::PseudoElement> pseudo_element, ComputeStyleMode mode, Optional<bool&> did_change_custom_properties) const
|
||||
{
|
||||
build_rule_cache_if_needed();
|
||||
|
||||
|
@ -2488,6 +2488,9 @@ GC::Ptr<ComputedProperties> StyleComputer::compute_style_impl(DOM::Element& elem
|
|||
PseudoClassBitmap attempted_pseudo_class_matches;
|
||||
auto matching_rule_set = build_matching_rule_set(element, pseudo_element, attempted_pseudo_class_matches, did_match_any_pseudo_element_rules, mode);
|
||||
|
||||
DOM::AbstractElement abstract_element { element, pseudo_element };
|
||||
auto old_custom_properties = abstract_element.custom_properties();
|
||||
|
||||
// Resolve all the CSS custom properties ("variables") for this element:
|
||||
// FIXME: Also resolve !important custom properties, in a second cascade.
|
||||
if (!pseudo_element.has_value() || pseudo_element_supports_property(*pseudo_element, PropertyID::Custom)) {
|
||||
|
@ -2533,6 +2536,11 @@ GC::Ptr<ComputedProperties> StyleComputer::compute_style_impl(DOM::Element& elem
|
|||
|
||||
auto computed_properties = compute_properties(element, pseudo_element, cascaded_properties);
|
||||
computed_properties->set_attempted_pseudo_class_matches(attempted_pseudo_class_matches);
|
||||
|
||||
if (did_change_custom_properties.has_value() && abstract_element.custom_properties() != old_custom_properties) {
|
||||
*did_change_custom_properties = true;
|
||||
}
|
||||
|
||||
return computed_properties;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue