Truly independent web browser
LibWeb: Keep no spare room in a sheet's shared rule lists
Andreas Kling3c838504e6e5
diff --git a/Libraries/LibWeb/Rust/src/css/style/order.rs b/Libraries/LibWeb/Rust/src/css/style/order.rsindex c62afd007cc..36f6fa3a76d 100644--- a/Libraries/LibWeb/Rust/src/css/style/order.rs+++ b/Libraries/LibWeb/Rust/src/css/style/order.rs@@ -37,6 +37,13 @@ impl OrderMaintenance {vec_bytes(&self.labels) + vec_bytes(&self.free_entries) + vec_bytes(&self.order)}+ /// Give up the room the order holds beyond its entries.+ pub(super) fn shrink_to_fit(&mut self) {+ self.labels.shrink_to_fit();+ self.free_entries.shrink_to_fit();+ self.order.shrink_to_fit();+ }+#[must_use]pub fn new() -> Self {Self::default()diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rsindex 2feabad3b15..1df958e7953 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rs@@ -1605,18 +1605,30 @@ impl ProcessRuleIndexes {rules: &mut Arc<Vec<RuleID>>,rule_order: &mut Arc<crate::css::style::order::OrderMaintenance>,) {- fn share<T: PartialEq + Hash>(pool: &std::sync::Mutex<WeakPool<T>>, value: &mut Arc<T>) {+ // NB: What a document finds here is what another document built, so it holds no room for how this one grew.+ fn share<T: Clone + PartialEq + Hash>(+ pool: &std::sync::Mutex<WeakPool<T>>,+ value: &mut Arc<T>,+ shrink: impl FnOnce(&mut T),+ ) {let mut hasher = super::super::fast_hash::fast_hasher();value.hash(&mut hasher);let hash = std::hash::Hasher::finish(&hasher);let mut pool = pool.lock().unwrap_or_else(std::sync::PoisonError::into_inner);match pool.find(hash, |candidate| candidate == &**value) {Some(found) => *value = found,- None => pool.insert(hash, value),+ None => {+ shrink(Arc::make_mut(value));+ pool.insert(hash, value);+ }}}- share(&self.sheet_rules, rules);- share(&self.sheet_rule_orders, rule_order);+ share(&self.sheet_rules, rules, |rules| rules.shrink_to_fit());+ share(+ &self.sheet_rule_orders,+ rule_order,+ crate::css::style::order::OrderMaintenance::shrink_to_fit,+ );}/// The segment of `selectors`, built where no document of the process binds one, and whetherdiff --git a/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-at-rule-by-owner.txt b/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-at-rule-by-owner.txtindex 232ba1f8c8d..eab02a80e64 100644--- a/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-at-rule-by-owner.txt+++ b/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-at-rule-by-owner.txt@@ -6,28 +6,28 @@sharedDeclarations: within 40animationEffects: within 0@media that fails:- ruleStore: within 68+ ruleStore: within 69ruleIndex: within 0sheetSegments: within 0invalidation: within 0sharedDeclarations: within 40animationEffects: within 0@layer:- ruleStore: within 84+ ruleStore: within 87ruleIndex: within 60sheetSegments: within 240invalidation: within 0sharedDeclarations: within 40animationEffects: within 0@container:- ruleStore: within 60+ ruleStore: within 63ruleIndex: within 196sheetSegments: within 240invalidation: within 0sharedDeclarations: within 40animationEffects: within 0@keyframes:- ruleStore: within 116+ ruleStore: within 120ruleIndex: within 0sheetSegments: within 0invalidation: within 0diff --git a/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-rule-by-owner.txt b/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-rule-by-owner.txtindex 78095dfbea8..106735bfc00 100644--- a/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-rule-by-owner.txt+++ b/Tests/LibWeb/Text/expected/css/style-memory/bytes-per-rule-by-owner.txt@@ -22,7 +22,7 @@ descendant:invalidation: within 8sharedDeclarations: within 40styleValues: within 0- total: within 460+ total: within 462selector list:ruleStore: within 72ruleIndex: within 24@@ -31,4 +31,4 @@ selector list:invalidation: within 8sharedDeclarations: within 40styleValues: within 8- total: within 224+ total: within 225diff --git a/Tests/LibWeb/Text/input/css/style-memory/bytes-per-at-rule-by-owner.html b/Tests/LibWeb/Text/input/css/style-memory/bytes-per-at-rule-by-owner.htmlindex 8f87626e4b1..7dec28fa5e9 100644--- a/Tests/LibWeb/Text/input/css/style-memory/bytes-per-at-rule-by-owner.html+++ b/Tests/LibWeb/Text/input/css/style-memory/bytes-per-at-rule-by-owner.html@@ -42,10 +42,10 @@const budgets = {mediaHolds: { ruleStore: 76, ruleIndex: 56, sheetSegments: 240, sharedDeclarations: 40 },// NB: A rule under a condition that fails takes no place in the index until the condition holds.- mediaFails: { ruleStore: 68, sharedDeclarations: 40 },- layer: { ruleStore: 84, ruleIndex: 60, sheetSegments: 240, sharedDeclarations: 40 },- container: { ruleStore: 60, ruleIndex: 196, sheetSegments: 240, sharedDeclarations: 40 },- keyframes: { ruleStore: 116 },+ mediaFails: { ruleStore: 69, sharedDeclarations: 40 },+ layer: { ruleStore: 87, ruleIndex: 60, sheetSegments: 240, sharedDeclarations: 40 },+ container: { ruleStore: 63, ruleIndex: 196, sheetSegments: 240, sharedDeclarations: 40 },+ keyframes: { ruleStore: 120 },};test(() => {diff --git a/Tests/LibWeb/Text/input/css/style-memory/bytes-per-rule-by-owner.html b/Tests/LibWeb/Text/input/css/style-memory/bytes-per-rule-by-owner.htmlindex 5092a001a94..f779c9e37d6 100644--- a/Tests/LibWeb/Text/input/css/style-memory/bytes-per-rule-by-owner.html+++ b/Tests/LibWeb/Text/input/css/style-memory/bytes-per-rule-by-owner.html@@ -84,7 +84,7 @@invalidation: 8,sheetSegments: 344,sharedDeclarations: 40,- total: 460,+ total: 462,};const listBudgets = {styleValues: 8,@@ -93,7 +93,7 @@invalidation: 8,sheetSegments: 112,sharedDeclarations: 40,- total: 224,+ total: 225,};// Bytes of a document with no rules of its own each owner may hold.// NB: The user agent index owner counts the rules of every user agent sheet the process published so far, which