lighthouse 11.7.0-dev.20240408 → 11.7.1

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 (141) hide show
  1. package/CONTRIBUTING.md +2 -2
  2. package/cli/test/smokehouse/core-tests.js +2 -0
  3. package/core/audits/accessibility/duplicate-id-active.d.ts +10 -0
  4. package/core/audits/accessibility/duplicate-id-active.js +42 -0
  5. package/core/audits/accessibility/target-size.js +1 -0
  6. package/core/audits/byte-efficiency/byte-efficiency-audit.d.ts +16 -0
  7. package/core/audits/byte-efficiency/byte-efficiency-audit.js +38 -1
  8. package/core/audits/byte-efficiency/offscreen-images.d.ts +11 -0
  9. package/core/audits/byte-efficiency/offscreen-images.js +15 -0
  10. package/core/audits/dobetterweb/uses-http2.d.ts +13 -0
  11. package/core/audits/dobetterweb/uses-http2.js +34 -2
  12. package/core/audits/layout-shift-elements.d.ts +16 -0
  13. package/core/audits/layout-shift-elements.js +101 -0
  14. package/core/audits/no-unload-listeners.d.ts +16 -0
  15. package/core/audits/no-unload-listeners.js +86 -0
  16. package/core/audits/preload-fonts.d.ts +5 -1
  17. package/core/audits/preload-fonts.js +10 -1
  18. package/core/audits/script-elements-test-audit.d.ts +14 -0
  19. package/core/audits/script-elements-test-audit.js +29 -0
  20. package/core/audits/seo/is-crawlable.d.ts +1 -2
  21. package/core/audits/seo/plugins.d.ts +15 -0
  22. package/core/audits/seo/plugins.js +150 -0
  23. package/core/audits/seo/tap-targets.d.ts +50 -0
  24. package/core/audits/seo/tap-targets.js +352 -0
  25. package/core/audits/uses-rel-preload.d.ts +5 -1
  26. package/core/audits/uses-rel-preload.js +11 -1
  27. package/core/audits/work-during-interaction.d.ts +2 -2
  28. package/core/audits/work-during-interaction.js +2 -2
  29. package/core/computed/js-bundles.d.ts +1 -1
  30. package/core/computed/metrics/lantern-first-contentful-paint.d.ts +82 -13
  31. package/core/computed/metrics/lantern-first-contentful-paint.js +178 -15
  32. package/core/computed/metrics/lantern-first-meaningful-paint.d.ts +12 -13
  33. package/core/computed/metrics/lantern-first-meaningful-paint.js +49 -10
  34. package/core/computed/metrics/lantern-interactive.d.ts +21 -13
  35. package/core/computed/metrics/lantern-interactive.js +84 -11
  36. package/core/computed/metrics/lantern-largest-contentful-paint.d.ts +25 -13
  37. package/core/computed/metrics/lantern-largest-contentful-paint.js +80 -12
  38. package/core/computed/metrics/lantern-max-potential-fid.d.ts +24 -13
  39. package/core/computed/metrics/lantern-max-potential-fid.js +64 -11
  40. package/core/computed/metrics/lantern-metric.d.ts +18 -9
  41. package/core/computed/metrics/lantern-metric.js +31 -13
  42. package/core/computed/metrics/lantern-speed-index.d.ts +32 -13
  43. package/core/computed/metrics/lantern-speed-index.js +116 -12
  44. package/core/computed/metrics/lantern-total-blocking-time.d.ts +25 -13
  45. package/core/computed/metrics/lantern-total-blocking-time.js +94 -10
  46. package/core/computed/metrics/metric.js +3 -1
  47. package/core/computed/module-duplication.d.ts +1 -1
  48. package/core/computed/page-dependency-graph.js +1 -2
  49. package/core/config/default-config.js +74 -46
  50. package/core/config/experimental-config.js +0 -11
  51. package/core/config/metrics-to-audits.d.ts +19 -0
  52. package/core/config/metrics-to-audits.js +62 -0
  53. package/core/gather/gatherers/accessibility.js +3 -1
  54. package/core/gather/gatherers/global-listeners.d.ts +27 -0
  55. package/core/gather/gatherers/global-listeners.js +108 -0
  56. package/core/gather/gatherers/script-elements.d.ts +21 -0
  57. package/core/gather/gatherers/script-elements.js +100 -0
  58. package/core/gather/gatherers/seo/embedded-content.d.ts +10 -0
  59. package/core/gather/gatherers/seo/embedded-content.js +63 -0
  60. package/core/gather/gatherers/seo/tap-targets.d.ts +21 -0
  61. package/core/gather/gatherers/seo/tap-targets.js +389 -0
  62. package/core/gather/gatherers/trace-elements.d.ts +10 -0
  63. package/core/gather/gatherers/trace-elements.js +19 -0
  64. package/core/lib/lantern/page-dependency-graph.d.ts +4 -4
  65. package/core/lib/lantern/page-dependency-graph.js +5 -5
  66. package/core/lib/lighthouse-compatibility.js +10 -53
  67. package/dist/report/bundle.esm.js +1 -1
  68. package/dist/report/flow.js +14 -14
  69. package/dist/report/standalone.js +1 -1
  70. package/flow-report/src/summary/category.tsx +12 -10
  71. package/package.json +1 -1
  72. package/report/renderer/performance-category-renderer.d.ts +7 -0
  73. package/report/renderer/performance-category-renderer.js +11 -1
  74. package/report/renderer/report-utils.js +10 -13
  75. package/shared/localization/locales/ar-XB.json +64 -1
  76. package/shared/localization/locales/ar.json +64 -1
  77. package/shared/localization/locales/bg.json +64 -1
  78. package/shared/localization/locales/ca.json +64 -1
  79. package/shared/localization/locales/cs.json +64 -1
  80. package/shared/localization/locales/da.json +64 -1
  81. package/shared/localization/locales/de.json +64 -1
  82. package/shared/localization/locales/el.json +64 -1
  83. package/shared/localization/locales/en-GB.json +64 -1
  84. package/shared/localization/locales/en-US.json +65 -2
  85. package/shared/localization/locales/en-XA.json +64 -1
  86. package/shared/localization/locales/en-XL.json +65 -2
  87. package/shared/localization/locales/es-419.json +64 -1
  88. package/shared/localization/locales/es.json +64 -1
  89. package/shared/localization/locales/fi.json +64 -1
  90. package/shared/localization/locales/fil.json +64 -1
  91. package/shared/localization/locales/fr.json +64 -1
  92. package/shared/localization/locales/he.json +64 -1
  93. package/shared/localization/locales/hi.json +64 -1
  94. package/shared/localization/locales/hr.json +64 -1
  95. package/shared/localization/locales/hu.json +64 -1
  96. package/shared/localization/locales/id.json +64 -1
  97. package/shared/localization/locales/it.json +64 -1
  98. package/shared/localization/locales/ja.json +64 -1
  99. package/shared/localization/locales/ko.json +64 -1
  100. package/shared/localization/locales/lt.json +64 -1
  101. package/shared/localization/locales/lv.json +64 -1
  102. package/shared/localization/locales/nl.json +64 -1
  103. package/shared/localization/locales/no.json +64 -1
  104. package/shared/localization/locales/pl.json +64 -1
  105. package/shared/localization/locales/pt-PT.json +64 -1
  106. package/shared/localization/locales/pt.json +64 -1
  107. package/shared/localization/locales/ro.json +64 -1
  108. package/shared/localization/locales/ru.json +64 -1
  109. package/shared/localization/locales/sk.json +64 -1
  110. package/shared/localization/locales/sl.json +64 -1
  111. package/shared/localization/locales/sr-Latn.json +64 -1
  112. package/shared/localization/locales/sr.json +64 -1
  113. package/shared/localization/locales/sv.json +64 -1
  114. package/shared/localization/locales/ta.json +64 -1
  115. package/shared/localization/locales/te.json +64 -1
  116. package/shared/localization/locales/th.json +64 -1
  117. package/shared/localization/locales/tr.json +64 -1
  118. package/shared/localization/locales/uk.json +64 -1
  119. package/shared/localization/locales/vi.json +64 -1
  120. package/shared/localization/locales/zh-HK.json +64 -1
  121. package/shared/localization/locales/zh-TW.json +64 -1
  122. package/shared/localization/locales/zh.json +64 -1
  123. package/tsconfig.json +0 -1
  124. package/types/artifacts.d.ts +17 -3
  125. package/types/config.d.ts +1 -0
  126. package/types/lhr/audit-details.d.ts +4 -9
  127. package/types/lhr/lhr.d.ts +2 -0
  128. package/core/lib/lantern/metrics/first-contentful-paint.d.ts +0 -79
  129. package/core/lib/lantern/metrics/first-contentful-paint.js +0 -200
  130. package/core/lib/lantern/metrics/first-meaningful-paint.d.ts +0 -6
  131. package/core/lib/lantern/metrics/first-meaningful-paint.js +0 -66
  132. package/core/lib/lantern/metrics/interactive.d.ts +0 -26
  133. package/core/lib/lantern/metrics/interactive.js +0 -112
  134. package/core/lib/lantern/metrics/largest-contentful-paint.d.ts +0 -19
  135. package/core/lib/lantern/metrics/largest-contentful-paint.js +0 -108
  136. package/core/lib/lantern/metrics/max-potential-fid.d.ts +0 -30
  137. package/core/lib/lantern/metrics/max-potential-fid.js +0 -92
  138. package/core/lib/lantern/metrics/speed-index.d.ts +0 -38
  139. package/core/lib/lantern/metrics/speed-index.js +0 -145
  140. package/core/lib/lantern/metrics/total-blocking-time.d.ts +0 -31
  141. package/core/lib/lantern/metrics/total-blocking-time.js +0 -128
