Changeset 244308 in webkit


Ignore:
Timestamp:
Apr 15, 2019 4:48:57 PM (5 years ago)
Author:
Devin Rousso
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.

Location:
trunk/Source/WebInspectorUI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r244294 r244308  
     12019-04-15  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: Heap: don't use recursion when calculating root paths
     4        https://bugs.webkit.org/show_bug.cgi?id=196890
     5        <rdar://problem/49870751>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        * UserInterface/Workers/HeapSnapshot/HeapSnapshot.js:
     10        (HeapSnapshot.prototype.shortestGCRootPath):
     11        (HeapSnapshot.prototype._determineGCRootPaths):
     12        (HeapSnapshot.prototype._gcRootPathes.visitNode): Deleted.
     13        (HeapSnapshot.prototype._gcRootPathes): Deleted.
     14
    1152019-04-15  Joseph Pecoraro  <pecoraro@apple.com>
    216
  • trunk/Source/WebInspectorUI/UserInterface/Workers/HeapSnapshot/HeapSnapshot.js

    r241787 r244308  
    279279        // node is either a gcRoot or only reachable via Internal nodes.
    280280
    281         let paths = this._gcRootPathes(nodeIdentifier);
     281        let paths = this._determineGCRootPaths(nodeIdentifier);
    282282        if (!paths.length)
    283283            return [];
     
    735735    }
    736736
    737     _gcRootPathes(nodeIdentifier)
     737    _determineGCRootPaths(nodeIdentifier)
    738738    {
    739739        let targetNodeOrdinal = this._nodeIdentifierToOrdinal.get(nodeIdentifier);
     
    744744        // FIXME: Array push/pop can affect performance here, but in practice it hasn't been an issue.
    745745
    746         let paths = [];
    747         let currentPath = [];
     746        let gcRootPaths = [];
    748747        let visited = new Uint8Array(this._nodeCount);
    749748
    750         function visitNode(nodeOrdinal)
    751         {
     749        let pathsBeingProcessed = [
     750            {
     751                currentPath: [],
     752                nodeOrdinal: targetNodeOrdinal,
     753            },
     754        ];
     755        for (let i = 0; i < pathsBeingProcessed.length; ++i) {
     756            let {currentPath, nodeOrdinal} = pathsBeingProcessed[i];
     757
     758            // Rather than use `Array.prototype.unshift`, which may be very expensive, keep track of
     759            // the "current" position as `i` and "delete" the values already processed by clearing
     760            // the value at that index.
     761            pathsBeingProcessed[i] = undefined;
     762
    752763            if (this._nodeOrdinalIsGCRoot[nodeOrdinal]) {
    753764                let fullPath = currentPath.slice();
    754765                let nodeIndex = nodeOrdinal * this._nodeFieldCount;
    755766                fullPath.push({node: nodeIndex});
    756                 paths.push(fullPath);
    757                 return;
     767                gcRootPaths.push(fullPath);
     768                continue;
    758769            }
    759770
    760771            if (visited[nodeOrdinal])
    761                 return;
     772                continue;
     773
    762774            visited[nodeOrdinal] = 1;
    763775
     
    776788                    continue;
    777789
    778                 let edgeIndex = this._incomingEdges[incomingEdgeIndex];
    779                 currentPath.push({edge: edgeIndex});
    780                 visitNode.call(this, fromNodeOrdinal);
    781                 currentPath.pop();
     790                let newPath = currentPath.slice();
     791                newPath.push({edge: this._incomingEdges[incomingEdgeIndex]});
     792                pathsBeingProcessed.push({currentPath: newPath, nodeOrdinal: fromNodeOrdinal});
    782793            }
    783 
    784             currentPath.pop();
    785         }
    786 
    787         visitNode.call(this, targetNodeOrdinal);
    788 
    789         return paths;
     794        }
     795
     796        return gcRootPaths;
    790797    }
    791798};
Note: See TracChangeset for help on using the changeset viewer.