From 46acdbd10a6caa0ce6d480a76120cb4546c5b6da Mon Sep 17 00:00:00 2001 From: Callum Law Date: Thu, 20 Nov 2025 16:22:44 +1300 Subject: [PATCH] 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% --- Libraries/LibWeb/CSS/StyleComputer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 7d2b39b12ab..4222136fdd4 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -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 });