forked from checkinholiday/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
predictive-perf.js
107 lines (92 loc) · 3.97 KB
/
predictive-perf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {Audit} from './audit.js';
import * as i18n from '../lib/i18n/i18n.js';
import {LanternFirstContentfulPaint} from '../computed/metrics/lantern-first-contentful-paint.js';
import {LanternFirstMeaningfulPaint} from '../computed/metrics/lantern-first-meaningful-paint.js';
import {LanternInteractive} from '../computed/metrics/lantern-interactive.js';
import {LanternSpeedIndex} from '../computed/metrics/lantern-speed-index.js';
import {LanternLargestContentfulPaint} from '../computed/metrics/lantern-largest-contentful-paint.js';
import {TimingSummary} from '../computed/metrics/timing-summary.js';
import {defaultSettings} from '../config/constants.js';
// Parameters (in ms) for log-normal CDF scoring. To see the curve:
// https://www.desmos.com/calculator/bksgkihhj8
const SCORING_P10 = 3651;
const SCORING_MEDIAN = 10000;
const str_ = i18n.createIcuMessageFn(import.meta.url, {});
class PredictivePerf extends Audit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'predictive-perf',
title: 'Predicted Performance (beta)',
description:
'Predicted performance evaluates how your site will perform under ' +
'a cellular connection on a mobile device.',
scoreDisplayMode: Audit.SCORING_MODES.NUMERIC,
supportedModes: ['navigation'],
requiredArtifacts: ['traces', 'devtoolsLogs', 'GatherContext', 'URL'],
};
}
/**
* @param {LH.Artifacts} artifacts
* @param {LH.Audit.Context} context
* @return {Promise<LH.Audit.Product>}
*/
static async audit(artifacts, context) {
const gatherContext = artifacts.GatherContext;
const trace = artifacts.traces[Audit.DEFAULT_PASS];
const devtoolsLog = artifacts.devtoolsLogs[Audit.DEFAULT_PASS];
const URL = artifacts.URL;
/** @type {LH.Config.Settings} */
const settings = JSON.parse(JSON.stringify(defaultSettings)); // Use default settings.
const computationData = {trace, devtoolsLog, gatherContext, settings, URL};
const fcp = await LanternFirstContentfulPaint.request(computationData, context);
const fmp = await LanternFirstMeaningfulPaint.request(computationData, context);
const tti = await LanternInteractive.request(computationData, context);
const si = await LanternSpeedIndex.request(computationData, context);
const lcp = await LanternLargestContentfulPaint.request(computationData, context);
const timingSummary = await TimingSummary.request(computationData, context);
const values = {
roughEstimateOfFCP: fcp.timing,
optimisticFCP: fcp.optimisticEstimate.timeInMs,
pessimisticFCP: fcp.pessimisticEstimate.timeInMs,
roughEstimateOfFMP: fmp.timing,
optimisticFMP: fmp.optimisticEstimate.timeInMs,
pessimisticFMP: fmp.pessimisticEstimate.timeInMs,
roughEstimateOfTTI: tti.timing,
optimisticTTI: tti.optimisticEstimate.timeInMs,
pessimisticTTI: tti.pessimisticEstimate.timeInMs,
roughEstimateOfSI: si.timing,
optimisticSI: si.optimisticEstimate.timeInMs,
pessimisticSI: si.pessimisticEstimate.timeInMs,
roughEstimateOfLCP: lcp.timing,
optimisticLCP: lcp.optimisticEstimate.timeInMs,
pessimisticLCP: lcp.pessimisticEstimate.timeInMs,
roughEstimateOfTTFB: timingSummary.metrics.timeToFirstByte,
roughEstimateOfLCPLoadStart: timingSummary.metrics.lcpLoadStart,
roughEstimateOfLCPLoadEnd: timingSummary.metrics.lcpLoadEnd,
};
const score = Audit.computeLogNormalScore(
{p10: SCORING_P10, median: SCORING_MEDIAN},
values.roughEstimateOfTTI
);
return {
score,
numericValue: values.roughEstimateOfTTI,
numericUnit: 'millisecond',
displayValue: str_(i18n.UIStrings.ms, {timeInMs: values.roughEstimateOfTTI}),
details: {
type: 'debugdata',
// TODO: Consider not nesting values under `items`.
items: [values],
},
};
}
}
export default PredictivePerf;