Skip to content

Truly independent web browser

LibWeb: Compare only animated longhands of shared style groups

Andreas Kling57784339641d
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index 34c9083fb3b..6e1fd14c7c8 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -771,6 +771,23 @@ fn effective_value<'a>(
longhands.value(property)
}
+/// The indices of the longhands whose bits are set in `words`, one bit per longhand from the first.
+fn longhand_indices(words: [u64; crate::css::property_metadata::LONGHAND_WORD_COUNT]) -> impl Iterator<Item = usize> {
+ words
+ .into_iter()
+ .enumerate()
+ .flat_map(|(word_index, mut word)| {
+ std::iter::from_fn(move || {
+ let bit = word.trailing_zeros() as usize;
+ (word != 0).then(|| {
+ word &= word - 1;
+ word_index * 64 + bit
+ })
+ })
+ })
+ .take_while(|&index| index < NUMBER_OF_LONGHAND_PROPERTIES)
+}
+
fn same_value(first: Option<&StyleValueData>, second: Option<&StyleValueData>) -> bool {
match (first, second) {
(Some(first), Some(second)) => std::ptr::eq(first, second) || first == second,
@@ -1258,27 +1275,39 @@ fn record_move_damage(
let new_direction = new_values.direction();
// A longhand whose value both records hold in a group they share computes the same in
// both, which only an animated value or a writing mode mapping it elsewhere would change.
- let shared = old_table.shared_with(new_table).filter(|_| {
- old_record.animated_overlay.is_none()
- && new_record.animated_overlay.is_none()
- && old_writing_mode == new_writing_mode
- && old_direction == new_direction
- });
+ let shared = old_table
+ .shared_with(new_table)
+ .filter(|_| old_writing_mode == new_writing_mode && old_direction == new_direction);
+ let old_overlay = old_record.animated_overlay;
+ let new_overlay = new_record.animated_overlay;
+ // OPTIMIZATION: An animated value only changes the longhand its overlay entry names, so the shared groups
+ // still compute the same in both records apart from the longhands either overlay holds.
+ let mut animated = [0u64; crate::css::property_metadata::LONGHAND_WORD_COUNT];
+ for entry in old_overlay
+ .into_iter()
+ .chain(new_overlay)
+ .flat_map(|overlay| overlay.entries())
+ {
+ if let Some(index) = entry.property.checked_sub(FIRST_LONGHAND_PROPERTY_ID)
+ && usize::from(index) < NUMBER_OF_LONGHAND_PROPERTIES
+ {
+ animated[usize::from(index) / 64] |= 1 << (index % 64);
+ }
+ }
+ let is_animated = |property: u16| {
+ property
+ .checked_sub(FIRST_LONGHAND_PROPERTY_ID)
+ .is_some_and(|index| animated[usize::from(index) / 64] & (1 << (index % 64)) != 0)
+ };
let mut effective_changed = [false; NUMBER_OF_LONGHAND_PROPERTIES];
- let to_compare = shared.map_or(
+ let mut to_compare = shared.map_or(
[u64::MAX; crate::css::property_metadata::LONGHAND_WORD_COUNT],
super::computed::SharedLonghands::longhands_to_compare,
);
- let indices = to_compare.into_iter().enumerate().flat_map(|(word_index, mut word)| {
- std::iter::from_fn(move || {
- let bit = word.trailing_zeros() as usize;
- (word != 0).then(|| {
- word &= word - 1;
- word_index * 64 + bit
- })
- })
- });
- for index in indices.take_while(|&index| index < NUMBER_OF_LONGHAND_PROPERTIES) {
+ for (word, animated_word) in to_compare.iter_mut().zip(animated) {
+ *word |= animated_word;
+ }
+ for index in longhand_indices(to_compare) {
let changed = &mut effective_changed[index];
let property = FIRST_LONGHAND_PROPERTY_ID + index as u16;
let old_physical = if property_metadata::longhand_is_logical_alias(property) {
@@ -1291,7 +1320,11 @@ fn record_move_damage(
} else {
property
};
- if shared.is_some_and(|shared| shared.holds(new_physical)) {
+ if shared.is_some_and(|shared| shared.holds(new_physical))
+ && !is_animated(property)
+ && !is_animated(old_physical)
+ && !is_animated(new_physical)
+ {
continue;
}
let old_value = effective_value(&old_record, old_table, old_physical);
@@ -1325,19 +1358,12 @@ fn record_move_damage(
result.merge(invalidation);
}
result.merge(baked_filter_color_damage(old_values, new_values));
- let old_overlay = old_record.animated_overlay;
- let new_overlay = new_record.animated_overlay;
if old_overlay.is_some() || new_overlay.is_some() {
- for (index, effective_changed) in effective_changed.into_iter().enumerate() {
- if effective_changed {
+ for index in longhand_indices(animated) {
+ if effective_changed[index] {
continue;
}
let property = FIRST_LONGHAND_PROPERTY_ID + index as u16;
- if old_overlay.and_then(|overlay| overlay.get(property)).is_none()
- && new_overlay.and_then(|overlay| overlay.get(property)).is_none()
- {
- continue;
- }
let old_physical =
crate::css::style_compute::map_logical_alias_to_physical(property, old_writing_mode, old_direction);
let new_physical =