LibWeb: Avoid registering unnecessary transitions

Reduces time spent in `StyleComputer::compute_properties` when loading
https://en.wikipedia.org/wiki/2023_in_American_television from ~37% to
~13%
This commit is contained in:
Callum Law 2025-11-20 16:22:44 +13:00 committed by Jelle Raaijmakers
parent 67a3d0f1aa
commit 46acdbd10a
Notes: github-actions[bot] 2025-11-23 08:44:24 +00:00

View file

@ -1231,6 +1231,25 @@ static void compute_transitioned_properties(ComputedProperties const& style, DOM
element.clear_registered_transitions(pseudo_element);
auto const& delay = style.property(PropertyID::TransitionDelay);
auto const& duration = style.property(PropertyID::TransitionDuration);
// FIXME: Change this to support the associated StyleValueList values when we update
// parse_simple_comma_separated_value_list to always return a StyleValueList.
// OPTIMIZATION: Registered transitions with a "combined duration" of less than or equal to 0s are equivalent to not
// having a transition registered at all, except in the case that we already have an associated
// transition for that property, so we can skip registering them. This implementation intentionally
// ignores some of those cases (e.g. transitions being registered but for other properties, multiple
// transitions, negative delays, etc) since it covers the common (initial property values) case and
// the other cases are rare enough that the cost of identifying them would likely more than offset any
// gains.
if (
element.property_ids_with_existing_transitions(pseudo_element).is_empty()
&& delay.is_time() && delay.as_time().time().to_seconds() == 0
&& duration.is_time() && duration.as_time().time().to_seconds() == 0) {
return;
}
auto coordinated_transition_list = style.assemble_coordinated_value_list(
PropertyID::TransitionProperty,
{ PropertyID::TransitionProperty, PropertyID::TransitionDuration, PropertyID::TransitionTimingFunction, PropertyID::TransitionDelay, PropertyID::TransitionBehavior });