mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Reuse inherited custom properties if they didn't change after resolution
This should be cheap and gives us a lot of memory savings for the page on the bug, by deduplicating the inherited properties between parent and children. WebKit implements a similar optimization. Differential Revision: https://phabricator.services.mozilla.com/D140826
This commit is contained in:
parent
da81d71ffa
commit
8016c434b0
1 changed files with 26 additions and 0 deletions
|
@ -723,6 +723,22 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn inherited_properties_match(&self, map: &CustomPropertiesMap) -> bool {
|
||||||
|
let inherited = match self.inherited {
|
||||||
|
Some(inherited) => inherited,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
if inherited.len() != map.len() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for name in self.seen.iter() {
|
||||||
|
if inherited.get(*name) != map.get(*name) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the final map of applicable custom properties.
|
/// Returns the final map of applicable custom properties.
|
||||||
///
|
///
|
||||||
/// If there was any specified property, we've created a new map and now we
|
/// If there was any specified property, we've created a new map and now we
|
||||||
|
@ -734,9 +750,19 @@ impl<'a> CustomPropertiesBuilder<'a> {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
None => return self.inherited.cloned(),
|
None => return self.inherited.cloned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.may_have_cycles {
|
if self.may_have_cycles {
|
||||||
substitute_all(&mut map, &self.seen, self.device);
|
substitute_all(&mut map, &self.seen, self.device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some pages apply a lot of redundant custom properties, see e.g.
|
||||||
|
// bug 1758974 comment 5. Try to detect the case where the values
|
||||||
|
// haven't really changed, and save some memory by reusing the inherited
|
||||||
|
// map in that case.
|
||||||
|
if self.inherited_properties_match(&map) {
|
||||||
|
return self.inherited.cloned();
|
||||||
|
}
|
||||||
|
|
||||||
map.shrink_to_fit();
|
map.shrink_to_fit();
|
||||||
Some(Arc::new(map))
|
Some(Arc::new(map))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue