Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Unified Diff: Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js

Issue 967853002: DevTools: n^2 -> n while loading heap snapshots and timeline files. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed the load test. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/common/TextUtils.js ('k') | Source/devtools/front_end/timeline/TimelineModel.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
diff --git a/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js b/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
index 8285fa8ccf5f2cd96e53bed43dbf46c16d8e2616..b7e04701a4d4782cb07ae269e4f9efae2e9add94 100644
--- a/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
+++ b/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
@@ -122,7 +122,8 @@ WebInspector.HeapSnapshotLoader.prototype = {
*/
write: function(chunk)
{
- this._json += chunk;
+ if (this._json !== null)
+ this._json += chunk;
while (true) {
switch (this._state) {
case "find-snapshot-info": {
@@ -130,18 +131,19 @@ WebInspector.HeapSnapshotLoader.prototype = {
var snapshotTokenIndex = this._json.indexOf(snapshotToken);
if (snapshotTokenIndex === -1)
throw new Error("Snapshot token not found");
- this._json = this._json.slice(snapshotTokenIndex + snapshotToken.length + 1);
+
+ var json = this._json.slice(snapshotTokenIndex + snapshotToken.length + 1);
this._state = "parse-snapshot-info";
this._progress.updateStatus("Loading snapshot info\u2026");
- break;
+ this._json = null; // tokenizer takes over input.
+ this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this._writeBalancedJSON.bind(this));
+ // Fall through with adjusted payload.
+ chunk = json;
}
case "parse-snapshot-info": {
- var closingBracketIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(this._json);
- if (closingBracketIndex === -1)
- return;
- this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(this._json.slice(0, closingBracketIndex)));
- this._json = this._json.slice(closingBracketIndex);
- this._state = "find-nodes";
+ this._jsonTokenizer.write(chunk);
+ if (this._jsonTokenizer)
+ return; // no remainder to process.
break;
}
case "find-nodes": {
@@ -265,5 +267,16 @@ WebInspector.HeapSnapshotLoader.prototype = {
return;
}
}
+ },
+
+ /**
+ * @param {string} data
+ */
+ _writeBalancedJSON: function(data)
+ {
+ this._json = this._jsonTokenizer.remainder(); // tokenizer releases input.
+ this._jsonTokenizer = null;
+ this._state = "find-nodes";
+ this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(data));
}
-};
+}
« no previous file with comments | « Source/devtools/front_end/common/TextUtils.js ('k') | Source/devtools/front_end/timeline/TimelineModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698