@@ -1,25 +1,91 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2018 Google LLC
3
+ * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
7
  import {makeComputedArtifact} from '../computed-artifact.js';
8
- import {LargestContentfulPaint} from '../../lib/lantern/metrics/largest-contentful-paint.js';
9
- import {getComputationDataParams} from './lantern-metric.js';
8
+ import {LanternMetric} from './lantern-metric.js';
9
+ import {LighthouseError} from '../../lib/lh-error.js';
10
10
  import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';
11
11
 
12
- /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
12
+ /** @typedef {import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */
13
13
 
14
- class LanternLargestContentfulPaint extends LargestContentfulPaint {
14
+ class LanternLargestContentfulPaint extends LanternMetric {
15
15
  /**
16
- * @param {LH.Artifacts.MetricComputationDataInput} data
17
- * @param {LH.Artifacts.ComputedContext} context
18
- * @param {Omit<Extras, 'optimistic'>=} extras
19
- * @return {Promise<LH.Artifacts.LanternMetric>}
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}
20
44
  */
21
- static async computeMetricWithGraphs(data, context, extras) {
22
- return this.compute(await getComputationDataParams(data, context), extras);
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 LanternFirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
52
+ cutoffTimestamp: lcp,
53
+ treatNodeAsRenderBlocking: LanternLargestContentfulPaint.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 LanternFirstContentfulPaint.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 => LanternLargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))
83
+ .map(entry => entry[1].endTime);
84
+
85
+ return {
86
+ timeInMs: Math.max(...nodeTimesNotOffscreenImages),
87
+ nodeTimings: simulationResult.nodeTimings,
88
+ };
23
89
  }
