Title: [244308] trunk/Source/WebInspectorUI
Revision
244308
Author
[email protected]
Date
2019-04-15 16:48:57 -0700 (Mon, 15 Apr 2019)

Log Message

Web Inspector: Heap: don't use recursion when calculating root paths
https://bugs.webkit.org/show_bug.cgi?id=196890
<rdar://problem/49870751>

Reviewed by Joseph Pecoraro.

* UserInterface/Workers/HeapSnapshot/HeapSnapshot.js:
(HeapSnapshot.prototype.shortestGCRootPath):
(HeapSnapshot.prototype._determineGCRootPaths):
(HeapSnapshot.prototype._gcRootPathes.visitNode): Deleted.
(HeapSnapshot.prototype._gcRootPathes): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (244307 => 244308)


--- trunk/Source/WebInspectorUI/ChangeLog	2019-04-15 23:48:55 UTC (rev 244307)
+++ trunk/Source/WebInspectorUI/ChangeLog	2019-04-15 23:48:57 UTC (rev 244308)
@@ -1,3 +1,17 @@
+2019-04-15  Devin Rousso  <[email protected]>
+
+        Web Inspector: Heap: don't use recursion when calculating root paths
+        https://bugs.webkit.org/show_bug.cgi?id=196890
+        <rdar://problem/49870751>
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Workers/HeapSnapshot/HeapSnapshot.js:
+        (HeapSnapshot.prototype.shortestGCRootPath):
+        (HeapSnapshot.prototype._determineGCRootPaths):
+        (HeapSnapshot.prototype._gcRootPathes.visitNode): Deleted.
+        (HeapSnapshot.prototype._gcRootPathes): Deleted.
+
 2019-04-15  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: SameSite parsing should be stricter

Modified: trunk/Source/WebInspectorUI/UserInterface/Workers/HeapSnapshot/HeapSnapshot.js (244307 => 244308)


--- trunk/Source/WebInspectorUI/UserInterface/Workers/HeapSnapshot/HeapSnapshot.js	2019-04-15 23:48:55 UTC (rev 244307)
+++ trunk/Source/WebInspectorUI/UserInterface/Workers/HeapSnapshot/HeapSnapshot.js	2019-04-15 23:48:57 UTC (rev 244308)
@@ -278,7 +278,7 @@
         // Internal nodes are avoided, so if the path is empty this
         // node is either a gcRoot or only reachable via Internal nodes.
 
-        let paths = this._gcRootPathes(nodeIdentifier);
+        let paths = this._determineGCRootPaths(nodeIdentifier);
         if (!paths.length)
             return [];
 
@@ -734,7 +734,7 @@
             || className === "GlobalObject";
     }
 
-    _gcRootPathes(nodeIdentifier)
+    _determineGCRootPaths(nodeIdentifier)
     {
         let targetNodeOrdinal = this._nodeIdentifierToOrdinal.get(nodeIdentifier);
 
@@ -743,22 +743,34 @@
 
         // FIXME: Array push/pop can affect performance here, but in practice it hasn't been an issue.
 
-        let paths = [];
-        let currentPath = [];
+        let gcRootPaths = [];
         let visited = new Uint8Array(this._nodeCount);
 
-        function visitNode(nodeOrdinal)
-        {
+        let pathsBeingProcessed = [
+            {
+                currentPath: [],
+                nodeOrdinal: targetNodeOrdinal,
+            },
+        ];
+        for (let i = 0; i < pathsBeingProcessed.length; ++i) {
+            let {currentPath, nodeOrdinal} = pathsBeingProcessed[i];
+
+            // Rather than use `Array.prototype.unshift`, which may be very expensive, keep track of
+            // the "current" position as `i` and "delete" the values already processed by clearing
+            // the value at that index.
+            pathsBeingProcessed[i] = undefined;
+
             if (this._nodeOrdinalIsGCRoot[nodeOrdinal]) {
                 let fullPath = currentPath.slice();
                 let nodeIndex = nodeOrdinal * this._nodeFieldCount;
                 fullPath.push({node: nodeIndex});
-                paths.push(fullPath);
-                return;
+                gcRootPaths.push(fullPath);
+                continue;
             }
 
             if (visited[nodeOrdinal])
-                return;
+                continue;
+
             visited[nodeOrdinal] = 1;
 
             let nodeIndex = nodeOrdinal * this._nodeFieldCount;
@@ -775,18 +787,13 @@
                 if (fromNodeIsInternal)
                     continue;
 
-                let edgeIndex = this._incomingEdges[incomingEdgeIndex];
-                currentPath.push({edge: edgeIndex});
-                visitNode.call(this, fromNodeOrdinal);
-                currentPath.pop();
+                let newPath = currentPath.slice();
+                newPath.push({edge: this._incomingEdges[incomingEdgeIndex]});
+                pathsBeingProcessed.push({currentPath: newPath, nodeOrdinal: fromNodeOrdinal});
             }
-
-            currentPath.pop();
         }
 
-        visitNode.call(this, targetNodeOrdinal);
-
-        return paths;
+        return gcRootPaths;
     }
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to