Bug 1542762 - Use an explicit stack to measure rule tree memory usage. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 09 Apr 2019 00:11:03 +0000
changeset 468475 05cee7dc3b5ca0745802c80a27f13c2dc4638ebe
parent 468474 a7c00b62990f02b45c956cf371b1cb593ff5cfb9
child 468476 913749a193b6c4693e9f8cd4ede25506bb2d612b
push id112724
push usernerli@mozilla.com
push dateTue, 09 Apr 2019 10:03:26 +0000
treeherdermozilla-inbound@f6f2c5590ef2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1542762
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542762 - Use an explicit stack to measure rule tree memory usage. r=heycam A patch of mine that makes us measure the rule tree more often triggers this. Differential Revision: https://phabricator.services.mozilla.com/D26595
servo/components/style/rule_tree/mod.rs
--- a/servo/components/style/rule_tree/mod.rs
+++ b/servo/components/style/rule_tree/mod.rs
@@ -70,18 +70,25 @@ impl Drop for RuleTree {
             .next_free
             .store(ptr::null_mut(), Ordering::Relaxed);
     }
 }
 
 #[cfg(feature = "gecko")]
 impl MallocSizeOf for RuleTree {
     fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
-        let mut n = unsafe { ops.malloc_size_of(self.root.ptr()) };
-        n += self.root.get().size_of(ops);
+        let mut n = 0;
+        let mut stack = SmallVec::<[_; 32]>::new();
+        stack.push(self.root.downgrade());
+
+        while let Some(node) = stack.pop() {
+            n += unsafe { ops.malloc_size_of(node.ptr()) };
+            stack.extend(unsafe { (*node.ptr()).iter_children() });
+        }
+
         n
     }
 }
 
 /// A style source for the rule node. It can either be a CSS style rule or a
 /// declaration block.
 ///
 /// Note that, even though the declaration block from inside the style rule
@@ -942,28 +949,16 @@ impl RuleNode {
                 None
             } else {
                 Some(WeakRuleNode::from_ptr(first_child))
             },
         }
     }
 }
 
-#[cfg(feature = "gecko")]
-impl MallocSizeOf for RuleNode {
-    fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
-        let mut n = 0;
-        for child in self.iter_children() {
-            n += unsafe { ops.malloc_size_of(child.ptr()) };
-            n += unsafe { (*child.ptr()).size_of(ops) };
-        }
-        n
-    }
-}
-
 #[derive(Clone)]
 struct WeakRuleNode {
     p: ptr::NonNull<RuleNode>,
 }
 
 /// A strong reference to a rule node.
 #[derive(Debug, Eq, Hash, PartialEq)]
 pub struct StrongRuleNode {