24
90
 
25
91
  /**
@@ -29,7 +95,9 @@ class LanternLargestContentfulPaint extends LargestContentfulPaint {
29
95
  */
30
96
  static async compute_(data, context) {
31
97
  const fcpResult = await LanternFirstContentfulPaint.request(data, context);
32
- return this.computeMetricWithGraphs(data, context, {fcpResult});
98
+ const metricResult = await this.computeMetricWithGraphs(data, context);
99
+ metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
100
+ return metricResult;
33
101
  }
34
102
  }
35
103
 
@@ -1,25 +1,36 @@
1
1
  export { LanternMaxPotentialFIDComputed as LanternMaxPotentialFID };
2
- export type Extras = import('../../lib/lantern/metric.js').Extras;
2
+ export type Node = import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>;
3
3
  declare const LanternMaxPotentialFIDComputed: typeof LanternMaxPotentialFID & {
4
4
  request: (dependencies: import("../../index.js").Artifacts.MetricComputationDataInput, context: import("../../../types/utility-types.js").default.ImmutableObject<{
5
5
  computedCache: Map<string, import("../../lib/arbitrary-equality-map.js").ArbitraryEqualityMap>;
6
6
  }>) => Promise<import("../../index.js").Artifacts.LanternMetric>;
7
7
  };
