Truly independent web browser
LibWeb: Decide transitions without walking for inherited animated values
Andreas Kling0b778b3b7b25
diff --git a/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rs b/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rsindex 05408b146e7..3fdacd72859 100644--- a/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rs+++ b/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rs@@ -109,6 +109,23 @@ impl RetainedState {self.transition_baselines.get(node, pseudo_kind)}+ /// Whether an ancestor `node` inherits from holds animated values, which is the only way it inherits one.+ pub(crate) fn ancestors_hold_animated_values(&self, node: StyleNodeID) -> bool {+ let mut ancestor = self.tree.inheritance_parent(node);+ while let Some(current) = ancestor {+ if let Some(record) = self.computed_group_sets.assigned_style_record(current)+ && self+ .computed_group_sets+ .style_record_view(record.raw())+ .is_some_and(|view| view.animated_overlay.is_some())+ {+ return true;+ }+ ancestor = self.tree.inheritance_parent(current);+ }+ false+ }+/// Where an inherited value of `property` in `table`, a record of `node`'s, comes from when an/// ancestor animates it. A record the engine derives holds the animated value its parent passed/// on in its table, where a transition decides against the value beneath the animations: andiff --git a/Libraries/LibWeb/Rust/src/css/transition.rs b/Libraries/LibWeb/Rust/src/css/transition.rsindex a1df049c22a..0260372d62f 100644--- a/Libraries/LibWeb/Rust/src/css/transition.rs+++ b/Libraries/LibWeb/Rust/src/css/transition.rs@@ -530,6 +530,12 @@ impl TransitionDecision {};context.set_transform_reference_box(reference_box);let existing_for = |property_id| existing.iter().find(|existing| existing.property_id == property_id);+ // OPTIMIZATION: An element inherits an animated value only from an ancestor holding one, so one walk up the+ // tree, taken for the first inherited property, answers for every property where none does.+ let ancestors_hold_animated_values = std::cell::OnceCell::new();+ let inherits_animated_values = |element: crate::css::style::tree::StyleNodeID| {+ *ancestors_hold_animated_values.get_or_init(|| engine.ancestors_hold_animated_values(element))+ };let matched = entries.iter().map(|entry| (entry.property_id, Some(entry), existing_for(entry.property_id)));@@ -542,10 +548,12 @@ impl TransitionDecision {.map(|(property_id, entry, existing)| {let mut property = TransitionProperty::new(property_id, entry, existing);let inherited_animation = element- .filter(|_| {- after_overlay- .and_then(|overlay| overlay.get(property_id))- .is_none_or(|entry| !entry.inherited)+ .filter(|&element| {+ after_table.is_inherited(property_id)+ && after_overlay+ .and_then(|overlay| overlay.get(property_id))+ .is_none_or(|entry| !entry.inherited)+ && inherits_animated_values(element)}).and_then(|element| engine.inherited_animated_value(element, after_table, property_id));let values_originate_from_current_color = prepare_transition_values(@@ -567,6 +575,13 @@ impl TransitionDecision {}decide_transition(&context, &property, values_originate_from_current_color)})+ // A property the step leaves alone that holds no transition is one every consumer of the step leaves alone+ // where the step names no action for it.+ .filter(|action| {+ action.kind != FfiTransitionActionKind::None+ || !action.start_value.is_null()+ || existing_for(action.property_id).is_some()+ }).collect()}}