Skip to content

Commit 46acdbd

Browse files
Calme1709gmta
authored andcommitted
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%
1 parent 67a3d0f commit 46acdbd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,25 @@ static void compute_transitioned_properties(ComputedProperties const& style, DOM
12311231

12321232
element.clear_registered_transitions(pseudo_element);
12331233

1234+
auto const& delay = style.property(PropertyID::TransitionDelay);
1235+
auto const& duration = style.property(PropertyID::TransitionDuration);
1236+
1237+
// FIXME: Change this to support the associated StyleValueList values when we update
1238+
// parse_simple_comma_separated_value_list to always return a StyleValueList.
1239+
// OPTIMIZATION: Registered transitions with a "combined duration" of less than or equal to 0s are equivalent to not
1240+
// having a transition registered at all, except in the case that we already have an associated
1241+
// transition for that property, so we can skip registering them. This implementation intentionally
1242+
// ignores some of those cases (e.g. transitions being registered but for other properties, multiple
1243+
// transitions, negative delays, etc) since it covers the common (initial property values) case and
1244+
// the other cases are rare enough that the cost of identifying them would likely more than offset any
1245+
// gains.
1246+
if (
1247+
element.property_ids_with_existing_transitions(pseudo_element).is_empty()
1248+
&& delay.is_time() && delay.as_time().time().to_seconds() == 0
1249+
&& duration.is_time() && duration.as_time().time().to_seconds() == 0) {
1250+
return;
1251+
}
1252+
12341253
auto coordinated_transition_list = style.assemble_coordinated_value_list(
12351254
PropertyID::TransitionProperty,
12361255
{ PropertyID::TransitionProperty, PropertyID::TransitionDuration, PropertyID::TransitionTimingFunction, PropertyID::TransitionDelay, PropertyID::TransitionBehavior });

0 commit comments

Comments
 (0)