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

core: add FCP on 3G audit to JSON #7062

Merged
merged 4 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -27,6 +27,9 @@ Object {
Object {
"path": "metrics/first-meaningful-paint",
},
Object {
"path": "metrics/first-contentful-paint-3g",
},
Object {
"path": "load-fast-enough-for-pwa",
},
Expand Down Expand Up @@ -775,6 +778,10 @@ Object {
"id": "network-requests",
"weight": 0,
},
Object {
"id": "first-contentful-paint-3g",
"weight": 0,
},
Object {
"id": "metrics",
"weight": 0,
Expand Down
68 changes: 68 additions & 0 deletions lighthouse-core/audits/metrics/first-contentful-paint-3g.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @license Copyright 2019 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');
Copy link
Member

Choose a reason for hiding this comment

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

audit.js

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

const regular3G = require('../../config/constants.js').throttling.mobileRegluar3G;
const i18n = require('../../lib/i18n/i18n.js');
const FCP = require('./first-contentful-paint.js');
const ComputedFcp = require('../../computed/metrics/first-contentful-paint.js');

const i18nFilename = require.resolve('./first-contentful-paint.js');
const str_ = i18n.createMessageInstanceIdFn(i18nFilename, FCP.UIStrings);

class FirstContentfulPaint3G extends Audit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'first-contentful-paint-3g',
title: str_(FCP.UIStrings.title),
description: str_(FCP.UIStrings.description),
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC,
requiredArtifacts: ['traces', 'devtoolsLogs'],
};
}

/**
* @return {LH.Audit.ScoreOptions}
*/
static get defaultOptions() {
return {
// 75th and 95th percentiles HTTPArchive on Fast 3G -> multiply by 1.5 for RTT differential -> median and PODR
Copy link
Member

Choose a reason for hiding this comment

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

multiply what by 1.5?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the 75th and 95th percentiles :)

the -> is meant to be like a pipe

// https://bigquery.cloud.google.com/table/httparchive:lighthouse.2018_04_01_mobile?pli=1
scorePODR: 3000,
scoreMedian: 6000,
};
}

/**
* @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];
/** @type {LH.Config.Settings} */
const settings = {...context.settings, throttlingMethod: 'simulate', throttling: regular3G};
const metricComputationData = {trace, devtoolsLog, settings};
const metricResult = await ComputedFcp.request(metricComputationData, context);

