-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core(metrics): switch to speedIndex from perceptualSpeedIndex #4980
Changes from 1 commit
2a29d61
4161dce
ef527da
ec36daf
f75c225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,21 @@ 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 timeToInteractive = await artifacts.requestConsistentlyInteractive(metricComputationData); | ||
const speedIndex = await artifacts.requestSpeedIndex(metricComputationData); | ||
const metrics = []; | ||
|
||
// Include the simulated/observed performance metrics | ||
const metricsMap = {firstContentfulPaint, firstMeaningfulPaint, timeToInteractive}; | ||
const metricsMap = {firstContentfulPaint, firstMeaningfulPaint, 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 | ||
|
@@ -50,6 +56,23 @@ class Metrics extends Audit { | |
metrics.push({metricName, timing, timestamp}); | ||
} | ||
|
||
// Include some visual metrics from speedline | ||
metrics.push({ | ||
metricName: 'traceFirstVisualChange', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like these aren't from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. open to ideas, I'd like to be consistent here on the fact that these are the raw observed values compared to the (potentially) simulated metric values WDYT about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm okay. maybe we use 'observed' prefix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no no you're 😎 I originally had |
||
timing: speedline.first, | ||
timestamp: (speedline.first + speedline.beginning) * 1000, | ||
}); | ||
metrics.push({ | ||
metricName: 'traceLastVisualChange', | ||
timing: speedline.complete, | ||
timestamp: (speedline.complete + speedline.beginning) * 1000, | ||
}); | ||
metrics.push({ | ||
metricName: 'traceSpeedIndex', | ||
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)'}, | ||
|
This file was deleted.
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; |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we just collapse these 2 into 1? not sure if we use speedline for non-speedindex purposes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to keep them separate for exactly that reason, also if we want to do other stuff with the frames There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aiight groovy. 🕺 |
||
const timing = Math.round(speedline.speedIndex); | ||
const timestamp = (timing + speedline.beginning) * 1000; | ||
return Promise.resolve({timing, timestamp}); | ||
} | ||
} | ||
|
||
module.exports = SpeedIndex; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was done just in the audit, but it makes sense to be doing this everywhere speedline is needed, moved the test as well |
||
throw new LHError(LHError.errors.NO_SPEEDLINE_FRAMES); | ||
} | ||
|
||
if (speedline.speedIndex === 0) { | ||
throw new LHError(LHError.errors.SPEEDINDEX_OF_ZERO); | ||
} | ||
|
||
return speedline; | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice