Skip to content
Permalink
Browse files
Web Inspector: Speed up the build retainers phase.
https://bugs.webkit.org/show_bug.cgi?id=81763

Replacing the edge iterator with a raw loop makes it
faster by more than 10 times.

Patch by Alexei Filippov <alexeif@chromium.org> on 2012-03-22
Reviewed by Yury Semikhatsky.

* inspector/front-end/HeapSnapshot.js:
(WebInspector.HeapSnapshot.prototype._buildRetainers):

Canonical link: https://commits.webkit.org/99184@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@111688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Alexei Filippov authored and yury-s committed Mar 22, 2012
1 parent 09ecadc commit a660156ebeb404dbcc5ccbe66bd2df7ca5c6910a
Showing 2 changed files with 63 additions and 16 deletions.
@@ -1,3 +1,16 @@
2012-03-22 Alexei Filippov <alexeif@chromium.org>

Web Inspector: Speed up the build retainers phase.
https://bugs.webkit.org/show_bug.cgi?id=81763

Replacing the edge iterator with a raw loop makes it
faster by more than 10 times.

Reviewed by Yury Semikhatsky.

* inspector/front-end/HeapSnapshot.js:
(WebInspector.HeapSnapshot.prototype._buildRetainers):

2012-03-22 No'am Rosenthal <noam.rosenthal@nokia.com>

[Qt][WK2] The background appears to have one extra pixel from the contents
@@ -959,22 +959,56 @@ WebInspector.HeapSnapshot.prototype = {

_buildRetainers: function()
{
this._buildReverseIndex(
"_retainerIndex",
"_retainers",
(function (node, callback)
{
for (var edgesIter = node.edges; edgesIter.hasNext(); edgesIter.next())
callback(this._nodePosition[edgesIter.edge.nodeIndex]);
}).bind(this),
(function (node, indexCallback, dataCallback)
{
for (var edgesIter = node.edges; edgesIter.hasNext(); edgesIter.next()) {
var edge = edgesIter.edge;
var retIndex = this._getRetainerIndex(edge.nodeIndex);
dataCallback(indexCallback(retIndex), node.nodeIndex + this._firstEdgeOffset + edge.edgeIndex);
}
}).bind(this));
var nodeIndexes = this.nodeIndexes;
var nodePositions = this._nodePosition;
var nodeCount = this.nodeCount;
var nodes = this._nodes;

// Builds up two arrays:
// - "backRefsArray" is a continuous array, where each node owns an
// interval (can be empty) with corresponding back references.
// - "indexArray" is an array of indexes in the "backRefsArray"
// with the same positions as in the _nodeIndex.
var indexArray = this._retainerIndex = new Int32Array(nodeCount);
var edgesCountOffset = this._edgesCountOffset;
var firstEdgeOffset = this._firstEdgeOffset;
var edgeFieldsCount = this._edgeFieldsCount;
var edgeToNodeOffset = this._edgeToNodeOffset;
var backRefsCount = 0;
// Count the number of retainers for each node
for (var i = 0; i < nodeCount; ++i) {
var nodeIndex = nodeIndexes[i];
var edgesOffset = nodeIndex + firstEdgeOffset + edgeToNodeOffset;
var edgesCount = nodes[nodeIndex + edgesCountOffset];
backRefsCount += edgesCount;
for (var j = 0; j < edgesCount; ++j) {
var targetNodeIndex = nodes[j * edgeFieldsCount + edgesOffset];
++indexArray[nodePositions[targetNodeIndex]];
}
}
var backRefsArray = this._retainers = new Int32Array(backRefsCount);
// Put in the first slot of each backRefsArray slice the count of entries
// that will be filled.
var backRefsPosition = 0;
for (i = 0; i < nodeCount; ++i) {
backRefsCount = backRefsArray[backRefsPosition] = indexArray[i];
indexArray[i] = backRefsPosition;
backRefsPosition += backRefsCount;
}
var retainerIndex = this._retainerIndex;
// Fill up the retainers array with indexes of edges.
for (var i = 0; i < nodeCount; ++i) {
var nodeIndex = nodeIndexes[i];
var edgesOffset = nodeIndex + firstEdgeOffset;
var edgesCount = nodes[nodeIndex + edgesCountOffset];
for (var j = 0; j < edgesCount; ++j) {
var edgeIndex = j * edgeFieldsCount + edgesOffset;
var retNode = nodePositions[nodes[edgeIndex + edgeToNodeOffset]];
var retIndex = indexArray[retNode];
var backRefIndex = retIndex + (--backRefsArray[retIndex]);
backRefsArray[backRefIndex] = edgeIndex;
}
}
},

_calculateObjectToWindowDistance: function()

0 comments on commit a660156

Please sign in to comment.