return {
score: Audit.computeLogNormalScore(
metricResult.timing,
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
}

module.exports = FirstContentfulPaint3G;
Copy link
Member

Choose a reason for hiding this comment

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

tests?

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

13 changes: 13 additions & 0 deletions lighthouse-core/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9;
const throttling = {
DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
// These values align with WebPageTest's definition of "Fast 3G"
// But offer similar charateristics to roughly the 75th percentile of 4G connections.
mobileSlow4G: {
rttMs: 150,
throughputKbps: 1.6 * 1024,
Expand All @@ -24,6 +26,17 @@ const throttling = {
uploadThroughputKbps: 750 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
cpuSlowdownMultiplier: 4,
},
// These values partially align with WebPageTest's definition of "Regular 3G".
// These values are meant to roughly align with Chrome UX report's 3G definition which are based
// on HTTP RTT of 300-1400ms and downlink throughput of <700kbps.
mobileRegluar3G: {
rttMs: 300,
throughputKbps: 700,
requestLatencyMs: 300 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
downloadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
uploadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
cpuSlowdownMultiplier: 4,
},
};

/** @type {LH.Config.Settings} */
Expand Down
2 changes: 2 additions & 0 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const defaultConfig = {
'without-javascript',
'metrics/first-contentful-paint',
'metrics/first-meaningful-paint',
'metrics/first-contentful-paint-3g',
Copy link
Member

Choose a reason for hiding this comment

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

should we add this to the lr config files instead of the default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah good call

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we only need it in mobile right @paulirish ?

Copy link

Choose a reason for hiding this comment

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

Was this change only applied to mobile? I was testing with this version and all the desktop scores went down dramatically for first contentful paint. Are we sure that this metrics is not accidentally included in the desktop fcp score calculation?
@brendankenny @paulirish @patrickhulce

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dgargi desktop scoring changes are because of 161519a

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you're comparing to PSI you need to use the same settings PSI uses.

If you have the repo/code locally, node ./lighthouse-cli <url> --config-path=./lighthouse-core/config/lr-mobile-config.js. Replace lr-mobile-config.js with lr-desktop-config.js for the desktop quivalent.

Copy link

Choose a reason for hiding this comment

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

Oh thank you. This is invaluable information.
I tried to run the command you have given me
node ./lighthouse-cli <url> --config-path=./lighthouse-core/config/lr-desktop-config.js with the older version and compared the result to the new one.
I noticed something odd. The latest version is saying in the results
Emulated Desktop, Simulated Slow 4G network
whereas tag v3.2.1 says
Emulated Nexus 5X, Simulated Slow 4G network

Does that mean that in version v3.2.1 the configuration lr-desktop-config.js was not applied?

Copy link

@dgargi dgargi Feb 4, 2019

Choose a reason for hiding this comment

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

@patrickhulce seems this issue has put the internet in a frenzy. There are several threads in the PSI group.
Any ideas? It seems that one issue is that compressed assets are no longer being downloaded correctly when comparing to other tools. See this post for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks @dgargi there's a bug that is being investigated that also affected mobile scores (#7151) this is probably what most folks are seeing

Choose a reason for hiding this comment

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

@dgargi @patrickhulce thanks so much for the quick investigation. I filed #7151 and if you need more information, let me know. Thanks!

'load-fast-enough-for-pwa',
'metrics/speed-index',
'screenshot-thumbnails',
Expand Down Expand Up @@ -349,6 +350,7 @@ const defaultConfig = {
{id: 'dom-size', weight: 0, group: 'diagnostics'},
{id: 'critical-request-chains', weight: 0, group: 'diagnostics'},
{id: 'network-requests', weight: 0},
{id: 'first-contentful-paint-3g', weight: 0},
{id: 'metrics', weight: 0},
{id: 'user-timings', weight: 0, group: 'diagnostics'},
{id: 'bootup-time', weight: 0, group: 'diagnostics'},
Expand Down
73 changes: 59 additions & 14 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
"rawValue": 3969.136,
"displayValue": "4.0 s"
},
"first-contentful-paint-3g": {
"id": "first-contentful-paint-3g",
"title": "First Contentful Paint",
"description": "First Contentful Paint marks the time at which the first text or image is painted. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/first-contentful-paint).",
"score": 0.22,
"scoreDisplayMode": "numeric",
"rawValue": 8321.9015,
"displayValue": "8.3 s"
},
"load-fast-enough-for-pwa": {
"id": "load-fast-enough-for-pwa",
"title": "Page load is fast enough on mobile networks",
Expand Down Expand Up @@ -2928,6 +2937,10 @@
"id": "network-requests",
"weight": 0
},
{
"id": "first-contentful-paint-3g",
"weight": 0
},
{
"id": "metrics",
"weight": 0
Expand Down Expand Up @@ -3582,6 +3595,42 @@
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:first-contentful-paint-3g",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:FirstContentfulPaint",
Copy link
Member

Choose a reason for hiding this comment

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

these duplicate keys are kind of a bummer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah it is :(

I'm not sure it's worth sticking the options into the name though to differentiate either though :/

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's worth sticking the options into the name though to differentiate either though :/

yeah, will probably just confuse things without much benefit. If someone cares about that they'll be more likely to be looking at things in the timeline viewer anyways

"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:LanternFirstContentfulPaint",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:PageDependencyGraph",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:LoadSimulator",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:NetworkAnalysis",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:load-fast-enough-for-pwa",
Expand Down Expand Up @@ -3726,24 +3775,12 @@
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:PageDependencyGraph",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:LoadSimulator",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:computed:NetworkAnalysis",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:installable-manifest",
Expand Down Expand Up @@ -4393,10 +4430,12 @@
},
"icuMessagePaths": {
"lighthouse-core/audits/metrics/first-contentful-paint.js | title": [
"audits[first-contentful-paint].title"
"audits[first-contentful-paint].title",
"audits[first-contentful-paint-3g].title"
],
"lighthouse-core/audits/metrics/first-contentful-paint.js | description": [
"audits[first-contentful-paint].description"
"audits[first-contentful-paint].description",
"audits[first-contentful-paint-3g].description"
],
"lighthouse-core/lib/i18n/i18n.js | seconds": [
{
Expand All @@ -4411,6 +4450,12 @@
},
"path": "audits[first-meaningful-paint].displayValue"
},
{
"values": {
"timeInMs": 8321.9015
},
"path": "audits[first-contentful-paint-3g].displayValue"
},
{
"values": {
"timeInMs": 4417
Expand Down
60 changes: 48 additions & 12 deletions proto/sample_v2_round_trip.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,14 @@
"scoreDisplayMode": "numeric",
"title": "First Contentful Paint"
},
"first-contentful-paint-3g": {
"description": "First Contentful Paint marks the time at which the first text or image is painted. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/first-contentful-paint).",
"displayValue": "8.3\u00a0s",
"id": "first-contentful-paint-3g",
"score": 0.22,
"scoreDisplayMode": "numeric",
"title": "First Contentful Paint"
},
"first-cpu-idle": {
"description": "First CPU Idle marks the first time at which the page's main thread is quiet enough to handle input. [Learn more](https://developers.google.com/web/tools/lighthouse/audits/first-interactive).",
"displayValue": "4.9\u00a0s",
Expand Down Expand Up @@ -3045,6 +3053,10 @@
"id": "network-requests",
"weight": 0.0
},
{
"id": "first-contentful-paint-3g",
"weight": 0.0
},
{
"id": "metrics",
"weight": 0.0
Expand Down Expand Up @@ -3442,6 +3454,42 @@
"name": "lh:computed:FirstMeaningfulPaint",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:audit:first-contentful-paint-3g",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:FirstContentfulPaint",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:LanternFirstContentfulPaint",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:PageDependencyGraph",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:LoadSimulator",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:NetworkAnalysis",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
Expand Down Expand Up @@ -3586,24 +3634,12 @@
"name": "lh:computed:LanternFirstContentfulPaint",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:PageDependencyGraph",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:LoadSimulator",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:computed:NetworkAnalysis",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
Expand Down