8
- /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
9
- declare class LanternMaxPotentialFID extends MaxPotentialFID {
8
+ /** @typedef {import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */
9
+ declare class LanternMaxPotentialFID extends LanternMetric {
10
10
  /**
11
- * @param {LH.Artifacts.MetricComputationDataInput} data
12
- * @param {LH.Artifacts.ComputedContext} context
13
- * @param {Omit<Extras, 'optimistic'>=} extras
14
- * @return {Promise<LH.Artifacts.LanternMetric>}
11
+ * @param {Node} dependencyGraph
12
+ * @return {Node}
15
13
  */
16
- static computeMetricWithGraphs(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext, extras?: Omit<Extras, 'optimistic'> | undefined): Promise<LH.Artifacts.LanternMetric>;
14
+ static getOptimisticGraph(dependencyGraph: Node): Node;
17
15
  /**
18
- * @param {LH.Artifacts.MetricComputationDataInput} data
19
- * @param {LH.Artifacts.ComputedContext} context
20
- * @return {Promise<LH.Artifacts.LanternMetric>}
16
+ * @param {Node} dependencyGraph
17
+ * @return {Node}
21
18
  */
22
- static compute_(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext): Promise<LH.Artifacts.LanternMetric>;
19
+ static getPessimisticGraph(dependencyGraph: Node): Node;
20
+ /**
21
+ * @param {LH.Gatherer.Simulation.Result} simulation
22
+ * @param {import('../../lib/lantern/metric.js').Extras} extras
23
+ * @return {LH.Gatherer.Simulation.Result}
24
+ */
25
+ static getEstimateFromSimulation(simulation: LH.Gatherer.Simulation.Result, extras: import('../../lib/lantern/metric.js').Extras): LH.Gatherer.Simulation.Result;
26
+ /**
27
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
28
+ * @param {number} fcpTimeInMs
29
+ * @return {Array<{duration: number}>}
30
+ */
31
+ static getTimingsAfterFCP(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], fcpTimeInMs: number): Array<{
32
+ duration: number;
33
+ }>;
23
34
  }
24
- import { MaxPotentialFID } from '../../lib/lantern/metrics/max-potential-fid.js';
35
+ import { LanternMetric } from './lantern-metric.js';
25
36
  //# sourceMappingURL=lantern-max-potential-fid.d.ts.map
@@ -5,21 +5,63 @@
5
5
  */
6
6
 
7
7
  import {makeComputedArtifact} from '../computed-artifact.js';
8
- import {MaxPotentialFID} from '../../lib/lantern/metrics/max-potential-fid.js';
9
- import {getComputationDataParams} from './lantern-metric.js';
8
+ import {LanternMetric} from './lantern-metric.js';
9
+ import {BaseNode} from '../../lib/lantern/base-node.js';
10
10
  import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';
11
11
 
12
- /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
12
+ /** @typedef {import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */
13
13
 
