-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
new_audit: add Max Potential FID to JSON #5842
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6372106
new_audit(mfid): add Max Potential FID metric
patrickhulce d54ad37
feedback
patrickhulce 09e4791
Merge branch 'master' into max_fid
patrickhulce a330763
fix after merge
patrickhulce bce2822
test fixes
patrickhulce a69895f
undo EIL change
patrickhulce e2b6999
add test
patrickhulce 835967c
just use filter instead
patrickhulce 6554fa1
Merge branch 'master' into max_fid
patrickhulce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @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 Audit = require('../audit'); | ||
const ComputedFid = require('../../computed/metrics/max-potential-fid.js'); | ||
const i18n = require('../../lib/i18n/i18n'); | ||
|
||
const UIStrings = { | ||
/** The name of the metric "Maximum Potential First Input Delay" that marks the maximum estimated time between the page receiving input (a user clicking, tapping, or typing) and the page responding. Shown to users as the label for the numeric metric value. Ideally fits within a ~40 character limit. */ | ||
title: 'Max Potential FID', | ||
/** Description of the Estimated Input Latency metric that estimates the amount of time, in milliseconds, that the app takes to respond to user input. This description is displayed within a tooltip when the user hovers on the metric name to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */ | ||
description: 'The potential First Input Delay that your users could experience is the ' + | ||
'duration, in milliseconds, of the longest task.', | ||
}; | ||
|
||
const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); | ||
|
||
/** | ||
* @fileoverview This metric is the duration of the longest task after FCP. It is meant to capture | ||
* the worst case First Input Delay that a user might experience. | ||
* Tasks before FCP are excluded because it is unlikely that the user will try to interact with a page before it has painted anything. | ||
*/ | ||
class MaxPotentialFID extends Audit { | ||
/** | ||
* @return {LH.Audit.Meta} | ||
*/ | ||
static get meta() { | ||
return { | ||
id: 'max-potential-fid', | ||
title: str_(UIStrings.title), | ||
description: str_(UIStrings.description), | ||
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC, | ||
requiredArtifacts: ['traces'], | ||
}; | ||
} | ||
|
||
/** | ||
* @return {LH.Audit.ScoreOptions} | ||
*/ | ||
static get defaultOptions() { | ||
return { | ||
// see https://www.desmos.com/calculator/g3nf1ehtnk | ||
scorePODR: 100, | ||
scoreMedian: 250, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts} artifacts | ||
* @param {LH.Audit.Context} context | ||
* @return {Promise<LH.Audit.Product>} | ||
*/ | ||
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 ComputedFid.request(metricComputationData, context); | ||
|
||
return { | ||
score: Audit.computeLogNormalScore( | ||
metricResult.timing, | ||
context.options.scorePODR, | ||
context.options.scoreMedian | ||
), | ||
rawValue: metricResult.timing, | ||
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}), | ||
}; | ||
} | ||
} | ||
|
||
module.exports = MaxPotentialFID; | ||
module.exports.UIStrings = UIStrings; |
98 changes: 98 additions & 0 deletions
98
lighthouse-core/computed/metrics/lantern-max-potential-fid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @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 makeComputedArtifact = require('../computed-artifact.js'); | ||
const LanternMetricArtifact = require('./lantern-metric'); | ||
const BaseNode = require('../../lib/dependency-graph/base-node'); | ||
const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js'); | ||
|
||
/** @typedef {BaseNode.Node} Node */ | ||
|
||
class LanternMaxPotentialFID extends LanternMetricArtifact { | ||
/** | ||
* @return {LH.Gatherer.Simulation.MetricCoefficients} | ||
*/ | ||
static get COEFFICIENTS() { | ||
return { | ||
intercept: 0, | ||
optimistic: 0.5, | ||
pessimistic: 0.5, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {Node} dependencyGraph | ||
* @return {Node} | ||
*/ | ||
static getOptimisticGraph(dependencyGraph) { | ||
return dependencyGraph; | ||
} | ||
|
||
/** | ||
* @param {Node} dependencyGraph | ||
* @return {Node} | ||
*/ | ||
static getPessimisticGraph(dependencyGraph) { | ||
return dependencyGraph; | ||
} | ||
|
||
/** | ||
* @param {LH.Gatherer.Simulation.Result} simulation | ||
* @param {Object} extras | ||
* @return {LH.Gatherer.Simulation.Result} | ||
*/ | ||
static getEstimateFromSimulation(simulation, extras) { | ||
// Intentionally use the opposite FCP estimate, a more pessimistic FCP means that more tasks | ||
// are excluded from the FID computation, so a higher FCP means lower FID for same work. | ||
const fcpTimeInMs = extras.optimistic | ||
? extras.fcpResult.pessimisticEstimate.timeInMs | ||
: extras.fcpResult.optimisticEstimate.timeInMs; | ||
|
||
const events = LanternMaxPotentialFID.getEventsAfterFCP( | ||
simulation.nodeTimings, | ||
fcpTimeInMs | ||
); | ||
|
||
return { | ||
timeInMs: Math.max(...events.map(evt => evt.duration), 16), | ||
nodeTimings: simulation.nodeTimings, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationDataInput} data | ||
* @param {LH.Audit.Context} context | ||
* @return {Promise<LH.Artifacts.LanternMetric>} | ||
*/ | ||
static async compute_(data, context) { | ||
const fcpResult = await LanternFirstContentfulPaint.request(data, context); | ||
return super.computeMetricWithGraphs(data, context, {fcpResult}); | ||
} | ||
|
||
/** | ||
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings | ||
* @param {number} fcpTimeInMs | ||
*/ | ||
static getEventsAfterFCP(nodeTimings, fcpTimeInMs) { | ||
/** @type {Array<{start: number, end: number, duration: number}>} */ | ||
const events = []; | ||
for (const [node, timing] of nodeTimings.entries()) { | ||
if (node.type !== BaseNode.TYPES.CPU) continue; | ||
if (timing.endTime < fcpTimeInMs) continue; | ||
|
||
events.push({ | ||
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. you could just filter nodeTimings instead of constructing these new objects... 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. good point! done |
||
start: timing.startTime, | ||
end: timing.endTime, | ||
duration: timing.duration, | ||
}); | ||
} | ||
|
||
return events; | ||
} | ||
} | ||
|
||
module.exports = makeComputedArtifact(LanternMaxPotentialFID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @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 makeComputedArtifact = require('../computed-artifact.js'); | ||
const MetricArtifact = require('./metric'); | ||
const LanternMaxPotentialFID = require('./lantern-max-potential-fid.js'); | ||
const LHError = require('../../lib/lh-error'); | ||
const TracingProcessor = require('../../lib/traces/tracing-processor'); | ||
|
||
class MaxPotentialFID extends MetricArtifact { | ||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @param {LH.Audit.Context} context | ||
* @return {Promise<LH.Artifacts.LanternMetric>} | ||
*/ | ||
static computeSimulatedMetric(data, context) { | ||
return LanternMaxPotentialFID.request(data, context); | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.MetricComputationData} data | ||
* @return {Promise<LH.Artifacts.Metric>} | ||
*/ | ||
static computeObservedMetric(data) { | ||
const {firstContentfulPaint} = data.traceOfTab.timings; | ||
if (!firstContentfulPaint) { | ||
throw new LHError(LHError.errors.NO_FCP); | ||
} | ||
|
||
const events = TracingProcessor.getMainThreadTopLevelEvents( | ||
data.traceOfTab, | ||
firstContentfulPaint | ||
).filter(evt => evt.duration >= 1); | ||
|
||
return Promise.resolve({ | ||
timing: Math.max(...events.map(evt => evt.duration), 16), | ||
}); | ||
} | ||
} | ||
|
||
module.exports = makeComputedArtifact(MaxPotentialFID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
lighthouse-core/test/computed/metrics/__snapshots__/max-potential-fid-test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Metrics: Max Potential FID should compute a simulated value 1`] = ` | ||
Object { | ||
"optimistic": 396, | ||
"pessimistic": 396, | ||
"timing": 396, | ||
} | ||
`; |
36 changes: 36 additions & 0 deletions
36
lighthouse-core/test/computed/metrics/max-potential-fid-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @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 assert = require('assert'); | ||
|
||
const MaxPotentialFID = require('../../../computed/metrics/max-potential-fid.js'); | ||
const trace = require('../../fixtures/traces/progressive-app-m60.json'); | ||
const devtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json'); | ||
|
||
/* eslint-env jest */ | ||
|
||
describe('Metrics: Max Potential FID', () => { | ||
it('should compute a simulated value', async () => { | ||
const settings = {throttlingMethod: 'simulate'}; | ||
const context = {settings, computedCache: new Map()}; | ||
const result = await MaxPotentialFID.request({trace, devtoolsLog, settings}, context); | ||
|
||
expect({ | ||
timing: Math.round(result.timing), | ||
optimistic: Math.round(result.optimisticEstimate.timeInMs), | ||
pessimistic: Math.round(result.pessimisticEstimate.timeInMs), | ||
}).toMatchSnapshot(); | ||
}); | ||
|
||
it('should compute an observed value', async () => { | ||
const settings = {throttlingMethod: 'provided'}; | ||
const context = {settings, computedCache: new Map()}; | ||
const result = await MaxPotentialFID.request({trace, devtoolsLog, settings}, context); | ||
|
||
assert.equal(Math.round(result.timing), 198); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can we get some overview comment to explain the basics of how this metric is calculated?
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.
done