Skip to content
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 9 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lighthouse-cli/test/cli/__snapshots__/index-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ Object {
Object {
"path": "metrics/estimated-input-latency",
},
Object {
"path": "metrics/max-potential-fid",
},
Object {
"path": "errors-in-console",
},
Expand Down Expand Up @@ -682,6 +685,10 @@ Object {
"id": "estimated-input-latency",
"weight": 0,
},
Object {
"id": "max-potential-fid",
"weight": 0,
},
Object {
"group": "load-opportunities",
"id": "render-blocking-resources",
Expand Down
76 changes: 76 additions & 0 deletions lighthouse-core/audits/metrics/max-potential-fid.js
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 {
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* @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 lighthouse-core/computed/metrics/lantern-max-potential-fid.js
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({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could just filter nodeTimings instead of constructing these new objects...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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);
45 changes: 45 additions & 0 deletions lighthouse-core/computed/metrics/max-potential-fid.js
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);
2 changes: 2 additions & 0 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const defaultConfig = {
'screenshot-thumbnails',
'final-screenshot',
'metrics/estimated-input-latency',
'metrics/max-potential-fid',
'errors-in-console',
'time-to-first-byte',
'metrics/first-cpu-idle',
Expand Down Expand Up @@ -328,6 +329,7 @@ const defaultConfig = {
{id: 'interactive', weight: 5, group: 'metrics'},
{id: 'first-cpu-idle', weight: 2, group: 'metrics'},
{id: 'estimated-input-latency', weight: 0, group: 'metrics'},
{id: 'max-potential-fid', weight: 0}, // intentionally left out of metrics so it won't be displayed yet

{id: 'render-blocking-resources', weight: 0, group: 'load-opportunities'},
{id: 'uses-responsive-images', weight: 0, group: 'load-opportunities'},
Expand Down
8 changes: 8 additions & 0 deletions lighthouse-core/lib/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@
"message": "Time to Interactive",
"description": "The name of the metric that marks the time at which the page is fully loaded and is able to quickly respond to user input (clicks, taps, and keypresses feel responsive). Shown to users as the label for the numeric metric value. Ideally fits within a ~40 character limit."
},
"lighthouse-core/audits/metrics/max-potential-fid.js | description": {
"message": "The potential First Input Delay that your users could experience is the duration, in milliseconds, of the longest task.",
"description": "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."
},
"lighthouse-core/audits/metrics/max-potential-fid.js | title": {
"message": "Max Potential FID",
"description": "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."
},
"lighthouse-core/audits/metrics/speed-index.js | description": {
"message": "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).",
"description": "Description of the Speed Index metric, which summarizes how quickly the page looked visually complete. This 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."
Expand Down
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 lighthouse-core/test/computed/metrics/max-potential-fid-test.js
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);
});
});
37 changes: 37 additions & 0 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@
"rawValue": 16,
"displayValue": "20 ms"
},
"max-potential-fid": {
"id": "max-potential-fid",
"title": "Max Potential FID",
"description": "The potential First Input Delay that your users could experience is the duration, in milliseconds, of the longest task.",
"score": 0.92,
"scoreDisplayMode": "numeric",
"rawValue": 122.537,
"displayValue": "120 ms"
},
"errors-in-console": {
"id": "errors-in-console",
"title": "Browser errors were logged to the console",
Expand Down Expand Up @@ -2790,6 +2799,10 @@
"weight": 0,
"group": "metrics"
},
{
"id": "max-potential-fid",
"weight": 0
},
{
"id": "render-blocking-resources",
"weight": 0,
Expand Down Expand Up @@ -3599,6 +3612,18 @@
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:max-potential-fid",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:MaxPotentialFID",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:errors-in-console",
Expand Down Expand Up @@ -4416,8 +4441,20 @@
"timeInMs": 16
},
"path": "audits[estimated-input-latency].displayValue"
},
{
"values": {
"timeInMs": 122.537
},
"path": "audits[max-potential-fid].displayValue"
}
],
"lighthouse-core/audits/metrics/max-potential-fid.js | title": [
"audits[max-potential-fid].title"
],
"lighthouse-core/audits/metrics/max-potential-fid.js | description": [
"audits[max-potential-fid].description"
],
"lighthouse-core/audits/time-to-first-byte.js | title": [
"audits[time-to-first-byte].title"
],
Expand Down
Loading