Log Message
Perf dashboard can consume 50-70% of CPU on MacBook even if user is not interacting at all https://bugs.webkit.org/show_bug.cgi?id=159597
Reviewed by Chris Dumez. TimeSeriesChart and InteractiveTimeSeriesChart had been relying on continually polling on requestAnimationFrame to update itself in response to its canvas resizing. Even though there as an early exit in the case there was nothing to update, this is still causing a significant power drain when the user is not interacting at all. Let TimeSeriesChart use the regular top-down render path like other components with exceptions of listening to window's resize eventas well as when new JSONs are fetched from the server. The render() call to the latter case will be coerced into a single callback on requestAnimationFrame to avoid DOM-mutation-layout churn. * public/v3/components/base.js: (ComponentBase.isElementInViewport): Deleted. * public/v3/components/chart-pane-base.js: (ChartPaneBase.prototype.render): Enqueue charts to render. * public/v3/components/chart-styles.js: (ChartStyles.dashboardOptions): Removed updateOnRequestAnimationFrame which is no longer an available option. * public/v3/components/time-series-chart.js: (TimeSeriesChart): Replaced the code to register itself for rAF by the code to listen to resize events on window. (TimeSeriesChart._updateOnRAF): Deleted. (TimeSeriesChart._updateAllCharts): Added. (TimeSeriesChart.prototype._enqueueToRender): Added. (TimeSeriesChart._renderEnqueuedCharts): Added. (TimeSeriesChart.prototype.fetchMeasurementSets): Avoid calling fetchBetween when the range had been fetched. Without this change, we can incur a significant number of redundant calls to render() when adjusting the domain in charts page by the slider. When no new JSON is fetched, simply enqueue this chart to render on rAF. (TimeSeriesChart.prototype._didFetchMeasurementSet): Enqueue this chart to render on rAF. (TimeSeriesChart.prototype.render): Removed the check for isElementInViewport since we no longer get render() call when this chart moves into the viewport (as we no longer listen to every rAF or scroll event). * public/v3/models/measurement-set.js: (MeasurementSet.prototype.hasFetchedRange): Fixed various bugs revealed by the new use in fetchMeasurementSets. * public/v3/pages/chart-pane-status-view.js: (ChartPaneStatusView.prototype._updateRevisionListForNewCurrentRepository): Removed the dead code. It was probably copied from when this code was in InteractiveTimeSeries chart. There is no this._forceRender in this component. * public/v3/pages/dashboard-page.js: (DashboardPage.prototype.render): Enqueue charts to render. * public/v3/pages/heading.js: (SummaryPage.prototype.open): Removed the call to isElementInViewport. This wasn't really doing anything useful in this component. * unit-tests/measurement-set-tests.js: Added tests for hasFetchedRange. (.waitForMeasurementSet): Moved to be used in a newly added test case.
Modified Paths
- trunk/Websites/perf.webkit.org/ChangeLog
- trunk/Websites/perf.webkit.org/public/v3/components/base.js
- trunk/Websites/perf.webkit.org/public/v3/components/chart-pane-base.js
- trunk/Websites/perf.webkit.org/public/v3/components/chart-styles.js
- trunk/Websites/perf.webkit.org/public/v3/components/time-series-chart.js
- trunk/Websites/perf.webkit.org/public/v3/models/measurement-set.js
- trunk/Websites/perf.webkit.org/public/v3/pages/chart-pane-status-view.js
- trunk/Websites/perf.webkit.org/public/v3/pages/dashboard-page.js
- trunk/Websites/perf.webkit.org/public/v3/pages/heading.js
- trunk/Websites/perf.webkit.org/unit-tests/measurement-set-tests.js
Diff
Modified: trunk/Websites/perf.webkit.org/ChangeLog (203034 => 203035)
--- trunk/Websites/perf.webkit.org/ChangeLog 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/ChangeLog 2016-07-09 22:58:54 UTC (rev 203035)
@@ -1,5 +1,51 @@
2016-07-09 Ryosuke Niwa <[email protected]>
+ Perf dashboard can consume 50-70% of CPU on MacBook even if user is not interacting at all
+ https://bugs.webkit.org/show_bug.cgi?id=159597
+
+ Reviewed by Chris Dumez.
+
+ TimeSeriesChart and InteractiveTimeSeriesChart had been relying on continually polling on requestAnimationFrame
+ to update itself in response to its canvas resizing. Even though there as an early exit in the case there was
+ nothing to update, this is still causing a significant power drain when the user is not interacting at all.
+
+ Let TimeSeriesChart use the regular top-down render path like other components with exceptions of listening to
+ window's resize eventas well as when new JSONs are fetched from the server. The render() call to the latter case
+ will be coerced into a single callback on requestAnimationFrame to avoid DOM-mutation-layout churn.
+
+ * public/v3/components/base.js:
+ (ComponentBase.isElementInViewport): Deleted.
+ * public/v3/components/chart-pane-base.js:
+ (ChartPaneBase.prototype.render): Enqueue charts to render.
+ * public/v3/components/chart-styles.js:
+ (ChartStyles.dashboardOptions): Removed updateOnRequestAnimationFrame which is no longer an available option.
+ * public/v3/components/time-series-chart.js:
+ (TimeSeriesChart): Replaced the code to register itself for rAF by the code to listen to resize events on window.
+ (TimeSeriesChart._updateOnRAF): Deleted.
+ (TimeSeriesChart._updateAllCharts): Added.
+ (TimeSeriesChart.prototype._enqueueToRender): Added.
+ (TimeSeriesChart._renderEnqueuedCharts): Added.
+ (TimeSeriesChart.prototype.fetchMeasurementSets): Avoid calling fetchBetween when the range had been fetched.
+ Without this change, we can incur a significant number of redundant calls to render() when adjusting the domain
+ in charts page by the slider. When no new JSON is fetched, simply enqueue this chart to render on rAF.
+ (TimeSeriesChart.prototype._didFetchMeasurementSet): Enqueue this chart to render on rAF.
+ (TimeSeriesChart.prototype.render): Removed the check for isElementInViewport since we no longer get render() call
+ when this chart moves into the viewport (as we no longer listen to every rAF or scroll event).
+ * public/v3/models/measurement-set.js:
+ (MeasurementSet.prototype.hasFetchedRange): Fixed various bugs revealed by the new use in fetchMeasurementSets.
+ * public/v3/pages/chart-pane-status-view.js:
+ (ChartPaneStatusView.prototype._updateRevisionListForNewCurrentRepository): Removed the dead code. It was probably
+ copied from when this code was in InteractiveTimeSeries chart. There is no this._forceRender in this component.
+ * public/v3/pages/dashboard-page.js:
+ (DashboardPage.prototype.render): Enqueue charts to render.
+ * public/v3/pages/heading.js:
+ (SummaryPage.prototype.open): Removed the call to isElementInViewport. This wasn't really doing anything useful in
+ this component.
+ * unit-tests/measurement-set-tests.js: Added tests for hasFetchedRange.
+ (.waitForMeasurementSet): Moved to be used in a newly added test case.
+
+2016-07-09 Ryosuke Niwa <[email protected]>
+
REGRESSION: manifest.json generation takes multiple seconds on perf dashboard
https://bugs.webkit.org/show_bug.cgi?id=159596
Modified: trunk/Websites/perf.webkit.org/public/v3/components/base.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/components/base.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/components/base.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -75,16 +75,6 @@
}
}
- static isElementInViewport(element)
- {
- var viewportHeight = window.innerHeight;
- var boundingRect = element.getBoundingClientRect();
- if (viewportHeight < boundingRect.top || boundingRect.bottom < 0
- || !boundingRect.width || !boundingRect.height)
- return false;
- return true;
- }
-
static defineElement(name, elementInterface)
{
if (!ComponentBase._map)
Modified: trunk/Websites/perf.webkit.org/public/v3/components/chart-pane-base.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/components/chart-pane-base.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/components/chart-pane-base.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -197,6 +197,12 @@
super.render();
+ if (this._overviewChart)
+ this._overviewChart.enqueueToRender();
+
+ if (this._mainChart)
+ this._mainChart.enqueueToRender();
+
if (this._errorMessage) {
this.renderReplace(this.content().querySelector('.chart-pane-main'), this._errorMessage);
return;
Modified: trunk/Websites/perf.webkit.org/public/v3/components/chart-styles.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/components/chart-styles.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/components/chart-styles.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -87,7 +87,6 @@
static dashboardOptions(valueFormatter)
{
return {
- updateOnRequestAnimationFrame: true,
axis: {
yAxisWidth: 4, // rem
xAxisHeight: 2, // rem
Modified: trunk/Websites/perf.webkit.org/public/v3/components/time-series-chart.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/components/time-series-chart.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/components/time-series-chart.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -21,12 +21,11 @@
this._contextScaleY = 1;
this._rem = null;
- if (this._options.updateOnRequestAnimationFrame) {
- if (!TimeSeriesChart._chartList)
- TimeSeriesChart._chartList = [];
- TimeSeriesChart._chartList.push(this);
- TimeSeriesChart._updateOnRAF();
+ if (!TimeSeriesChart._chartList) {
+ TimeSeriesChart._chartList = [];
+ window.addEventListener('resize', TimeSeriesChart._updateAllCharts.bind(TimeSeriesChart));
}
+ TimeSeriesChart._chartList.push(this);
}
_ensureCanvas()
@@ -51,16 +50,27 @@
return document.createElement('canvas');
}
- static _updateOnRAF()
+ static _updateAllCharts()
{
- var self = this;
- window.requestAnimationFrame(function ()
- {
- TimeSeriesChart._chartList.map(function (chart) { chart.render(); });
- self._updateOnRAF();
- });
+ TimeSeriesChart._chartList.map(function (chart) { chart.render(); });
}
+ enqueueToRender()
+ {
+ if (!TimeSeriesChart._chartQueue) {
+ TimeSeriesChart._chartQueue = new Set;
+ window.requestAnimationFrame(TimeSeriesChart._renderEnqueuedCharts.bind(TimeSeriesChart));
+ }
+ TimeSeriesChart._chartQueue.add(this);
+ }
+
+ static _renderEnqueuedCharts()
+ {
+ for (var chart of TimeSeriesChart._chartQueue)
+ chart.render();
+ TimeSeriesChart._chartQueue = null;
+ }
+
setDomain(startTime, endTime)
{
console.assert(startTime < endTime, 'startTime must be before endTime');
@@ -77,13 +87,21 @@
fetchMeasurementSets(noCache)
{
+ var fetching = false;
for (var source of this._sourceList) {
- if (source.measurementSet)
+ if (source.measurementSet) {
+ if (source.measurementSet.hasFetchedRange(this._startTime, this._endTime))
+ continue;
source.measurementSet.fetchBetween(this._startTime, this._endTime, this._didFetchMeasurementSet.bind(this, source.measurementSet), noCache);
+ fetching = true;
+ }
+
}
this._sampledTimeSeriesData = null;
this._valueRangeCache = null;
this._annotationRows = null;
+ if (!fetching)
+ this.enqueueToRender();
}
_didFetchMeasurementSet(set)
@@ -92,6 +110,8 @@
this._sampledTimeSeriesData = null;
this._valueRangeCache = null;
this._annotationRows = null;
+
+ this.enqueueToRender();
}
// FIXME: Figure out a way to make this readonly.
@@ -135,8 +155,6 @@
// FIXME: Also detect horizontal scrolling.
var canvas = this._ensureCanvas();
- if (!TimeSeriesChart.isElementInViewport(canvas))
- return;
var metrics = this._layout();
if (!metrics.doneWork)
Modified: trunk/Websites/perf.webkit.org/public/v3/models/measurement-set.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/models/measurement-set.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/models/measurement-set.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -150,18 +150,23 @@
hasFetchedRange(startTime, endTime)
{
console.assert(startTime < endTime);
- var hasHole = false;
+ var foundStart = false;
var previousEndTime = null;
for (var cluster of this._sortedClusters) {
- if (cluster.startTime() < startTime && startTime < cluster.endTime())
- hasHole = false;
- if (previousEndTime !== null && previousEndTime != cluster.startTime())
- hasHole = true;
- if (cluster.startTime() < endTime && endTime < cluster.endTime())
- break;
+ var containsStart = cluster.startTime() <= startTime && startTime <= cluster.endTime();
+ var containsEnd = cluster.startTime() <= endTime && endTime <= cluster.endTime();
+ var preceedingClusterIsMissing = previousEndTime !== null && previousEndTime != cluster.startTime();
+ if (containsStart && containsEnd)
+ return true;
+ if (containsStart)
+ foundStart = true;
+ if (foundStart && preceedingClusterIsMissing)
+ return false;
+ if (containsEnd)
+ return foundStart; // Return true iff there were not missing clusters from the one that contains startTime
previousEndTime = cluster.endTime();
}
- return !hasHole;
+ return false; // Didn't find a cluster that contains startTime or endTime
}
fetchedTimeSeries(configType, includeOutliers, extendToFuture)
Modified: trunk/Websites/perf.webkit.org/public/v3/pages/chart-pane-status-view.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/pages/chart-pane-status-view.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/pages/chart-pane-status-view.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -117,7 +117,6 @@
{
this.updateStatusIfNeeded();
- this._forceRender = true;
for (var info of this._revisionList) {
if (info.repository == this._currentRepository) {
this._setRevisionRange(false, info.repository, info.from, info.to);
Modified: trunk/Websites/perf.webkit.org/public/v3/pages/dashboard-page.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/pages/dashboard-page.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/pages/dashboard-page.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -109,6 +109,9 @@
this._needsTableConstruction = false;
}
+ for (var chart of this._charts)
+ chart.enqueueToRender();
+
if (this._needsStatusUpdate) {
for (var statusView of this._statusViews)
statusView.render();
Modified: trunk/Websites/perf.webkit.org/public/v3/pages/heading.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/public/v3/pages/heading.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/public/v3/pages/heading.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -52,8 +52,7 @@
if (this._toolbar)
this._toolbar.render();
- // Workaround the bounding rects being 0x0 when the content is empty.
- if (this._renderedOnce && !Heading.isElementInViewport(this.element()))
+ if (this._renderedOnce)
return;
var title = this.content().querySelector('.heading-title a');
Modified: trunk/Websites/perf.webkit.org/unit-tests/measurement-set-tests.js (203034 => 203035)
--- trunk/Websites/perf.webkit.org/unit-tests/measurement-set-tests.js 2016-07-09 21:07:45 UTC (rev 203034)
+++ trunk/Websites/perf.webkit.org/unit-tests/measurement-set-tests.js 2016-07-09 22:58:54 UTC (rev 203035)
@@ -14,6 +14,15 @@
MeasurementSet._set = null;
});
+ function waitForMeasurementSet()
+ {
+ return Promise.resolve().then(function () {
+ return Promise.resolve();
+ }).then(function () {
+ return Promise.resolve();
+ });
+ }
+
describe('findSet', function () {
it('should create a new MeasurementSet for a new pair of platform and matric', function () {
assert.notEqual(MeasurementSet.findSet(1, 1, 3000), MeasurementSet.findSet(1, 2, 3000));
@@ -71,15 +80,6 @@
});
});
- function waitForMeasurementSet()
- {
- return Promise.resolve().then(function () {
- return Promise.resolve();
- }).then(function () {
- return Promise.resolve();
- });
- }
-
it('should invoke the callback and fetch a secondary cluster when the cached primary cluster is up-to-date and within in the requested range', function (done) {
var set = MeasurementSet.findSet(1, 1, 3000);
var callCount = 0;
@@ -517,4 +517,168 @@
});
+ describe('hasFetchedRange', function () {
+
+ it('should return false when no clusters had been fetched', function () {
+ var set = MeasurementSet.findSet(1, 1, 3000);
+ assert(!set.hasFetchedRange(2000, 3000));
+ });
+
+ it('should return true when a single cluster contains the entire range', function (done) {
+ var set = MeasurementSet.findSet(1, 1, 3000);
+ var promise = set.fetchBetween(2000, 3000);
+ assert.equal(requests.length, 1);
+ assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
+
+ requests[0].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 2000,
+ 'endTime': 3000,
+ 'lastModified': 3000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+
+ promise.then(function () {
+ assert(set.hasFetchedRange(2001, 2999));
+ assert(set.hasFetchedRange(2000, 3000));
+ done();
+ }).catch(function (error) {
+ done(error);
+ });
+ });
+
+ it('should return false when the range starts before the fetched cluster', function (done) {
+ var set = MeasurementSet.findSet(1, 1, 3000);
+ var promise = set.fetchBetween(2000, 3000);
+ assert.equal(requests.length, 1);
+ assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
+
+ requests[0].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 2000,
+ 'endTime': 3000,
+ 'lastModified': 3000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+
+ promise.then(function () {
+ assert(!set.hasFetchedRange(1500, 3000));
+ done();
+ }).catch(function (error) {
+ done(error);
+ });
+ });
+
+ it('should return false when the range ends after the fetched cluster', function (done) {
+ var set = MeasurementSet.findSet(1, 1, 3000);
+ var promise = set.fetchBetween(2000, 3000);
+ assert.equal(requests.length, 1);
+ assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
+
+ requests[0].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 2000,
+ 'endTime': 3000,
+ 'lastModified': 3000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+
+ promise.then(function () {
+ assert(!set.hasFetchedRange(2500, 3500));
+ done();
+ }).catch(function (error) {
+ done(error);
+ });
+ });
+
+ it('should return true when the range is within two fetched clusters', function (done) {
+ var set = MeasurementSet.findSet(1, 1, 5000);
+ var promise = set.fetchBetween(2000, 3000);
+ assert.equal(requests.length, 1);
+ assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
+
+ requests[0].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 3000,
+ 'endTime': 4000,
+ 'lastModified': 5000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+
+ waitForMeasurementSet().then(function () {
+ assert.equal(requests.length, 2);
+ assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
+ requests[1].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 2000,
+ 'endTime': 3000,
+ 'lastModified': 5000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+ }).then(function () {
+ assert(set.hasFetchedRange(2500, 3500));
+ done();
+ }).catch(function (error) {
+ done(error);
+ });
+ });
+
+ it('should return false when there is a cluster missing in the range', function (done) {
+ var set = MeasurementSet.findSet(1, 1, 5000);
+ var promise = set.fetchBetween(2000, 5000);
+ assert.equal(requests.length, 1);
+ assert.equal(requests[0].url, '../data/measurement-set-1-1.json');
+
+ requests[0].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 4000,
+ 'endTime': 5000,
+ 'lastModified': 5000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+
+ waitForMeasurementSet().then(function () {
+ assert.equal(requests.length, 3);
+ assert.equal(requests[1].url, '../data/measurement-set-1-1-3000.json');
+ assert.equal(requests[2].url, '../data/measurement-set-1-1-4000.json');
+ requests[1].resolve({
+ 'clusterStart': 1000,
+ 'clusterSize': 1000,
+ 'formatMap': [],
+ 'configurations': {current: []},
+ 'startTime': 2000,
+ 'endTime': 3000,
+ 'lastModified': 5000,
+ 'clusterCount': 2,
+ 'status': 'OK'});
+ }).then(function () {
+ assert(!set.hasFetchedRange(2500, 4500));
+ assert(set.hasFetchedRange(2100, 2300));
+ assert(set.hasFetchedRange(4000, 4800));
+ done();
+ }).catch(function (error) {
+ done(error);
+ });
+ });
+
+ });
+
});
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
