lighthouse 11.7.0-dev.20240326 → 11.7.0-dev.20240328

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/core/audits/work-during-interaction.d.ts +2 -2
  2. package/core/audits/work-during-interaction.js +2 -2
  3. package/core/computed/metrics/lantern-first-contentful-paint.d.ts +13 -82
  4. package/core/computed/metrics/lantern-first-contentful-paint.js +15 -178
  5. package/core/computed/metrics/lantern-first-meaningful-paint.d.ts +13 -12
  6. package/core/computed/metrics/lantern-first-meaningful-paint.js +10 -49
  7. package/core/computed/metrics/lantern-interactive.d.ts +13 -21
  8. package/core/computed/metrics/lantern-interactive.js +11 -84
  9. package/core/computed/metrics/lantern-largest-contentful-paint.d.ts +13 -25
  10. package/core/computed/metrics/lantern-largest-contentful-paint.js +12 -80
  11. package/core/computed/metrics/lantern-max-potential-fid.d.ts +13 -24
  12. package/core/computed/metrics/lantern-max-potential-fid.js +11 -64
  13. package/core/computed/metrics/lantern-metric.d.ts +9 -18
  14. package/core/computed/metrics/lantern-metric.js +13 -31
  15. package/core/computed/metrics/lantern-speed-index.d.ts +13 -32
  16. package/core/computed/metrics/lantern-speed-index.js +12 -116
  17. package/core/computed/metrics/lantern-total-blocking-time.d.ts +13 -25
  18. package/core/computed/metrics/lantern-total-blocking-time.js +10 -94
  19. package/core/computed/metrics/metric.js +1 -3
  20. package/core/config/default-config.js +45 -58
  21. package/core/config/experimental-config.js +1 -1
  22. package/core/lib/lantern/metrics/first-contentful-paint.d.ts +79 -0
  23. package/core/lib/lantern/metrics/first-contentful-paint.js +200 -0
  24. package/core/lib/lantern/metrics/first-meaningful-paint.d.ts +6 -0
  25. package/core/lib/lantern/metrics/first-meaningful-paint.js +66 -0
  26. package/core/lib/lantern/metrics/interactive.d.ts +26 -0
  27. package/core/lib/lantern/metrics/interactive.js +112 -0
  28. package/core/lib/lantern/metrics/largest-contentful-paint.d.ts +19 -0
  29. package/core/lib/lantern/metrics/largest-contentful-paint.js +108 -0
  30. package/core/lib/lantern/metrics/max-potential-fid.d.ts +30 -0
  31. package/core/lib/lantern/metrics/max-potential-fid.js +92 -0
  32. package/core/lib/lantern/metrics/speed-index.d.ts +38 -0
  33. package/core/lib/lantern/metrics/speed-index.js +145 -0
  34. package/core/lib/lantern/metrics/total-blocking-time.d.ts +31 -0
  35. package/core/lib/lantern/metrics/total-blocking-time.js +128 -0
  36. package/core/lib/lighthouse-compatibility.js +53 -10
  37. package/dist/report/bundle.esm.js +1 -1
  38. package/dist/report/flow.js +2 -2
  39. package/dist/report/standalone.js +1 -1
  40. package/package.json +1 -1
  41. package/report/renderer/performance-category-renderer.d.ts +0 -7
  42. package/report/renderer/performance-category-renderer.js +1 -11
  43. package/report/renderer/report-utils.js +13 -10
  44. package/shared/localization/locales/ar-XB.json +1 -16
  45. package/shared/localization/locales/ar.json +1 -16
  46. package/shared/localization/locales/bg.json +1 -16
  47. package/shared/localization/locales/ca.json +1 -16
  48. package/shared/localization/locales/cs.json +1 -16
  49. package/shared/localization/locales/da.json +1 -16
  50. package/shared/localization/locales/de.json +1 -16
  51. package/shared/localization/locales/el.json +1 -16
  52. package/shared/localization/locales/en-GB.json +1 -16
  53. package/shared/localization/locales/en-US.json +2 -17
  54. package/shared/localization/locales/en-XA.json +1 -16
  55. package/shared/localization/locales/en-XL.json +2 -17
  56. package/shared/localization/locales/es-419.json +1 -16
  57. package/shared/localization/locales/es.json +1 -16
  58. package/shared/localization/locales/fi.json +1 -16
  59. package/shared/localization/locales/fil.json +1 -16
  60. package/shared/localization/locales/fr.json +1 -16
  61. package/shared/localization/locales/he.json +1 -16
  62. package/shared/localization/locales/hi.json +1 -16
  63. package/shared/localization/locales/hr.json +1 -16
  64. package/shared/localization/locales/hu.json +1 -16
  65. package/shared/localization/locales/id.json +1 -16
  66. package/shared/localization/locales/it.json +1 -16
  67. package/shared/localization/locales/ja.json +1 -16
  68. package/shared/localization/locales/ko.json +1 -16
  69. package/shared/localization/locales/lt.json +1 -16
  70. package/shared/localization/locales/lv.json +1 -16
  71. package/shared/localization/locales/nl.json +1 -16
  72. package/shared/localization/locales/no.json +1 -16
  73. package/shared/localization/locales/pl.json +1 -16
  74. package/shared/localization/locales/pt-PT.json +1 -16
  75. package/shared/localization/locales/pt.json +1 -16
  76. package/shared/localization/locales/ro.json +1 -16
  77. package/shared/localization/locales/ru.json +1 -16
  78. package/shared/localization/locales/sk.json +1 -16
  79. package/shared/localization/locales/sl.json +1 -16
  80. package/shared/localization/locales/sr-Latn.json +1 -16
  81. package/shared/localization/locales/sr.json +1 -16
  82. package/shared/localization/locales/sv.json +1 -16
  83. package/shared/localization/locales/ta.json +1 -16
  84. package/shared/localization/locales/te.json +1 -16
  85. package/shared/localization/locales/th.json +1 -16
  86. package/shared/localization/locales/tr.json +1 -16
  87. package/shared/localization/locales/uk.json +1 -16
  88. package/shared/localization/locales/vi.json +1 -16
  89. package/shared/localization/locales/zh-HK.json +1 -16
  90. package/shared/localization/locales/zh-TW.json +1 -16
  91. package/shared/localization/locales/zh.json +1 -16
  92. package/tsconfig.json +1 -0
  93. package/types/config.d.ts +0 -1
  94. package/types/lhr/lhr.d.ts +0 -2
  95. package/core/audits/no-unload-listeners.d.ts +0 -16
  96. package/core/audits/no-unload-listeners.js +0 -86
  97. package/core/config/metrics-to-audits.d.ts +0 -19
  98. package/core/config/metrics-to-audits.js +0 -60
  99. package/core/gather/gatherers/global-listeners.d.ts +0 -27
  100. package/core/gather/gatherers/global-listeners.js +0 -108
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import * as Lantern from '../types/lantern.js';
8
+ import {Metric} from '../metric.js';
9
+ // TODO(15841): don't use LighthouseError
10
+ import {LighthouseError} from '../../lh-error.js';
11
+ import {FirstContentfulPaint} from './first-contentful-paint.js';
12
+
13
+ /** @typedef {import('../base-node.js').Node} Node */
14
+
15
+ class FirstMeaningfulPaint extends Metric {
16
+ /**
17
+ * @return {Lantern.Simulation.MetricCoefficients}
18
+ */
19
+ static get COEFFICIENTS() {
20
+ return {
21
+ intercept: 0,
22
+ optimistic: 0.5,
23
+ pessimistic: 0.5,
24
+ };
25
+ }
26
+
27
+ /**
28
+ * @param {Node} dependencyGraph
29
+ * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
30
+ * @return {Node}
31
+ */
32
+ static getOptimisticGraph(dependencyGraph, processedNavigation) {
33
+ const fmp = processedNavigation.timestamps.firstMeaningfulPaint;
34
+ if (!fmp) {
35
+ throw new LighthouseError(LighthouseError.errors.NO_FMP);
36
+ }
37
+ return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
38
+ cutoffTimestamp: fmp,
39
+ // See FirstContentfulPaint's getOptimisticGraph implementation for a longer description
40
+ // of why we exclude script initiated resources here.
41
+ treatNodeAsRenderBlocking: node =>
42
+ node.hasRenderBlockingPriority() && node.initiatorType !== 'script',
43
+ });
44
+ }
45
+
46
+ /**
47
+ * @param {Node} dependencyGraph
48
+ * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
49
+ * @return {Node}
50
+ */
51
+ static getPessimisticGraph(dependencyGraph, processedNavigation) {
52
+ const fmp = processedNavigation.timestamps.firstMeaningfulPaint;
53
+ if (!fmp) {
54
+ throw new LighthouseError(LighthouseError.errors.NO_FMP);
55
+ }
56
+
57
+ return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
58
+ cutoffTimestamp: fmp,
59
+ treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority(),
60
+ // For pessimistic FMP we'll include *all* layout nodes
61
+ additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),
62
+ });
63
+ }
64
+ }
65
+
66
+ export {FirstMeaningfulPaint};
@@ -0,0 +1,26 @@
1
+ export type Node = import('../base-node.js').Node;
2
+ export class Interactive extends Metric {
3
+ /**
4
+ * @param {Node} dependencyGraph
5
+ * @return {Node}
6
+ */
7
+ static getOptimisticGraph(dependencyGraph: Node): Node;
8
+ /**
9
+ * @param {Node} dependencyGraph
10
+ * @return {Node}
11
+ */
12
+ static getPessimisticGraph(dependencyGraph: Node): Node;
13
+ /**
14
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
15
+ * @param {import('../metric.js').Extras} extras
16
+ * @return {LH.Gatherer.Simulation.Result}
17
+ */
18
+ static getEstimateFromSimulation(simulationResult: LH.Gatherer.Simulation.Result, extras: import('../metric.js').Extras): LH.Gatherer.Simulation.Result;
19
+ /**
20
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
21
+ * @return {number}
22
+ */
23
+ static getLastLongTaskEndTime(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], duration?: number): number;
24
+ }
25
+ import { Metric } from '../metric.js';
26
+ //# sourceMappingURL=interactive.d.ts.map
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import * as Lantern from '../types/lantern.js';
8
+ import {Metric} from '../metric.js';
9
+ import {BaseNode} from '../base-node.js';
10
+ import {NetworkRequestTypes} from '../lantern.js';
11
+
12
+ /** @typedef {import('../base-node.js').Node} Node */
13
+
14
+ // Any CPU task of 20 ms or more will end up being a critical long task on mobile
15
+ const CRITICAL_LONG_TASK_THRESHOLD = 20;
16
+
17
+ class Interactive extends Metric {
18
+ /**
19
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
20
+ */
21
+ static get COEFFICIENTS() {
22
+ return {
23
+ intercept: 0,
24
+ optimistic: 0.5,
25
+ pessimistic: 0.5,
26
+ };
27
+ }
28
+
29
+ /**
30
+ * @param {Node} dependencyGraph
31
+ * @return {Node}
32
+ */
33
+ static getOptimisticGraph(dependencyGraph) {
34
+ // Adjust the critical long task threshold for microseconds
35
+ const minimumCpuTaskDuration = CRITICAL_LONG_TASK_THRESHOLD * 1000;
36
+
37
+ return dependencyGraph.cloneWithRelationships(node => {
38
+ // Include everything that might be a long task
39
+ if (node.type === BaseNode.TYPES.CPU) {
40
+ return node.event.dur > minimumCpuTaskDuration;
41
+ }
42
+
43
+ // Include all scripts and high priority requests, exclude all images
44
+ const isImage = node.record.resourceType === NetworkRequestTypes.Image;
45
+ const isScript = node.record.resourceType === NetworkRequestTypes.Script;
46
+ return (
47
+ !isImage &&
48
+ (isScript ||
49
+ node.record.priority === 'High' ||
50
+ node.record.priority === 'VeryHigh')
51
+ );
52
+ });
53
+ }
54
+
55
+ /**
56
+ * @param {Node} dependencyGraph
57
+ * @return {Node}
58
+ */
59
+ static getPessimisticGraph(dependencyGraph) {
60
+ return dependencyGraph;
61
+ }
62
+
63
+ /**
64
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
65
+ * @param {import('../metric.js').Extras} extras
66
+ * @return {LH.Gatherer.Simulation.Result}
67
+ */
68
+ static getEstimateFromSimulation(simulationResult, extras) {
69
+ if (!extras.fmpResult) throw new Error('missing fmpResult');
70
+
71
+ const lastTaskAt = Interactive.getLastLongTaskEndTime(simulationResult.nodeTimings);
72
+ const minimumTime = extras.optimistic
73
+ ? extras.fmpResult.optimisticEstimate.timeInMs
74
+ : extras.fmpResult.pessimisticEstimate.timeInMs;
75
+ return {
76
+ timeInMs: Math.max(minimumTime, lastTaskAt),
77
+ nodeTimings: simulationResult.nodeTimings,
78
+ };
79
+ }
80
+
81
+ /**
82
+ * @param {Lantern.Simulation.MetricComputationDataInput} data
83
+ * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
84
+ * @return {Promise<LH.Artifacts.LanternMetric>}
85
+ */
86
+ static async compute(data, extras) {
87
+ const fmpResult = extras?.fmpResult;
88
+ if (!fmpResult) {
89
+ throw new Error('FMP is required to calculate the Interactive metric');
90
+ }
91
+
92
+ const metricResult = await super.compute(data, extras);
93
+ metricResult.timing = Math.max(metricResult.timing, fmpResult.timing);
94
+ return metricResult;
95
+ }
96
+
97
+ /**
98
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
99
+ * @return {number}
100
+ */
101
+ static getLastLongTaskEndTime(nodeTimings, duration = 50) {
102
+ return Array.from(nodeTimings.entries())
103
+ .filter(([node, timing]) => {
104
+ if (node.type !== BaseNode.TYPES.CPU) return false;
105
+ return timing.duration > duration;
106
+ })
107
+ .map(([_, timing]) => timing.endTime)
108
+ .reduce((max, x) => Math.max(max || 0, x || 0), 0);
109
+ }
110
+ }
111
+
112
+ export {Interactive};
@@ -0,0 +1,19 @@
1
+ export type Node = import('../base-node.js').Node;
2
+ /** @typedef {import('../base-node.js').Node} Node */
3
+ export class LargestContentfulPaint extends Metric {
4
+ /**
5
+ * Low priority image nodes are usually offscreen and very unlikely to be the
6
+ * resource that is required for LCP. Our LCP graphs include everything except for these images.
7
+ *
8
+ * @param {Node} node
9
+ * @return {boolean}
10
+ */
11
+ static isNotLowPriorityImageNode(node: Node): boolean;
12
+ /**
13
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
14
+ * @return {LH.Gatherer.Simulation.Result}
15
+ */
16
+ static getEstimateFromSimulation(simulationResult: LH.Gatherer.Simulation.Result): LH.Gatherer.Simulation.Result;
17
+ }
18
+ import { Metric } from '../metric.js';
19
+ //# sourceMappingURL=largest-contentful-paint.d.ts.map
@@ -0,0 +1,108 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import * as Lantern from '../types/lantern.js';
8
+ import {Metric} from '../metric.js';
9
+ import {LighthouseError} from '../../../lib/lh-error.js';
10
+ import {FirstContentfulPaint} from './first-contentful-paint.js';
11
+
12
+ /** @typedef {import('../base-node.js').Node} Node */
13
+
14
+ class LargestContentfulPaint extends Metric {
15
+ /**
16
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
17
+ */
18
+ static get COEFFICIENTS() {
19
+ return {
20
+ intercept: 0,
21
+ optimistic: 0.5,
22
+ pessimistic: 0.5,
23
+ };
24
+ }
25
+
26
+ /**
27
+ * Low priority image nodes are usually offscreen and very unlikely to be the
28
+ * resource that is required for LCP. Our LCP graphs include everything except for these images.
29
+ *
30
+ * @param {Node} node
31
+ * @return {boolean}
32
+ */
33
+ static isNotLowPriorityImageNode(node) {
34
+ if (node.type !== 'network') return true;
35
+ const isImage = node.record.resourceType === 'Image';
36
+ const isLowPriority = node.record.priority === 'Low' || node.record.priority === 'VeryLow';
37
+ return !isImage || !isLowPriority;
38
+ }
39
+
40
+ /**
41
+ * @param {Node} dependencyGraph
42
+ * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
43
+ * @return {Node}
44
+ */
45
+ static getOptimisticGraph(dependencyGraph, processedNavigation) {
46
+ const lcp = processedNavigation.timestamps.largestContentfulPaint;
47
+ if (!lcp) {
48
+ throw new LighthouseError(LighthouseError.errors.NO_LCP);
49
+ }
50
+
51
+ return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
52
+ cutoffTimestamp: lcp,
53
+ treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,
54
+ });
55
+ }
56
+
57
+ /**
58
+ * @param {Node} dependencyGraph
59
+ * @param {LH.Artifacts.ProcessedNavigation} processedNavigation
60
+ * @return {Node}
61
+ */
62
+ static getPessimisticGraph(dependencyGraph, processedNavigation) {
63
+ const lcp = processedNavigation.timestamps.largestContentfulPaint;
64
+ if (!lcp) {
65
+ throw new LighthouseError(LighthouseError.errors.NO_LCP);
66
+ }
67
+
68
+ return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
69
+ cutoffTimestamp: lcp,
70
+ treatNodeAsRenderBlocking: _ => true,
71
+ // For pessimistic LCP we'll include *all* layout nodes
72
+ additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),
73
+ });
74
+ }
75
+
76
+ /**
77
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
78
+ * @return {LH.Gatherer.Simulation.Result}
79
+ */
80
+ static getEstimateFromSimulation(simulationResult) {
81
+ const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())
82
+ .filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))
83
+ .map(entry => entry[1].endTime);
84
+
85
+ return {
86
+ timeInMs: Math.max(...nodeTimesNotOffscreenImages),
87
+ nodeTimings: simulationResult.nodeTimings,
88
+ };
89
+ }
90
+
91
+ /**
92
+ * @param {Lantern.Simulation.MetricComputationDataInput} data
93
+ * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
94
+ * @return {Promise<LH.Artifacts.LanternMetric>}
95
+ */
96
+ static async compute(data, extras) {
97
+ const fcpResult = extras?.fcpResult;
98
+ if (!fcpResult) {
99
+ throw new Error('FCP is required to calculate the LCP metric');
100
+ }
101
+
102
+ const metricResult = await super.compute(data, extras);
103
+ metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
104
+ return metricResult;
105
+ }
106
+ }
107
+
108
+ export {LargestContentfulPaint};
@@ -0,0 +1,30 @@
1
+ export type Node = import('../base-node.js').Node;
2
+ /** @typedef {import('../base-node.js').Node} Node */
3
+ export class MaxPotentialFID extends Metric {
4
+ /**
5
+ * @param {Node} dependencyGraph
6
+ * @return {Node}
7
+ */
8
+ static getOptimisticGraph(dependencyGraph: Node): Node;
9
+ /**
10
+ * @param {Node} dependencyGraph
11
+ * @return {Node}
12
+ */
13
+ static getPessimisticGraph(dependencyGraph: Node): Node;
14
+ /**
15
+ * @param {LH.Gatherer.Simulation.Result} simulation
16
+ * @param {import('../metric.js').Extras} extras
17
+ * @return {LH.Gatherer.Simulation.Result}
18
+ */
19
+ static getEstimateFromSimulation(simulation: LH.Gatherer.Simulation.Result, extras: import('../metric.js').Extras): LH.Gatherer.Simulation.Result;
20
+ /**
21
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
22
+ * @param {number} fcpTimeInMs
23
+ * @return {Array<{duration: number}>}
24
+ */
25
+ static getTimingsAfterFCP(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], fcpTimeInMs: number): Array<{
26
+ duration: number;
27
+ }>;
28
+ }
29
+ import { Metric } from '../metric.js';
30
+ //# sourceMappingURL=max-potential-fid.d.ts.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import * as Lantern from '../types/lantern.js';
8
+ import {Metric} from '../metric.js';
9
+ import {BaseNode} from '../base-node.js';
10
+
11
+ /** @typedef {import('../base-node.js').Node} Node */
12
+
13
+ class MaxPotentialFID extends Metric {
14
+ /**
15
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
16
+ */
17
+ static get COEFFICIENTS() {
18
+ return {
19
+ intercept: 0,
20
+ optimistic: 0.5,
21
+ pessimistic: 0.5,
22
+ };
23
+ }
24
+
25
+ /**
26
+ * @param {Node} dependencyGraph
27
+ * @return {Node}
28
+ */
29
+ static getOptimisticGraph(dependencyGraph) {
30
+ return dependencyGraph;
31
+ }
32
+
33
+ /**
34
+ * @param {Node} dependencyGraph
35
+ * @return {Node}
36
+ */
37
+ static getPessimisticGraph(dependencyGraph) {
38
+ return dependencyGraph;
39
+ }
40
+
41
+ /**
42
+ * @param {LH.Gatherer.Simulation.Result} simulation
43
+ * @param {import('../metric.js').Extras} extras
44
+ * @return {LH.Gatherer.Simulation.Result}
45
+ */
46
+ static getEstimateFromSimulation(simulation, extras) {
47
+ if (!extras.fcpResult) throw new Error('missing fcpResult');
48
+
49
+ // Intentionally use the opposite FCP estimate, a more pessimistic FCP means that more tasks
50
+ // are excluded from the FID computation, so a higher FCP means lower FID for same work.
51
+ const fcpTimeInMs = extras.optimistic
52
+ ? extras.fcpResult.pessimisticEstimate.timeInMs
53
+ : extras.fcpResult.optimisticEstimate.timeInMs;
54
+
55
+ const timings = MaxPotentialFID.getTimingsAfterFCP(
56
+ simulation.nodeTimings,
57
+ fcpTimeInMs
58
+ );
59
+
60
+ return {
61
+ timeInMs: Math.max(...timings.map(timing => timing.duration), 16),
62
+ nodeTimings: simulation.nodeTimings,
63
+ };
64
+ }
65
+
66
+ /**
67
+ * @param {Lantern.Simulation.MetricComputationDataInput} data
68
+ * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
69
+ * @return {Promise<LH.Artifacts.LanternMetric>}
70
+ */
71
+ static compute(data, extras) {
72
+ const fcpResult = extras?.fcpResult;
73
+ if (!fcpResult) {
74
+ throw new Error('FCP is required to calculate the Max Potential FID metric');
75
+ }
76
+
77
+ return super.compute(data, extras);
78
+ }
79
+
80
+ /**
81
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
82
+ * @param {number} fcpTimeInMs
83
+ * @return {Array<{duration: number}>}
84
+ */
85
+ static getTimingsAfterFCP(nodeTimings, fcpTimeInMs) {
86
+ return Array.from(nodeTimings.entries())
87
+ .filter(([node, timing]) => node.type === BaseNode.TYPES.CPU && timing.endTime > fcpTimeInMs)
88
+ .map(([_, timing]) => timing);
89
+ }
90
+ }
91
+
92
+ export {MaxPotentialFID};
@@ -0,0 +1,38 @@
1
+ export type Node = import('../base-node.js').Node;
2
+ /** @typedef {import('../base-node.js').Node} Node */
3
+ export class SpeedIndex extends Metric {
4
+ /**
5
+ * @param {Node} dependencyGraph
6
+ * @return {Node}
7
+ */
8
+ static getOptimisticGraph(dependencyGraph: Node): Node;
9
+ /**
10
+ * @param {Node} dependencyGraph
11
+ * @return {Node}
12
+ */
13
+ static getPessimisticGraph(dependencyGraph: Node): Node;
14
+ /**
15
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
16
+ * @param {import('../metric.js').Extras} extras
17
+ * @return {LH.Gatherer.Simulation.Result}
18
+ */
19
+ static getEstimateFromSimulation(simulationResult: LH.Gatherer.Simulation.Result, extras: import('../metric.js').Extras): LH.Gatherer.Simulation.Result;
20
+ /**
21
+ * Approximate speed index using layout events from the simulated node timings.
22
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
23
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
24
+ *
25
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
26
+ *
27
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
28
+ * different methods. Read more in the evaluation doc.
29
+ *
30
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
31
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
32
+ * @param {number} fcpTimeInMs
33
+ * @return {number}
34
+ */
35
+ static computeLayoutBasedSpeedIndex(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], fcpTimeInMs: number): number;
36
+ }
37
+ import { Metric } from '../metric.js';
38
+ //# sourceMappingURL=speed-index.d.ts.map
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import * as Lantern from '../types/lantern.js';
8
+ import {Metric} from '../metric.js';
9
+ import {BaseNode} from '../base-node.js';
10
+ // TODO(15841): move this default config value into lib/lantern
11
+ import {throttling as defaultThrottling} from '../../../config/constants.js';
12
+
13
+ /** @typedef {import('../base-node.js').Node} Node */
14
+
15
+ class SpeedIndex extends Metric {
16
+ /**
17
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
18
+ */
19
+ static get COEFFICIENTS() {
20
+ return {
21
+ // Negative intercept is OK because estimate is Math.max(FCP, Speed Index) and
22
+ // the optimistic estimate is based on the real observed speed index rather than a real
23
+ // lantern graph.
24
+ intercept: -250,
25
+ optimistic: 1.4,
26
+ pessimistic: 0.65,
27
+ };
28
+ }
29
+
30
+ /**
31
+ * @param {number} rttMs
32
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
33
+ */
34
+ static getScaledCoefficients(rttMs) { // eslint-disable-line no-unused-vars
35
+ // We want to scale our default coefficients based on the speed of the connection.
36
+ // We will linearly interpolate coefficients for the passed-in rttMs based on two pre-determined points:
37
+ // 1. Baseline point of 30 ms RTT where Speed Index should be a ~50/50 blend of optimistic/pessimistic.
38
+ // 30 ms was based on a typical home WiFi connection's actual RTT.
39
+ // Coefficients here follow from the fact that the optimistic estimate should be very close
40
+ // to reality at this connection speed and the pessimistic estimate compensates for minor
41
+ // connection speed differences.
42
+ // 2. Default throttled point of 150 ms RTT where the default coefficients have been determined to be most accurate.
43
+ // Coefficients here were determined through thorough analysis and linear regression on the
44
+ // lantern test data set. See core/scripts/test-lantern.sh for more detail.
45
+ // While the coefficients haven't been analyzed at the interpolated points, it's our current best effort.
46
+ const defaultCoefficients = this.COEFFICIENTS;
47
+ const defaultRttExcess = defaultThrottling.mobileSlow4G.rttMs - 30;
48
+ const multiplier = Math.max((rttMs - 30) / defaultRttExcess, 0);
49
+
50
+ return {
51
+ intercept: defaultCoefficients.intercept * multiplier,
52
+ optimistic: 0.5 + (defaultCoefficients.optimistic - 0.5) * multiplier,
53
+ pessimistic: 0.5 + (defaultCoefficients.pessimistic - 0.5) * multiplier,
54
+ };
55
+ }
56
+
57
+ /**
58
+ * @param {Node} dependencyGraph
59
+ * @return {Node}
60
+ */
61
+ static getOptimisticGraph(dependencyGraph) {
62
+ return dependencyGraph;
63
+ }
64
+
65
+ /**
66
+ * @param {Node} dependencyGraph
67
+ * @return {Node}
68
+ */
69
+ static getPessimisticGraph(dependencyGraph) {
70
+ return dependencyGraph;
71
+ }
72
+
73
+ /**
74
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
75
+ * @param {import('../metric.js').Extras} extras
76
+ * @return {LH.Gatherer.Simulation.Result}
77
+ */
78
+ static getEstimateFromSimulation(simulationResult, extras) {
79
+ if (!extras.fcpResult) throw new Error('missing fcpResult');
80
+ if (!extras.speedline) throw new Error('missing speedline');
81
+
82
+ const fcpTimeInMs = extras.fcpResult.pessimisticEstimate.timeInMs;
83
+ const estimate = extras.optimistic
84
+ ? extras.speedline.speedIndex
85
+ : SpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTimings, fcpTimeInMs);
86
+ return {
87
+ timeInMs: estimate,
88
+ nodeTimings: simulationResult.nodeTimings,
89
+ };
90
+ }
91
+
92
+ /**
93
+ * @param {Lantern.Simulation.MetricComputationDataInput} data
94
+ * @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
95
+ * @return {Promise<LH.Artifacts.LanternMetric>}
96
+ */
97
+ static async compute(data, extras) {
98
+ const fcpResult = extras?.fcpResult;
99
+ if (!fcpResult) {
100
+ throw new Error('FCP is required to calculate the SpeedIndex metric');
101
+ }
102
+
103
+ const metricResult = await super.compute(data, extras);
104
+ metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
105
+ return metricResult;
106
+ }
107
+
108
+ /**
109
+ * Approximate speed index using layout events from the simulated node timings.
110
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
111
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
112
+ *
113
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
114
+ *
115
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
116
+ * different methods. Read more in the evaluation doc.
117
+ *
118
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
119
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
120
+ * @param {number} fcpTimeInMs
121
+ * @return {number}
122
+ */
123
+ static computeLayoutBasedSpeedIndex(nodeTimings, fcpTimeInMs) {
124
+ /** @type {Array<{time: number, weight: number}>} */
125
+ const layoutWeights = [];
126
+ for (const [node, timing] of nodeTimings.entries()) {
127
+ if (node.type !== BaseNode.TYPES.CPU) continue;
128
+
129
+ if (node.childEvents.some(x => x.name === 'Layout')) {
130
+ const timingWeight = Math.max(Math.log2(timing.endTime - timing.startTime), 0);
131
+ layoutWeights.push({time: timing.endTime, weight: timingWeight});
132
+ }
133
+ }
134
+
135
+ const totalWeightedTime = layoutWeights
136
+ .map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs))
137
+ .reduce((a, b) => a + b, 0);
138
+ const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);
139
+
140
+ if (!totalWeight) return fcpTimeInMs;
141
+ return totalWeightedTime / totalWeight;
142
+ }
143
+ }
144
+
145
+ export {SpeedIndex};
@@ -0,0 +1,31 @@
1
+ export type Node = import('../base-node.js').Node;
2
+ /** @typedef {import('../base-node.js').Node} Node */
3
+ export class TotalBlockingTime extends Metric {
4
+ /**
5
+ * @param {Node} dependencyGraph
6
+ * @return {Node}
7
+ */
8
+ static getOptimisticGraph(dependencyGraph: Node): Node;
9
+ /**
10
+ * @param {Node} dependencyGraph
11
+ * @return {Node}
12
+ */
13
+ static getPessimisticGraph(dependencyGraph: Node): Node;
14
+ /**
15
+ * @param {LH.Gatherer.Simulation.Result} simulation
16
+ * @param {import('../metric.js').Extras} extras
17
+ * @return {LH.Gatherer.Simulation.Result}
18
+ */
19
+ static getEstimateFromSimulation(simulation: LH.Gatherer.Simulation.Result, extras: import('../metric.js').Extras): LH.Gatherer.Simulation.Result;
20
+ /**
21
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
22
+ * @param {number} minDurationMs
23
+ */
24
+ static getTopLevelEvents(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], minDurationMs: number): {
25
+ start: number;
26
+ end: number;
27
+ duration: number;
28
+ }[];
29
+ }
30
+ import { Metric } from '../metric.js';
31
+ //# sourceMappingURL=total-blocking-time.d.ts.map