14
- class LanternMaxPotentialFID extends MaxPotentialFID {
14
+ class LanternMaxPotentialFID extends LanternMetric {
15
15
  /**
16
- * @param {LH.Artifacts.MetricComputationDataInput} data
17
- * @param {LH.Artifacts.ComputedContext} context
18
- * @param {Omit<Extras, 'optimistic'>=} extras
19
- * @return {Promise<LH.Artifacts.LanternMetric>}
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
+ * @param {Node} dependencyGraph
28
+ * @return {Node}
29
+ */
30
+ static getOptimisticGraph(dependencyGraph) {
31
+ return dependencyGraph;
32
+ }
33
+
34
+ /**
35
+ * @param {Node} dependencyGraph
36
+ * @return {Node}
20
37
  */
21
- static async computeMetricWithGraphs(data, context, extras) {
22
- return this.compute(await getComputationDataParams(data, context), extras);
38
+ static getPessimisticGraph(dependencyGraph) {
39
+ return dependencyGraph;
40
+ }
41
+
42
+ /**
43
+ * @param {LH.Gatherer.Simulation.Result} simulation
44
+ * @param {import('../../lib/lantern/metric.js').Extras} extras
45
+ * @return {LH.Gatherer.Simulation.Result}
46
+ */
47
+ static getEstimateFromSimulation(simulation, extras) {
48
+ if (!extras.fcpResult) throw new Error('missing fcpResult');
49
+
50
+ // Intentionally use the opposite FCP estimate, a more pessimistic FCP means that more tasks
51
+ // are excluded from the FID computation, so a higher FCP means lower FID for same work.
52
+ const fcpTimeInMs = extras.optimistic
53
+ ? extras.fcpResult.pessimisticEstimate.timeInMs
54
+ : extras.fcpResult.optimisticEstimate.timeInMs;
55
+
56
+ const timings = LanternMaxPotentialFID.getTimingsAfterFCP(
57
+ simulation.nodeTimings,
58
+ fcpTimeInMs
59
+ );
60
+
61
+ return {
62
+ timeInMs: Math.max(...timings.map(timing => timing.duration), 16),
63
+ nodeTimings: simulation.nodeTimings,
64
+ };
23
65
  }
24
66
 
25
67
  /**
@@ -29,7 +71,18 @@ class LanternMaxPotentialFID extends MaxPotentialFID {
29
71
  */
30
72
  static async compute_(data, context) {
31
73
  const fcpResult = await LanternFirstContentfulPaint.request(data, context);
32
- return this.computeMetricWithGraphs(data, context, {fcpResult});
74
+ return super.computeMetricWithGraphs(data, context, {fcpResult});
75
+ }
76
+
77
+ /**
78
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
79
+ * @param {number} fcpTimeInMs
80
+ * @return {Array<{duration: number}>}
81
+ */
82
+ static getTimingsAfterFCP(nodeTimings, fcpTimeInMs) {
83
+ return Array.from(nodeTimings.entries())
84
+ .filter(([node, timing]) => node.type === BaseNode.TYPES.CPU && timing.endTime > fcpTimeInMs)
85
+ .map(([_, timing]) => timing);
33
86
  }
34
87
  }
35
88
 
@@ -1,10 +1,19 @@
1
- /**
2
- * @param {LH.Artifacts.MetricComputationDataInput} data
3
- * @param {LH.Artifacts.ComputedContext} context
4
- */
5
- export function getComputationDataParams(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext): Promise<{
6
- simulator: import("../../lib/lantern/simulator/simulator.js").Simulator<any>;
7
- graph: import("../page-dependency-graph.js").Node;
8
- processedNavigation: import("../../index.js").Artifacts.ProcessedNavigation;
9
- }>;
1
+ export type Extras = import('../../lib/lantern/metric.js').Extras;
2
+ /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
3
+ export class LanternMetric extends Metric {
4
+ /**
5
+ * @param {LH.Artifacts.MetricComputationDataInput} data
6
+ * @param {LH.Artifacts.ComputedContext} context
7
+ * @param {Omit<Extras, 'optimistic'>=} extras
8
+ * @return {Promise<LH.Artifacts.LanternMetric>}
9
+ */
10
+ static computeMetricWithGraphs(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext, extras?: Omit<Extras, 'optimistic'> | undefined): Promise<LH.Artifacts.LanternMetric>;
11
+ /**
12
+ * @param {LH.Artifacts.MetricComputationDataInput} data
13
+ * @param {LH.Artifacts.ComputedContext} context
14
+ * @return {Promise<LH.Artifacts.LanternMetric>}
15
+ */
16
+ static compute_(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext): Promise<LH.Artifacts.LanternMetric>;
17
+ }
18
+ import { Metric } from '../../lib/lantern/metric.js';
10
19
  //# sourceMappingURL=lantern-metric.d.ts.map
@@ -4,24 +4,42 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
+ import {Metric} from '../../lib/lantern/metric.js';
7
8
  import {LoadSimulator} from '../load-simulator.js';
8
9
  import {PageDependencyGraph} from '../page-dependency-graph.js';
9
10
  import {ProcessedNavigation} from '../processed-navigation.js';
10
11
 
11
- /**
12
- * @param {LH.Artifacts.MetricComputationDataInput} data
13
- * @param {LH.Artifacts.ComputedContext} context
14
- */
15
- async function getComputationDataParams(data, context) {
16
- if (data.gatherContext.gatherMode !== 'navigation') {
17
- throw new Error(`Lantern metrics can only be computed on navigations`);
18
- }
12
+ /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
13
+
14
+ class LanternMetric extends Metric {
15
+ /**
16
+ * @param {LH.Artifacts.MetricComputationDataInput} data
17
+ * @param {LH.Artifacts.ComputedContext} context
18
+ * @param {Omit<Extras, 'optimistic'>=} extras
19
+ * @return {Promise<LH.Artifacts.LanternMetric>}
20
+ */
21
+ static async computeMetricWithGraphs(data, context, extras) {
22
+ // TODO: remove this fallback when lighthouse-pub-ads plugin can update.
23
+ const gatherContext = data.gatherContext || {gatherMode: 'navigation'};
24
+ if (gatherContext.gatherMode !== 'navigation') {
25
+ throw new Error(`Lantern metrics can only be computed on navigations`);
26
+ }
19
27
 
20
- const graph = await PageDependencyGraph.request(data, context);
21
- const processedNavigation = await ProcessedNavigation.request(data.trace, context);
22
- const simulator = data.simulator || (await LoadSimulator.request(data, context));
28
+ const graph = await PageDependencyGraph.request(data, context);
29
+ const processedNavigation = await ProcessedNavigation.request(data.trace, context);
30
+ const simulator = data.simulator || (await LoadSimulator.request(data, context));
23
31
 
24
- return {simulator, graph, processedNavigation};
32
+ return this.compute({simulator, graph, processedNavigation}, extras);
33
+ }
34
+
35
+ /**
36
+ * @param {LH.Artifacts.MetricComputationDataInput} data
37
+ * @param {LH.Artifacts.ComputedContext} context
38
+ * @return {Promise<LH.Artifacts.LanternMetric>}
39
+ */
40
+ static async compute_(data, context) {
41
+ return this.computeMetricWithGraphs(data, context);
42
+ }
25
43
  }
26
44
 
27
- export {getComputationDataParams};
45
+ export {LanternMetric};
@@ -1,25 +1,44 @@
1
1
  export { LanternSpeedIndexComputed as LanternSpeedIndex };
2
- export type Extras = import('../../lib/lantern/metric.js').Extras;
2
+ export type Node = import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>;
3
3
  declare const LanternSpeedIndexComputed: typeof LanternSpeedIndex & {
4
4
  request: (dependencies: import("../../index.js").Artifacts.MetricComputationDataInput, context: import("../../../types/utility-types.js").default.ImmutableObject<{
5
5
  computedCache: Map<string, import("../../lib/arbitrary-equality-map.js").ArbitraryEqualityMap>;
6
6
  }>) => Promise<import("../../index.js").Artifacts.LanternMetric>;
7
7
  };
8
- /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
9
- declare class LanternSpeedIndex extends SpeedIndex {
8
+ /** @typedef {import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */
9
+ declare class LanternSpeedIndex extends LanternMetric {
10
10
  /**
11
- * @param {LH.Artifacts.MetricComputationDataInput} data
12
- * @param {LH.Artifacts.ComputedContext} context
13
- * @param {Omit<Extras, 'optimistic'>=} extras
14
- * @return {Promise<LH.Artifacts.LanternMetric>}
11
+ * @param {Node} dependencyGraph
12
+ * @return {Node}
15
13
  */
16
- static computeMetricWithGraphs(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext, extras?: Omit<Extras, 'optimistic'> | undefined): Promise<LH.Artifacts.LanternMetric>;
14
+ static getOptimisticGraph(dependencyGraph: Node): Node;
17
15
  /**
18
- * @param {LH.Artifacts.MetricComputationDataInput} data
19
- * @param {LH.Artifacts.ComputedContext} context
20
- * @return {Promise<LH.Artifacts.LanternMetric>}
16
+ * @param {Node} dependencyGraph
17
+ * @return {Node}
21
18
  */
22
- static compute_(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext): Promise<LH.Artifacts.LanternMetric>;
19
+ static getPessimisticGraph(dependencyGraph: Node): Node;
20
+ /**
21
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
22
+ * @param {import('../../lib/lantern/metric.js').Extras} extras
23
+ * @return {LH.Gatherer.Simulation.Result}
24
+ */
25
+ static getEstimateFromSimulation(simulationResult: LH.Gatherer.Simulation.Result, extras: import('../../lib/lantern/metric.js').Extras): LH.Gatherer.Simulation.Result;
26
+ /**
27
+ * Approximate speed index using layout events from the simulated node timings.
28
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
29
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
30
+ *
31
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
32
+ *
33
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
34
+ * different methods. Read more in the evaluation doc.
35
+ *
36
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
37
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
38
+ * @param {number} fcpTimeInMs
39
+ * @return {number}
40
+ */
41
+ static computeLayoutBasedSpeedIndex(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], fcpTimeInMs: number): number;
23
42
  }
24
- import { SpeedIndex } from '../../lib/lantern/metrics/speed-index.js';
43
+ import { LanternMetric } from './lantern-metric.js';
25
44
  //# sourceMappingURL=lantern-speed-index.d.ts.map
@@ -5,22 +5,89 @@
5
5
  */
6
6
 
7
7
  import {makeComputedArtifact} from '../computed-artifact.js';
8
- import {getComputationDataParams} from './lantern-metric.js';
8
+ import {LanternMetric} from './lantern-metric.js';
9
+ import {BaseNode} from '../../lib/lantern/base-node.js';
9
10
  import {Speedline} from '../speedline.js';
10
11
  import {LanternFirstContentfulPaint} from './lantern-first-contentful-paint.js';
11
- import {SpeedIndex} from '../../lib/lantern/metrics/speed-index.js';
12
+ import {throttling as defaultThrottling} from '../../config/constants.js';
12
13
 
13
- /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
14
+ /** @typedef {import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */
14
15
 
15
- class LanternSpeedIndex extends SpeedIndex {
16
+ class LanternSpeedIndex extends LanternMetric {
16
17
  /**
17
- * @param {LH.Artifacts.MetricComputationDataInput} data
18
- * @param {LH.Artifacts.ComputedContext} context
19
- * @param {Omit<Extras, 'optimistic'>=} extras
20
- * @return {Promise<LH.Artifacts.LanternMetric>}
18
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
19
+ */
20
+ static get COEFFICIENTS() {
21
+ return {
22
+ // Negative intercept is OK because estimate is Math.max(FCP, Speed Index) and
23
+ // the optimistic estimate is based on the real observed speed index rather than a real
24
+ // lantern graph.
25
+ intercept: -250,
26
+ optimistic: 1.4,
27
+ pessimistic: 0.65,
28
+ };
29
+ }
30
+
31
+ /**
32
+ * @param {number} rttMs
33
+ * @return {LH.Gatherer.Simulation.MetricCoefficients}
34
+ */
35
+ static getScaledCoefficients(rttMs) { // eslint-disable-line no-unused-vars
36
+ // We want to scale our default coefficients based on the speed of the connection.
37
+ // We will linearly interpolate coefficients for the passed-in rttMs based on two pre-determined points:
38
+ // 1. Baseline point of 30 ms RTT where Speed Index should be a ~50/50 blend of optimistic/pessimistic.
39
+ // 30 ms was based on a typical home WiFi connection's actual RTT.
40
+ // Coefficients here follow from the fact that the optimistic estimate should be very close
41
+ // to reality at this connection speed and the pessimistic estimate compensates for minor
42
+ // connection speed differences.
43
+ // 2. Default throttled point of 150 ms RTT where the default coefficients have been determined to be most accurate.
44
+ // Coefficients here were determined through thorough analysis and linear regression on the
45
+ // lantern test data set. See core/scripts/test-lantern.sh for more detail.
46
+ // While the coefficients haven't been analyzed at the interpolated points, it's our current best effort.
47
+ const defaultCoefficients = this.COEFFICIENTS;
48
+ const defaultRttExcess = defaultThrottling.mobileSlow4G.rttMs - 30;
49
+ const multiplier = Math.max((rttMs - 30) / defaultRttExcess, 0);
50
+
51
+ return {
52
+ intercept: defaultCoefficients.intercept * multiplier,
53
+ optimistic: 0.5 + (defaultCoefficients.optimistic - 0.5) * multiplier,
54
+ pessimistic: 0.5 + (defaultCoefficients.pessimistic - 0.5) * multiplier,
55
+ };
56
+ }
57
+
58
+ /**
59
+ * @param {Node} dependencyGraph
60
+ * @return {Node}
61
+ */
62
+ static getOptimisticGraph(dependencyGraph) {
63
+ return dependencyGraph;
64
+ }
65
+
66
+ /**
67
+ * @param {Node} dependencyGraph
68
+ * @return {Node}
21
69
  */
22
- static async computeMetricWithGraphs(data, context, extras) {
23
- return this.compute(await getComputationDataParams(data, context), extras);
70
+ static getPessimisticGraph(dependencyGraph) {
71
+ return dependencyGraph;
72
+ }
73
+
74
+ /**
75
+ * @param {LH.Gatherer.Simulation.Result} simulationResult
76
+ * @param {import('../../lib/lantern/metric.js').Extras} extras
77
+ * @return {LH.Gatherer.Simulation.Result}
78
+ */
79
+ static getEstimateFromSimulation(simulationResult, extras) {
80
+ if (!extras.fcpResult) throw new Error('missing fcpResult');
81
+ if (!extras.speedline) throw new Error('missing speedline');
82
+
83
+ const fcpTimeInMs = extras.fcpResult.pessimisticEstimate.timeInMs;
84
+ const estimate = extras.optimistic
85
+ ? extras.speedline.speedIndex
86
+ : LanternSpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTimings, fcpTimeInMs);
87
+ return {
88
+ timeInMs: estimate,
89
+ nodeTimings: simulationResult.nodeTimings,
90
+ };
24
91
  }
25
92
 
26
93
  /**
@@ -29,13 +96,50 @@ class LanternSpeedIndex extends SpeedIndex {
29
96
  * @return {Promise<LH.Artifacts.LanternMetric>}
30
97
  */
31
98
  static async compute_(data, context) {
32
- // TODO(15841): lib/lantern should probably run Speedline
33
99
  const speedline = await Speedline.request(data.trace, context);
34
100
  const fcpResult = await LanternFirstContentfulPaint.request(data, context);
35
- return this.computeMetricWithGraphs(data, context, {
101
+ const metricResult = await this.computeMetricWithGraphs(data, context, {
36
102
  speedline,
37
103
  fcpResult,
38
104
  });
105
+ metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
106
+ return metricResult;
107
+ }
108
+
109
+ /**
110
+ * Approximate speed index using layout events from the simulated node timings.
111
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
112
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
113
+ *
114
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
115
+ *
116
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
117
+ * different methods. Read more in the evaluation doc.
118
+ *
119
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
120
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
121
+ * @param {number} fcpTimeInMs
122
+ * @return {number}
123
+ */
124
+ static computeLayoutBasedSpeedIndex(nodeTimings, fcpTimeInMs) {
125
+ /** @type {Array<{time: number, weight: number}>} */
126
+ const layoutWeights = [];
127
+ for (const [node, timing] of nodeTimings.entries()) {
128
+ if (node.type !== BaseNode.TYPES.CPU) continue;
129
+
130
+ if (node.childEvents.some(x => x.name === 'Layout')) {
131
+ const timingWeight = Math.max(Math.log2(timing.endTime - timing.startTime), 0);
132
+ layoutWeights.push({time: timing.endTime, weight: timingWeight});
133
+ }
134
+ }
135
+
136
+ const totalWeightedTime = layoutWeights
137
+ .map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs))
138
+ .reduce((a, b) => a + b, 0);
139
+ const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);
140
+
141
+ if (!totalWeight) return fcpTimeInMs;
142
+ return totalWeightedTime / totalWeight;
39
143
  }
40
144
  }
41
145
 
@@ -1,25 +1,37 @@
1
1
  export { LanternTotalBlockingTimeComputed as LanternTotalBlockingTime };
2
- export type Extras = import('../../lib/lantern/metric.js').Extras;
2
+ export type Node = import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>;
3
3
  declare const LanternTotalBlockingTimeComputed: typeof LanternTotalBlockingTime & {
4
4
  request: (dependencies: import("../../index.js").Artifacts.MetricComputationDataInput, context: import("../../../types/utility-types.js").default.ImmutableObject<{
5
5
  computedCache: Map<string, import("../../lib/arbitrary-equality-map.js").ArbitraryEqualityMap>;
6
6
  }>) => Promise<import("../../index.js").Artifacts.LanternMetric>;
7
7
  };
8
- /** @typedef {import('../../lib/lantern/metric.js').Extras} Extras */
9
- declare class LanternTotalBlockingTime extends TotalBlockingTime {
8
+ /** @typedef {import('../../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */
9
+ declare class LanternTotalBlockingTime extends LanternMetric {
10
10
  /**
11
- * @param {LH.Artifacts.MetricComputationDataInput} data
12
- * @param {LH.Artifacts.ComputedContext} context
13
- * @param {Omit<Extras, 'optimistic'>=} extras
14
- * @return {Promise<LH.Artifacts.LanternMetric>}
11
+ * @param {Node} dependencyGraph
12
+ * @return {Node}
15
13
  */
16
- static computeMetricWithGraphs(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext, extras?: Omit<Extras, 'optimistic'> | undefined): Promise<LH.Artifacts.LanternMetric>;
14
+ static getOptimisticGraph(dependencyGraph: Node): Node;
17
15
  /**
18
- * @param {LH.Artifacts.MetricComputationDataInput} data
19
- * @param {LH.Artifacts.ComputedContext} context
20
- * @return {Promise<LH.Artifacts.LanternMetric>}
16
+ * @param {Node} dependencyGraph
17
+ * @return {Node}
21
18
  */
22
- static compute_(data: LH.Artifacts.MetricComputationDataInput, context: LH.Artifacts.ComputedContext): Promise<LH.Artifacts.LanternMetric>;
19
+ static getPessimisticGraph(dependencyGraph: Node): Node;
20
+ /**
21
+ * @param {LH.Gatherer.Simulation.Result} simulation
22
+ * @param {import('../../lib/lantern/metric.js').Extras} extras
23
+ * @return {LH.Gatherer.Simulation.Result}
24
+ */
25
+ static getEstimateFromSimulation(simulation: LH.Gatherer.Simulation.Result, extras: import('../../lib/lantern/metric.js').Extras): LH.Gatherer.Simulation.Result;
26
+ /**
27
+ * @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
28
+ * @param {number} minDurationMs
29
+ */
30
+ static getTopLevelEvents(nodeTimings: LH.Gatherer.Simulation.Result['nodeTimings'], minDurationMs: number): {
31
+ start: number;
32
+ end: number;
33
+ duration: number;
34
+ }[];
23
35
  }
24
- import { TotalBlockingTime } from '../../lib/lantern/metrics/total-blocking-time.js';
36
+ import { LanternMetric } from './lantern-metric.js';
25
37
  //# sourceMappingURL=lantern-total-blocking-time.d.ts.map