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 all 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
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.js');
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: 1 addition & 1 deletion lighthouse-core/config/lr-desktop-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const config = {
throughputKbps: 10 * 1024,
cpuSlowdownMultiplier: 1,
},
// Skip the h2 audit so it doesn't lie to us. See #6539
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
Copy link
Member

Choose a reason for hiding this comment

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

❤️

skipAudits: ['uses-http2'],
},
audits: [
Expand Down
13 changes: 12 additions & 1 deletion lighthouse-core/config/lr-mobile-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ const config = {
extends: 'lighthouse:default',
settings: {
maxWaitForLoad: 35 * 1000,
// Skip the h2 audit so it doesn't lie to us. See #6539
// Skip the h2 audit so it doesn't lie to us. See https://github.com/GoogleChrome/lighthouse/issues/6539
skipAudits: ['uses-http2'],
},
audits: [
'metrics/first-contentful-paint-3g',
],
// @ts-ignore TODO(bckenny): type extended Config where e.g. category.title isn't required
categories: {
performance: {
auditRefs: [
{id: 'first-contentful-paint-3g', weight: 0},
],
},
},
};

module.exports = config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @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 FCP3G = require('../../../audits/metrics/first-contentful-paint-3g.js');
const options = FCP3G.defaultOptions;

const pwaTrace = require('../../fixtures/traces/progressive-app-m60.json');
const pwaDevtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json');

/* eslint-env jest */

describe('Performance: first-contentful-paint-3g audit', () => {
it('evaluates valid input correctly', async () => {
const artifacts = {
traces: {
[FCP3G.DEFAULT_PASS]: pwaTrace,
},
devtoolsLogs: {
[FCP3G.DEFAULT_PASS]: pwaDevtoolsLog,
},
};

const result = await FCP3G.audit(artifacts, {settings: {}, options, computedCache: new Map()});
// Use InlineSnapshot here so changes to Lantern coefficients can be easily updated en masse
expect({score: result.score, value: Math.round(result.rawValue)}).toMatchInlineSnapshot(`
Object {
"score": 1,
"value": 1661,
}
Copy link
Member

Choose a reason for hiding this comment

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

lol

`);
});
});