Skip to content

Commit

Permalink
core(metrics): switch to speedIndex from perceptualSpeedIndex (#4980)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed Apr 19, 2018
1 parent 9b7b690 commit cc56516
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 357 deletions.
9 changes: 1 addition & 8 deletions lighthouse-cli/test/smokehouse/perf/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ module.exports = [
initialUrl: 'http://localhost:10200/preload.html',
url: 'http://localhost:10200/preload.html',
audits: {
'speed-index-metric': {
'speed-index': {
score: '>=0.80',
extendedInfo: {
value: {
timings: {},
timestamps: {},
frames: [],
},
},
},
'first-meaningful-paint': {
score: '>=0.90',
Expand Down
29 changes: 27 additions & 2 deletions lighthouse-core/audits/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class Metrics extends Audit {
const metricComputationData = {trace, devtoolsLog, settings: context.settings};

const traceOfTab = await artifacts.requestTraceOfTab(trace);
const speedline = await artifacts.requestSpeedline(trace);
const firstContentfulPaint = await artifacts.requestFirstContentfulPaint(metricComputationData);
const firstMeaningfulPaint = await artifacts.requestFirstMeaningfulPaint(metricComputationData);
const firstCPUIdle = await artifacts.requestFirstCPUIdle(metricComputationData);
const timeToInteractive = await artifacts.requestConsistentlyInteractive(metricComputationData);
const speedIndex = await artifacts.requestSpeedIndex(metricComputationData);
const metrics = [];

// Include the simulated/observed performance metrics
Expand All @@ -43,19 +45,42 @@ class Metrics extends Audit {
firstMeaningfulPaint,
firstCPUIdle,
timeToInteractive,
speedIndex,
};

for (const [metricName, values] of Object.entries(metricsMap)) {
metrics.push(Object.assign({metricName}, values));
metrics.push({
metricName,
timing: Math.round(values.timing),
timestamp: values.timestamp,
});
}

// Include all timestamps of interest from trace of tab
for (const [traceEventName, timing] of Object.entries(traceOfTab.timings)) {
const uppercased = traceEventName.slice(0, 1).toUpperCase() + traceEventName.slice(1);
const metricName = `trace${uppercased}`;
const metricName = `observed${uppercased}`;
const timestamp = traceOfTab.timestamps[traceEventName];
metrics.push({metricName, timing, timestamp});
}

// Include some visual metrics from speedline
metrics.push({
metricName: 'observedFirstVisualChange',
timing: speedline.first,
timestamp: (speedline.first + speedline.beginning) * 1000,
});
metrics.push({
metricName: 'observedLastVisualChange',
timing: speedline.complete,
timestamp: (speedline.complete + speedline.beginning) * 1000,
});
metrics.push({
metricName: 'observedSpeedIndex',
timing: speedline.speedIndex,
timestamp: (speedline.speedIndex + speedline.beginning) * 1000,
});

const headings = [
{key: 'metricName', itemType: 'text', text: 'Name'},
{key: 'timing', itemType: 'ms', granularity: 10, text: 'Value (ms)'},
Expand Down
106 changes: 0 additions & 106 deletions lighthouse-core/audits/speed-index-metric.js

This file was deleted.

62 changes: 62 additions & 0 deletions lighthouse-core/audits/speed-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license Copyright 2016 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const Audit = require('./audit');
const Util = require('../report/v2/renderer/util');

class SpeedIndex extends Audit {
/**
* @return {!AuditMeta}
*/
static get meta() {
return {
name: 'speed-index',
description: 'Speed Index',
helpText: 'Speed Index shows how quickly the contents of a page are visibly populated. ' +
'[Learn more](https://developers.google.com/web/tools/lighthouse/audits/speed-index).',
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC,
requiredArtifacts: ['traces', 'devtoolsLogs'],
};
}

/**
* @return {LH.Audit.ScoreOptions}
*/
static get defaultOptions() {
return {
// see https://www.desmos.com/calculator/mdgjzchijg
scorePODR: 1250,
scoreMedian: 5500,
};
}

/**
* Audits the page to give a score for the Speed Index.
* @see https://github.com/GoogleChrome/lighthouse/issues/197
* @param {Artifacts} artifacts The artifacts from the gather phase.
* @param {LH.Audit.Context} context
* @return {Promise<AuditResult>}
*/
static async audit(artifacts, context) {
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const metricComputationData = {trace, devtoolsLog, settings: context.settings};
const metricResult = await artifacts.requestSpeedIndex(metricComputationData);

return {
score: Audit.computeLogNormalScore(
metricResult.timing,
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
displayValue: Util.formatMilliseconds(metricResult.timing),
};
}
}

module.exports = SpeedIndex;
4 changes: 2 additions & 2 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {
'first-contentful-paint',
'first-meaningful-paint',
'load-fast-enough-for-pwa',
'speed-index-metric',
'speed-index',
'screenshot-thumbnails',
'estimated-input-latency',
'errors-in-console',
Expand Down Expand Up @@ -268,7 +268,7 @@ module.exports = {
{id: 'first-meaningful-paint', weight: 3, group: 'perf-metric'},
{id: 'first-cpu-idle', weight: 5, group: 'perf-metric'},
{id: 'consistently-interactive', weight: 5, group: 'perf-metric'},
{id: 'speed-index-metric', weight: 1, group: 'perf-metric'},
{id: 'speed-index', weight: 1, group: 'perf-metric'},
{id: 'estimated-input-latency', weight: 1, group: 'perf-metric'},
{id: 'link-blocking-first-paint', weight: 0, group: 'perf-hint'},
{id: 'script-blocking-first-paint', weight: 0, group: 'perf-hint'},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/fast-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
'first-cpu-idle',
'consistently-interactive',
'estimated-input-latency',
'speed-index-metric',
'speed-index',
'offscreen-images',
'load-fast-enough-for-pwa',
],
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/plots-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
settings: {
onlyAudits: [
'first-meaningful-paint',
'speed-index-metric',
'speed-index',
'estimated-input-latency',
'first-cpu-idle',
'consistently-interactive',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SpeedIndex extends MetricArtifact {
getEstimateFromSimulation(simulationResult, extras) {
const fcpTimeInMs = extras.fcpResult.timing;
const estimate = extras.optimistic
? extras.speedline.perceptualSpeedIndex
? extras.speedline.speedIndex
: SpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTiming, fcpTimeInMs);
return {
timeInMs: estimate,
Expand Down
28 changes: 28 additions & 0 deletions lighthouse-core/gather/computed/metrics/speed-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const MetricArtifact = require('./metric');

class SpeedIndex extends MetricArtifact {
get name() {
return 'SpeedIndex';
}

/**
* @param {LH.Artifacts.MetricComputationData} data
* @param {Object} artifacts
* @return {Promise<LH.Artifacts.Metric>}
*/
async computeObservedMetric(data, artifacts) {
const speedline = await artifacts.requestSpeedline(data.trace);
const timing = Math.round(speedline.speedIndex);
const timestamp = (timing + speedline.beginning) * 1000;
return Promise.resolve({timing, timestamp});
}
}

module.exports = SpeedIndex;
12 changes: 11 additions & 1 deletion lighthouse-core/gather/computed/speedline.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,24 @@ class Speedline extends ComputedArtifact {
return speedline(traceEvents, {
timeOrigin: navStart,
fastMode: true,
include: 'perceptualSpeedIndex',
include: 'speedIndex',
});
}).catch(err => {
if (/No screenshots found in trace/.test(err.message)) {
throw new LHError(LHError.errors.NO_SCREENSHOTS);
}

throw err;
}).then(speedline => {
if (speedline.frames.length === 0) {
throw new LHError(LHError.errors.NO_SPEEDLINE_FRAMES);
}

if (speedline.speedIndex === 0) {
throw new LHError(LHError.errors.SPEEDINDEX_OF_ZERO);
}

return speedline;
});
}
}
Expand Down
Loading

0 comments on commit cc56516

Please sign in to comment.