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

Unified Diff: chrome/browser/resources/profiler.js

Issue 8585023: Avoid too many consecutive redraws on about:profiler while loading. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/profiler.js
===================================================================
--- chrome/browser/resources/profiler.js (revision 110453)
+++ chrome/browser/resources/profiler.js (working copy)
@@ -531,6 +531,16 @@
KEY_LINE_NUMBER,
];
+ /**
+ * The time (in milliseconds) to wait after receiving new data before
+ * re-drawing it to the screen. The reason we wait a bit is to avoid
+ * repainting repeatedly during the loading phase (which can slow things
+ * down). Note that this only slows down the addition of new data. It does
+ * not impact the latency of user-initiated operations like sorting or
+ * merging.
+ */
+ var PROCESS_DATA_DELAY_MS = 500;
+
// --------------------------------------------------------------------------
// General utility functions
// --------------------------------------------------------------------------
@@ -714,6 +724,13 @@
return path.substr(lastSlash + 1);
}
+ /**
+ * Returns the current time in milliseconds since unix epoch.
+ */
+ function getTimeMillis() {
+ return (new Date()).getTime();
+ }
+
// --------------------------------------------------------------------------
// Functions that augment, bucket, and compute aggregates for the input data.
// --------------------------------------------------------------------------
@@ -1168,10 +1185,39 @@
this.flatData_.push(newRow);
}
- // Recompute the merged data based on flatData_.
- this.updateMergedData_();
+ // We may end up calling addData() repeatedly (once for each process).
+ // To avoid this from slowing us down we do bulk updates on a timer.
+ this.updateMergedDataSoon_();
},
+ updateMergedDataSoon_: function() {
+ if (this.updateMergedDataPending_) {
+ // If a delayed task has already been posted to re-merge the data,
+ // then we don't need to do anything extra.
+ return;
+ }
+
+ // Otherwise schedule updateMergeData_() to be called later. We want it to
+ // be called no more than once every PROCESS_DATA_DELAY_MS milliseconds.
+
+ if (this.lastUpdateMergedDataTime_ == undefined)
+ this.lastUpdateMergedDataTime_ = 0;
+
+ var timeSinceLastMerge = getTimeMillis() - this.lastUpdateMergedDataTime_;
+ var timeToWait = Math.max(0, PROCESS_DATA_DELAY_MS - timeSinceLastMerge);
+
+ var functionToRun = function() {
+ // Do the actual update.
+ this.updateMergedData_();
+ // Keep track of when we last ran.
+ this.lastUpdateMergedDataTime_ = getTimeMillis();
+ this.updateMergedDataPending_ = false;
+ }.bind(this);
jar (doing other things) 2011/11/17 07:02:42 curious qusetion: Do you need the .bind(this)? Wo
eroman 2011/11/17 07:06:55 |this| is a very weird beast in javascript. Wherea
+
+ this.updateMergedDataPending_ = true;
+ window.setTimeout(functionToRun, timeToWait);
+ },
+
updateMergedData_: function() {
// Recompute mergedData_.
this.mergedData_ = mergeRows(this.flatData_,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698