-
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 all commits
2a29d61
4161dce
ef527da
ec36daf
f75c225
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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