@paulirish/trace_engine 0.0.24 → 0.0.26

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 (150) hide show
  1. package/core/platform/TypedArrayUtilities.d.ts +7 -0
  2. package/core/platform/TypedArrayUtilities.js +41 -0
  3. package/core/platform/TypedArrayUtilities.js.map +1 -1
  4. package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  5. package/core/platform/platform-tsconfig.json +0 -1
  6. package/generated/protocol.d.ts +73 -18
  7. package/models/cpu_profile/cpu_profile-tsconfig.json +0 -1
  8. package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  9. package/models/trace/LanternComputationData.d.ts +8 -0
  10. package/models/trace/LanternComputationData.js +368 -0
  11. package/models/trace/LanternComputationData.js.map +1 -0
  12. package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  13. package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  14. package/models/trace/extras/extras-tsconfig.json +0 -1
  15. package/models/trace/handlers/AuctionWorkletsHandler.js +1 -1
  16. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
  17. package/models/trace/handlers/EnhancedTracesHandler.d.ts +46 -0
  18. package/models/trace/handlers/EnhancedTracesHandler.js +137 -0
  19. package/models/trace/handlers/EnhancedTracesHandler.js.map +1 -0
  20. package/models/trace/handlers/LayoutShiftsHandler.d.ts +1 -1
  21. package/models/trace/handlers/LayoutShiftsHandler.js +3 -3
  22. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  23. package/models/trace/handlers/MetaHandler.js +39 -13
  24. package/models/trace/handlers/MetaHandler.js.map +1 -1
  25. package/models/trace/handlers/ModelHandlers.d.ts +1 -0
  26. package/models/trace/handlers/ModelHandlers.js +1 -0
  27. package/models/trace/handlers/ModelHandlers.js.map +1 -1
  28. package/models/trace/handlers/NetworkRequestsHandler.js +2 -2
  29. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  30. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +1 -2
  31. package/models/trace/handlers/PageLoadMetricsHandler.js +2 -35
  32. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
  33. package/models/trace/handlers/ScreenshotsHandler.js +1 -2
  34. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  35. package/models/trace/handlers/UserInteractionsHandler.d.ts +6 -0
  36. package/models/trace/handlers/UserInteractionsHandler.js +17 -2
  37. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  38. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  39. package/models/trace/handlers/handlers-tsconfig.json +1 -1
  40. package/models/trace/helpers/SyntheticEvents.d.ts +1 -0
  41. package/models/trace/helpers/SyntheticEvents.js +12 -0
  42. package/models/trace/helpers/SyntheticEvents.js.map +1 -1
  43. package/models/trace/helpers/Timing.d.ts +17 -6
  44. package/models/trace/helpers/Timing.js +17 -76
  45. package/models/trace/helpers/Timing.js.map +1 -1
  46. package/models/trace/helpers/Trace.js +1 -2
  47. package/models/trace/helpers/Trace.js.map +1 -1
  48. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  49. package/models/trace/helpers/helpers-tsconfig.json +0 -1
  50. package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  51. package/models/trace/insights/insights-tsconfig.json +0 -1
  52. package/models/trace/lantern/BaseNode.d.ts +91 -0
  53. package/models/trace/lantern/BaseNode.js +268 -0
  54. package/models/trace/lantern/BaseNode.js.map +1 -0
  55. package/models/trace/lantern/CPUNode.d.ts +24 -0
  56. package/models/trace/lantern/CPUNode.js +64 -0
  57. package/models/trace/lantern/CPUNode.js.map +1 -0
  58. package/models/trace/lantern/LanternError.d.ts +3 -0
  59. package/models/trace/lantern/LanternError.js +7 -0
  60. package/models/trace/lantern/LanternError.js.map +1 -0
  61. package/models/trace/lantern/MetricsModule.d.ts +11 -0
  62. package/models/trace/lantern/MetricsModule.js +14 -0
  63. package/models/trace/lantern/MetricsModule.js.map +1 -0
  64. package/models/trace/lantern/NetworkNode.d.ts +22 -0
  65. package/models/trace/lantern/NetworkNode.js +83 -0
  66. package/models/trace/lantern/NetworkNode.js.map +1 -0
  67. package/models/trace/lantern/PageDependencyGraph.d.ts +43 -0
  68. package/models/trace/lantern/PageDependencyGraph.js +509 -0
  69. package/models/trace/lantern/PageDependencyGraph.js.map +1 -0
  70. package/models/trace/lantern/SimulationModule.d.ts +17 -0
  71. package/models/trace/lantern/SimulationModule.js +13 -0
  72. package/models/trace/lantern/SimulationModule.js.map +1 -0
  73. package/models/trace/lantern/bundle-tsconfig.json +1 -0
  74. package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  75. package/models/trace/lantern/lantern-tsconfig.json +64 -0
  76. package/models/trace/lantern/lantern.d.ts +29 -0
  77. package/models/trace/lantern/lantern.js +33 -0
  78. package/models/trace/lantern/lantern.js.map +1 -0
  79. package/models/trace/lantern/metrics/FirstContentfulPaint.d.ts +42 -0
  80. package/models/trace/lantern/metrics/FirstContentfulPaint.js +137 -0
  81. package/models/trace/lantern/metrics/FirstContentfulPaint.js.map +1 -0
  82. package/models/trace/lantern/metrics/Interactive.d.ts +12 -0
  83. package/models/trace/lantern/metrics/Interactive.js +68 -0
  84. package/models/trace/lantern/metrics/Interactive.js.map +1 -0
  85. package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +16 -0
  86. package/models/trace/lantern/metrics/LargestContentfulPaint.js +70 -0
  87. package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -0
  88. package/models/trace/lantern/metrics/MaxPotentialFID.d.ts +14 -0
  89. package/models/trace/lantern/metrics/MaxPotentialFID.js +49 -0
  90. package/models/trace/lantern/metrics/MaxPotentialFID.js.map +1 -0
  91. package/models/trace/lantern/metrics/Metric.d.ts +26 -0
  92. package/models/trace/lantern/metrics/Metric.js +71 -0
  93. package/models/trace/lantern/metrics/Metric.js.map +1 -0
  94. package/models/trace/lantern/metrics/SpeedIndex.d.ts +25 -0
  95. package/models/trace/lantern/metrics/SpeedIndex.js +102 -0
  96. package/models/trace/lantern/metrics/SpeedIndex.js.map +1 -0
  97. package/models/trace/lantern/metrics/TBTUtils.d.ts +31 -0
  98. package/models/trace/lantern/metrics/TBTUtils.js +65 -0
  99. package/models/trace/lantern/metrics/TBTUtils.js.map +1 -0
  100. package/models/trace/lantern/metrics/TotalBlockingTime.d.ts +16 -0
  101. package/models/trace/lantern/metrics/TotalBlockingTime.js +79 -0
  102. package/models/trace/lantern/metrics/TotalBlockingTime.js.map +1 -0
  103. package/models/trace/lantern/metrics/metrics.d.ts +15 -0
  104. package/models/trace/lantern/metrics/metrics.js +12 -0
  105. package/models/trace/lantern/metrics/metrics.js.map +1 -0
  106. package/models/trace/lantern/simulation/ConnectionPool.d.ts +26 -0
  107. package/models/trace/lantern/simulation/ConnectionPool.js +116 -0
  108. package/models/trace/lantern/simulation/ConnectionPool.js.map +1 -0
  109. package/models/trace/lantern/simulation/Constants.d.ts +31 -0
  110. package/models/trace/lantern/simulation/Constants.js +43 -0
  111. package/models/trace/lantern/simulation/Constants.js.map +1 -0
  112. package/models/trace/lantern/simulation/DNSCache.d.ts +22 -0
  113. package/models/trace/lantern/simulation/DNSCache.js +48 -0
  114. package/models/trace/lantern/simulation/DNSCache.js.map +1 -0
  115. package/models/trace/lantern/simulation/NetworkAnalyzer.d.ts +112 -0
  116. package/models/trace/lantern/simulation/NetworkAnalyzer.js +486 -0
  117. package/models/trace/lantern/simulation/NetworkAnalyzer.js.map +1 -0
  118. package/models/trace/lantern/simulation/SimulationTimingMap.d.ts +71 -0
  119. package/models/trace/lantern/simulation/SimulationTimingMap.js +134 -0
  120. package/models/trace/lantern/simulation/SimulationTimingMap.js.map +1 -0
  121. package/models/trace/lantern/simulation/Simulator.d.ts +82 -0
  122. package/models/trace/lantern/simulation/Simulator.js +449 -0
  123. package/models/trace/lantern/simulation/Simulator.js.map +1 -0
  124. package/models/trace/lantern/simulation/TCPConnection.d.ts +48 -0
  125. package/models/trace/lantern/simulation/TCPConnection.js +158 -0
  126. package/models/trace/lantern/simulation/TCPConnection.js.map +1 -0
  127. package/models/trace/lantern/simulation/simulation.d.ts +21 -0
  128. package/models/trace/lantern/simulation/simulation.js +11 -0
  129. package/models/trace/lantern/simulation/simulation.js.map +1 -0
  130. package/models/trace/lantern/types/lantern.d.ts +205 -0
  131. package/models/trace/lantern/types/lantern.js +5 -0
  132. package/models/trace/lantern/types/lantern.js.map +1 -0
  133. package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  134. package/models/trace/root-causes/root-causes-tsconfig.json +0 -1
  135. package/models/trace/trace-tsconfig.json +4 -1
  136. package/models/trace/trace.d.ts +3 -1
  137. package/models/trace/trace.js +3 -1
  138. package/models/trace/trace.js.map +1 -1
  139. package/models/trace/types/Extensions.d.ts +2 -3
  140. package/models/trace/types/Extensions.js +2 -11
  141. package/models/trace/types/Extensions.js.map +1 -1
  142. package/models/trace/types/File.d.ts +28 -5
  143. package/models/trace/types/File.js +36 -1
  144. package/models/trace/types/File.js.map +1 -1
  145. package/models/trace/types/TraceEvents.d.ts +50 -0
  146. package/models/trace/types/TraceEvents.js +33 -0
  147. package/models/trace/types/TraceEvents.js.map +1 -1
  148. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  149. package/models/trace/types/types-tsconfig.json +0 -1
  150. package/package.json +1 -1
@@ -0,0 +1,49 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import { BaseNode } from '../BaseNode.js';
5
+ import { Metric } from './Metric.js';
6
+ class MaxPotentialFID extends Metric {
7
+ // eslint-disable-next-line @typescript-eslint/naming-convention
8
+ static get coefficients() {
9
+ return {
10
+ intercept: 0,
11
+ optimistic: 0.5,
12
+ pessimistic: 0.5,
13
+ };
14
+ }
15
+ static getOptimisticGraph(dependencyGraph) {
16
+ return dependencyGraph;
17
+ }
18
+ static getPessimisticGraph(dependencyGraph) {
19
+ return dependencyGraph;
20
+ }
21
+ static getEstimateFromSimulation(simulation, extras) {
22
+ if (!extras.fcpResult) {
23
+ throw new Error('missing fcpResult');
24
+ }
25
+ // Intentionally use the opposite FCP estimate, a more pessimistic FCP means that more tasks
26
+ // are excluded from the FID computation, so a higher FCP means lower FID for same work.
27
+ const fcpTimeInMs = extras.optimistic ? extras.fcpResult.pessimisticEstimate.timeInMs :
28
+ extras.fcpResult.optimisticEstimate.timeInMs;
29
+ const timings = MaxPotentialFID.getTimingsAfterFCP(simulation.nodeTimings, fcpTimeInMs);
30
+ return {
31
+ timeInMs: Math.max(...timings.map(timing => timing.duration), 16),
32
+ nodeTimings: simulation.nodeTimings,
33
+ };
34
+ }
35
+ static compute(data, extras) {
36
+ const fcpResult = extras?.fcpResult;
37
+ if (!fcpResult) {
38
+ throw new Error('FCP is required to calculate the Max Potential FID metric');
39
+ }
40
+ return super.compute(data, extras);
41
+ }
42
+ static getTimingsAfterFCP(nodeTimings, fcpTimeInMs) {
43
+ return Array.from(nodeTimings.entries())
44
+ .filter(([node, timing]) => node.type === BaseNode.types.CPU && timing.endTime > fcpTimeInMs)
45
+ .map(([_, timing]) => timing);
46
+ }
47
+ }
48
+ export { MaxPotentialFID };
49
+ //# sourceMappingURL=MaxPotentialFID.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MaxPotentialFID.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/MaxPotentialFID.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,EAAC,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAc,MAAM,EAAC,MAAM,aAAa,CAAC;AAEhD,MAAM,eAAgB,SAAQ,MAAM;IAClC,gEAAgE;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MAAM,CAAC,kBAAkB,CAAC,WAAqD,EAAE,WAAmB;QAElG,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aACnC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,MAAM,CAAC,OAAO,GAAG,WAAW,CAAC;aAC5F,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;CACF;AAED,OAAO,EAAC,eAAe,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {BaseNode, type Node} from '../BaseNode.js';\nimport type * as Lantern from '../types/lantern.js';\n\nimport {type Extras, Metric} from './Metric.js';\n\nclass MaxPotentialFID extends Metric {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static override get coefficients(): Lantern.Simulation.MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n static override getOptimisticGraph(dependencyGraph: Node): Node {\n return dependencyGraph;\n }\n\n static override getPessimisticGraph(dependencyGraph: Node): Node {\n return dependencyGraph;\n }\n\n static override getEstimateFromSimulation(simulation: Lantern.Simulation.Result, extras: Extras):\n Lantern.Simulation.Result {\n if (!extras.fcpResult) {\n throw new Error('missing fcpResult');\n }\n\n // Intentionally use the opposite FCP estimate, a more pessimistic FCP means that more tasks\n // are excluded from the FID computation, so a higher FCP means lower FID for same work.\n const fcpTimeInMs = extras.optimistic ? extras.fcpResult.pessimisticEstimate.timeInMs :\n extras.fcpResult.optimisticEstimate.timeInMs;\n\n const timings = MaxPotentialFID.getTimingsAfterFCP(\n simulation.nodeTimings,\n fcpTimeInMs,\n );\n\n return {\n timeInMs: Math.max(...timings.map(timing => timing.duration), 16),\n nodeTimings: simulation.nodeTimings,\n };\n }\n\n static override compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>):\n Promise<Lantern.Metrics.Result> {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Error('FCP is required to calculate the Max Potential FID metric');\n }\n\n return super.compute(data, extras);\n }\n\n static getTimingsAfterFCP(nodeTimings: Lantern.Simulation.Result['nodeTimings'], fcpTimeInMs: number):\n Array<{duration: number}> {\n return Array.from(nodeTimings.entries())\n .filter(([node, timing]) => node.type === BaseNode.types.CPU && timing.endTime > fcpTimeInMs)\n .map(([_, timing]) => timing);\n }\n}\n\nexport {MaxPotentialFID};\n"]}
@@ -0,0 +1,26 @@
1
+ import { type Node } from '../BaseNode.js';
2
+ import { type NetworkNode } from '../NetworkNode.js';
3
+ import type * as Lantern from '../types/lantern.js';
4
+ export interface Extras {
5
+ optimistic: boolean;
6
+ fcpResult?: Lantern.Metrics.Result;
7
+ lcpResult?: Lantern.Metrics.Result;
8
+ interactiveResult?: Lantern.Metrics.Result;
9
+ observedSpeedIndex?: number;
10
+ }
11
+ declare class Metric {
12
+ static getScriptUrls(dependencyGraph: Node, treatNodeAsRenderBlocking?: (node: NetworkNode) => boolean): Set<string>;
13
+ static get coefficients(): Lantern.Simulation.MetricCoefficients;
14
+ /**
15
+ * Returns the coefficients, scaled by the throttling settings if needed by the metric.
16
+ * Some lantern metrics (speed-index) use components in their estimate that are not
17
+ * from the simulator. In this case, we need to adjust the coefficients as the target throttling
18
+ * settings change.
19
+ */
20
+ static getScaledCoefficients(rttMs: number): Lantern.Simulation.MetricCoefficients;
21
+ static getOptimisticGraph(dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node;
22
+ static getPessimisticGraph(dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node;
23
+ static getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result, extras: Extras): Lantern.Simulation.Result;
24
+ static compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result>;
25
+ }
26
+ export { Metric };
@@ -0,0 +1,71 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import { BaseNode } from '../BaseNode.js';
5
+ class Metric {
6
+ static getScriptUrls(dependencyGraph, treatNodeAsRenderBlocking) {
7
+ const scriptUrls = new Set();
8
+ dependencyGraph.traverse(node => {
9
+ if (node.type !== BaseNode.types.NETWORK) {
10
+ return;
11
+ }
12
+ if (node.request.resourceType !== 'Script') {
13
+ return;
14
+ }
15
+ if (treatNodeAsRenderBlocking?.(node)) {
16
+ scriptUrls.add(node.request.url);
17
+ }
18
+ });
19
+ return scriptUrls;
20
+ }
21
+ // eslint-disable-next-line @typescript-eslint/naming-convention
22
+ static get coefficients() {
23
+ throw new Error('coefficients unimplemented!');
24
+ }
25
+ /* eslint-disable @typescript-eslint/no-unused-vars */
26
+ /**
27
+ * Returns the coefficients, scaled by the throttling settings if needed by the metric.
28
+ * Some lantern metrics (speed-index) use components in their estimate that are not
29
+ * from the simulator. In this case, we need to adjust the coefficients as the target throttling
30
+ * settings change.
31
+ */
32
+ static getScaledCoefficients(rttMs) {
33
+ return this.coefficients;
34
+ }
35
+ static getOptimisticGraph(dependencyGraph, processedNavigation) {
36
+ throw new Error('Optimistic graph unimplemented!');
37
+ }
38
+ static getPessimisticGraph(dependencyGraph, processedNavigation) {
39
+ throw new Error('Pessmistic graph unimplemented!');
40
+ }
41
+ static getEstimateFromSimulation(simulationResult, extras) {
42
+ return simulationResult;
43
+ }
44
+ /* eslint-enable @typescript-eslint/no-unused-vars */
45
+ static async compute(data, extras) {
46
+ const { simulator, graph, processedNavigation } = data;
47
+ const metricName = this.name.replace('Lantern', '');
48
+ const optimisticGraph = this.getOptimisticGraph(graph, processedNavigation);
49
+ const pessimisticGraph = this.getPessimisticGraph(graph, processedNavigation);
50
+ let simulateOptions = { label: `optimistic${metricName}` };
51
+ const optimisticSimulation = simulator.simulate(optimisticGraph, simulateOptions);
52
+ simulateOptions = { label: `pessimistic${metricName}` };
53
+ const pessimisticSimulation = simulator.simulate(pessimisticGraph, simulateOptions);
54
+ const optimisticEstimate = this.getEstimateFromSimulation(optimisticSimulation, { ...extras, optimistic: true });
55
+ const pessimisticEstimate = this.getEstimateFromSimulation(pessimisticSimulation, { ...extras, optimistic: false });
56
+ const coefficients = this.getScaledCoefficients(simulator.rtt);
57
+ // Estimates under 1s don't really follow the normal curve fit, minimize the impact of the intercept
58
+ const interceptMultiplier = coefficients.intercept > 0 ? Math.min(1, optimisticEstimate.timeInMs / 1000) : 1;
59
+ const timing = coefficients.intercept * interceptMultiplier +
60
+ coefficients.optimistic * optimisticEstimate.timeInMs + coefficients.pessimistic * pessimisticEstimate.timeInMs;
61
+ return {
62
+ timing,
63
+ optimisticEstimate,
64
+ pessimisticEstimate,
65
+ optimisticGraph,
66
+ pessimisticGraph,
67
+ };
68
+ }
69
+ }
70
+ export { Metric };
71
+ //# sourceMappingURL=Metric.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Metric.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/Metric.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,EAAC,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAYnD,MAAM,MAAM;IACV,MAAM,CAAC,aAAa,CAAC,eAAqB,EAAE,yBAA0D;QACpG,MAAM,UAAU,GAAgB,IAAI,GAAG,EAAE,CAAC;QAE1C,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBACzC,OAAO;YACT,CAAC;YACD,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,KA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C,KAAK,EAAE,aAAa,UAAU,EAAE,EAAC,CAAC;QACzD,MAAM,oBAAoB,GAAG,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;QAElF,eAAe,GAAG,EAAC,KAAK,EAAE,cAAc,UAAU,EAAE,EAAC,CAAC;QACtD,MAAM,qBAAqB,GAAG,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;QAEpF,MAAM,kBAAkB,GAAG,IAAI,CAAC,yBAAyB,CACrD,oBAAoB,EACpB,EAAC,GAAG,MAAM,EAAE,UAAU,EAAE,IAAI,EAAC,CAChC,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,yBAAyB,CACtD,qBAAqB,EACrB,EAAC,GAAG,MAAM,EAAE,UAAU,EAAE,KAAK,EAAC,CACjC,CAAC;QAEF,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/D,oGAAoG;QACpG,MAAM,mBAAmB,GAAG,YAAY,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7G,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,GAAG,mBAAmB;YACvD,YAAY,CAAC,UAAU,GAAG,kBAAkB,CAAC,QAAQ,GAAG,YAAY,CAAC,WAAW,GAAG,mBAAmB,CAAC,QAAQ,CAAC;QAEpH,OAAO;YACL,MAAM;YACN,kBAAkB;YAClB,mBAAmB;YACnB,eAAe;YACf,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAC,MAAM,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {BaseNode, type Node} from '../BaseNode.js';\nimport {type NetworkNode} from '../NetworkNode.js';\nimport type * as Lantern from '../types/lantern.js';\n\nexport interface Extras {\n optimistic: boolean;\n fcpResult?: Lantern.Metrics.Result;\n lcpResult?: Lantern.Metrics.Result;\n interactiveResult?: Lantern.Metrics.Result;\n observedSpeedIndex?: number;\n}\n\nclass Metric {\n static getScriptUrls(dependencyGraph: Node, treatNodeAsRenderBlocking?: (node: NetworkNode) => boolean): Set<string> {\n const scriptUrls: Set<string> = new Set();\n\n dependencyGraph.traverse(node => {\n if (node.type !== BaseNode.types.NETWORK) {\n return;\n }\n if (node.request.resourceType !== 'Script') {\n return;\n }\n if (treatNodeAsRenderBlocking?.(node)) {\n scriptUrls.add(node.request.url);\n }\n });\n\n return scriptUrls;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static get coefficients(): Lantern.Simulation.MetricCoefficients {\n throw new Error('coefficients unimplemented!');\n }\n\n /* eslint-disable @typescript-eslint/no-unused-vars */\n\n /**\n * Returns the coefficients, scaled by the throttling settings if needed by the metric.\n * Some lantern metrics (speed-index) use components in their estimate that are not\n * from the simulator. In this case, we need to adjust the coefficients as the target throttling\n * settings change.\n */\n static getScaledCoefficients(rttMs: number): Lantern.Simulation.MetricCoefficients {\n return this.coefficients;\n }\n\n static getOptimisticGraph(dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node {\n throw new Error('Optimistic graph unimplemented!');\n }\n\n static getPessimisticGraph(dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node {\n throw new Error('Pessmistic graph unimplemented!');\n }\n\n static getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result, extras: Extras):\n Lantern.Simulation.Result {\n return simulationResult;\n }\n\n /* eslint-enable @typescript-eslint/no-unused-vars */\n\n static async compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>):\n Promise<Lantern.Metrics.Result> {\n const {simulator, graph, processedNavigation} = data;\n\n const metricName = this.name.replace('Lantern', '');\n const optimisticGraph = this.getOptimisticGraph(graph, processedNavigation);\n const pessimisticGraph = this.getPessimisticGraph(graph, processedNavigation);\n\n let simulateOptions = {label: `optimistic${metricName}`};\n const optimisticSimulation = simulator.simulate(optimisticGraph, simulateOptions);\n\n simulateOptions = {label: `pessimistic${metricName}`};\n const pessimisticSimulation = simulator.simulate(pessimisticGraph, simulateOptions);\n\n const optimisticEstimate = this.getEstimateFromSimulation(\n optimisticSimulation,\n {...extras, optimistic: true},\n );\n\n const pessimisticEstimate = this.getEstimateFromSimulation(\n pessimisticSimulation,\n {...extras, optimistic: false},\n );\n\n const coefficients = this.getScaledCoefficients(simulator.rtt);\n // Estimates under 1s don't really follow the normal curve fit, minimize the impact of the intercept\n const interceptMultiplier = coefficients.intercept > 0 ? Math.min(1, optimisticEstimate.timeInMs / 1000) : 1;\n const timing = coefficients.intercept * interceptMultiplier +\n coefficients.optimistic * optimisticEstimate.timeInMs + coefficients.pessimistic * pessimisticEstimate.timeInMs;\n\n return {\n timing,\n optimisticEstimate,\n pessimisticEstimate,\n optimisticGraph,\n pessimisticGraph,\n };\n }\n}\n\nexport {Metric};\n"]}
@@ -0,0 +1,25 @@
1
+ import { type Node } from '../BaseNode.js';
2
+ import type * as Lantern from '../types/lantern.js';
3
+ import { type Extras, Metric } from './Metric.js';
4
+ declare class SpeedIndex extends Metric {
5
+ static get coefficients(): Lantern.Simulation.MetricCoefficients;
6
+ static getScaledCoefficients(rttMs: number): Lantern.Simulation.MetricCoefficients;
7
+ static getOptimisticGraph(dependencyGraph: Node): Node;
8
+ static getPessimisticGraph(dependencyGraph: Node): Node;
9
+ static getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result, extras: Extras): Lantern.Simulation.Result;
10
+ static compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result>;
11
+ /**
12
+ * Approximate speed index using layout events from the simulated node timings.
13
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
14
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
15
+ *
16
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
17
+ *
18
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
19
+ * different methods. Read more in the evaluation doc.
20
+ *
21
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
22
+ */
23
+ static computeLayoutBasedSpeedIndex(nodeTimings: Lantern.Simulation.Result['nodeTimings'], fcpTimeInMs: number): number;
24
+ }
25
+ export { SpeedIndex };
@@ -0,0 +1,102 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import { BaseNode } from '../BaseNode.js';
5
+ import { Metric } from './Metric.js';
6
+ const mobileSlow4GRtt = 150;
7
+ class SpeedIndex extends Metric {
8
+ // eslint-disable-next-line @typescript-eslint/naming-convention
9
+ static get coefficients() {
10
+ return {
11
+ // Note that the optimistic estimate is based on the real observed speed index rather than a
12
+ // real lantern graph (and the final estimate will be Math.max(FCP, Speed Index)).
13
+ intercept: 0,
14
+ optimistic: 1.4,
15
+ pessimistic: 0.4,
16
+ };
17
+ }
18
+ static getScaledCoefficients(rttMs) {
19
+ // We want to scale our default coefficients based on the speed of the connection.
20
+ // We will linearly interpolate coefficients for the passed-in rttMs based on two pre-determined points:
21
+ // 1. Baseline point of 30 ms RTT where Speed Index should be a ~50/50 blend of optimistic/pessimistic.
22
+ // 30 ms was based on a typical home WiFi connection's actual RTT.
23
+ // Coefficients here follow from the fact that the optimistic estimate should be very close
24
+ // to reality at this connection speed and the pessimistic estimate compensates for minor
25
+ // connection speed differences.
26
+ // 2. Default throttled point of 150 ms RTT where the default coefficients have been determined to be most accurate.
27
+ // Coefficients here were determined through thorough analysis and linear regression on the
28
+ // lantern test data set. See core/scripts/test-lantern.sh for more detail.
29
+ // While the coefficients haven't been analyzed at the interpolated points, it's our current best effort.
30
+ const defaultCoefficients = this.coefficients;
31
+ const defaultRttExcess = mobileSlow4GRtt - 30;
32
+ const multiplier = Math.max((rttMs - 30) / defaultRttExcess, 0);
33
+ return {
34
+ intercept: defaultCoefficients.intercept * multiplier,
35
+ optimistic: 0.5 + (defaultCoefficients.optimistic - 0.5) * multiplier,
36
+ pessimistic: 0.5 + (defaultCoefficients.pessimistic - 0.5) * multiplier,
37
+ };
38
+ }
39
+ static getOptimisticGraph(dependencyGraph) {
40
+ return dependencyGraph;
41
+ }
42
+ static getPessimisticGraph(dependencyGraph) {
43
+ return dependencyGraph;
44
+ }
45
+ static getEstimateFromSimulation(simulationResult, extras) {
46
+ if (!extras.fcpResult) {
47
+ throw new Error('missing fcpResult');
48
+ }
49
+ if (extras.observedSpeedIndex === undefined) {
50
+ throw new Error('missing observedSpeedIndex');
51
+ }
52
+ const fcpTimeInMs = extras.fcpResult.pessimisticEstimate.timeInMs;
53
+ const estimate = extras.optimistic ?
54
+ extras.observedSpeedIndex :
55
+ SpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTimings, fcpTimeInMs);
56
+ return {
57
+ timeInMs: estimate,
58
+ nodeTimings: simulationResult.nodeTimings,
59
+ };
60
+ }
61
+ static async compute(data, extras) {
62
+ const fcpResult = extras?.fcpResult;
63
+ if (!fcpResult) {
64
+ throw new Error('FCP is required to calculate the SpeedIndex metric');
65
+ }
66
+ const metricResult = await super.compute(data, extras);
67
+ metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
68
+ return metricResult;
69
+ }
70
+ /**
71
+ * Approximate speed index using layout events from the simulated node timings.
72
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
73
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
74
+ *
75
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
76
+ *
77
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
78
+ * different methods. Read more in the evaluation doc.
79
+ *
80
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
81
+ */
82
+ static computeLayoutBasedSpeedIndex(nodeTimings, fcpTimeInMs) {
83
+ const layoutWeights = [];
84
+ for (const [node, timing] of nodeTimings.entries()) {
85
+ if (node.type !== BaseNode.types.CPU) {
86
+ continue;
87
+ }
88
+ if (node.childEvents.some(x => x.name === 'Layout')) {
89
+ const timingWeight = Math.max(Math.log2(timing.endTime - timing.startTime), 0);
90
+ layoutWeights.push({ time: timing.endTime, weight: timingWeight });
91
+ }
92
+ }
93
+ const totalWeightedTime = layoutWeights.map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs)).reduce((a, b) => a + b, 0);
94
+ const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);
95
+ if (!totalWeight) {
96
+ return fcpTimeInMs;
97
+ }
98
+ return totalWeightedTime / totalWeight;
99
+ }
100
+ }
101
+ export { SpeedIndex };
102
+ //# sourceMappingURL=SpeedIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpeedIndex.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/SpeedIndex.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,EAAC,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAc,MAAM,EAAC,MAAM,aAAa,CAAC;AAEhD,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,UAAW,SAAQ,MAAM;IAC7B,gEAAgE;IAChE,MAAM,KAAc,YAAY;QAC9B,OAAO;YACL,4FAA4F;YAC5F,kFAAkF;YAClF,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,CAAU,qBAAqB,CAAC,KAAa;QAEjD,kFAAkF;QAClF,wGAAwG;QACxG,y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,MAAM,EAAE,YAAY,EAAC,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;QAED,MAAM,iBAAiB,GACnB,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACtG,MAAM,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAEpF,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,OAAO,iBAAiB,GAAG,WAAW,CAAC;IACzC,CAAC;CACF;AAED,OAAO,EAAC,UAAU,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {BaseNode, type Node} from '../BaseNode.js';\nimport type * as Lantern from '../types/lantern.js';\n\nimport {type Extras, Metric} from './Metric.js';\n\nconst mobileSlow4GRtt = 150;\n\nclass SpeedIndex extends Metric {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static override get coefficients(): Lantern.Simulation.MetricCoefficients {\n return {\n // Note that the optimistic estimate is based on the real observed speed index rather than a\n // real lantern graph (and the final estimate will be Math.max(FCP, Speed Index)).\n intercept: 0,\n optimistic: 1.4,\n pessimistic: 0.4,\n };\n }\n\n static override getScaledCoefficients(rttMs: number):\n Lantern.Simulation.MetricCoefficients { // eslint-disable-line no-unused-vars\n // We want to scale our default coefficients based on the speed of the connection.\n // We will linearly interpolate coefficients for the passed-in rttMs based on two pre-determined points:\n // 1. Baseline point of 30 ms RTT where Speed Index should be a ~50/50 blend of optimistic/pessimistic.\n // 30 ms was based on a typical home WiFi connection's actual RTT.\n // Coefficients here follow from the fact that the optimistic estimate should be very close\n // to reality at this connection speed and the pessimistic estimate compensates for minor\n // connection speed differences.\n // 2. Default throttled point of 150 ms RTT where the default coefficients have been determined to be most accurate.\n // Coefficients here were determined through thorough analysis and linear regression on the\n // lantern test data set. See core/scripts/test-lantern.sh for more detail.\n // While the coefficients haven't been analyzed at the interpolated points, it's our current best effort.\n const defaultCoefficients = this.coefficients;\n const defaultRttExcess = mobileSlow4GRtt - 30;\n const multiplier = Math.max((rttMs - 30) / defaultRttExcess, 0);\n\n return {\n intercept: defaultCoefficients.intercept * multiplier,\n optimistic: 0.5 + (defaultCoefficients.optimistic - 0.5) * multiplier,\n pessimistic: 0.5 + (defaultCoefficients.pessimistic - 0.5) * multiplier,\n };\n }\n\n static override getOptimisticGraph(dependencyGraph: Node): Node {\n return dependencyGraph;\n }\n\n static override getPessimisticGraph(dependencyGraph: Node): Node {\n return dependencyGraph;\n }\n\n static override getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result, extras: Extras):\n Lantern.Simulation.Result {\n if (!extras.fcpResult) {\n throw new Error('missing fcpResult');\n }\n if (extras.observedSpeedIndex === undefined) {\n throw new Error('missing observedSpeedIndex');\n }\n\n const fcpTimeInMs = extras.fcpResult.pessimisticEstimate.timeInMs;\n const estimate = extras.optimistic ?\n extras.observedSpeedIndex :\n SpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTimings, fcpTimeInMs);\n return {\n timeInMs: estimate,\n nodeTimings: simulationResult.nodeTimings,\n };\n }\n\n static override async compute(\n data: Lantern.Simulation.MetricComputationDataInput,\n extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result> {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Error('FCP is required to calculate the SpeedIndex metric');\n }\n\n const metricResult = await super.compute(data, extras);\n metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);\n return metricResult;\n }\n\n /**\n * Approximate speed index using layout events from the simulated node timings.\n * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained\n * a 'Layout' task. log(duration) is used as the weight to stand for \"significance\" to the page.\n *\n * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.\n *\n * This approach was determined after evaluating the accuracy/complexity tradeoff of many\n * different methods. Read more in the evaluation doc.\n *\n * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#\n */\n static computeLayoutBasedSpeedIndex(nodeTimings: Lantern.Simulation.Result['nodeTimings'], fcpTimeInMs: number):\n number {\n const layoutWeights: Array<{time: number, weight: number}> = [];\n for (const [node, timing] of nodeTimings.entries()) {\n if (node.type !== BaseNode.types.CPU) {\n continue;\n }\n\n if (node.childEvents.some(x => x.name === 'Layout')) {\n const timingWeight = Math.max(Math.log2(timing.endTime - timing.startTime), 0);\n layoutWeights.push({time: timing.endTime, weight: timingWeight});\n }\n }\n\n const totalWeightedTime =\n layoutWeights.map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs)).reduce((a, b) => a + b, 0);\n const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);\n\n if (!totalWeight) {\n return fcpTimeInMs;\n }\n return totalWeightedTime / totalWeight;\n }\n}\n\nexport {SpeedIndex};\n"]}
@@ -0,0 +1,31 @@
1
+ declare const BLOCKING_TIME_THRESHOLD = 50;
2
+ /**
3
+ * For TBT, We only want to consider tasks that fall in our time range
4
+ * - FCP and TTI for navigation mode
5
+ * - Trace start and trace end for timespan mode
6
+ *
7
+ * FCP is picked as `startTimeMs` because there is little risk of user input happening
8
+ * before FCP so Long Queuing Qelay regions do not harm user experience. Developers should be
9
+ * optimizing to reach FCP as fast as possible without having to worry about task lengths.
10
+ *
11
+ * TTI is picked as `endTimeMs` because we want a well defined end point for page load.
12
+ *
13
+ * @param startTimeMs Should be FCP in navigation mode and the trace start time in timespan mode
14
+ * @param endTimeMs Should be TTI in navigation mode and the trace end time in timespan mode
15
+ * @param topLevelEvent Leave unset if `event` is top level. Has no effect if `event` has the same duration as `topLevelEvent`.
16
+ */
17
+ declare function calculateTbtImpactForEvent(event: {
18
+ start: number;
19
+ end: number;
20
+ duration: number;
21
+ }, startTimeMs: number, endTimeMs: number, topLevelEvent?: {
22
+ start: number;
23
+ end: number;
24
+ duration: number;
25
+ }): number;
26
+ declare function calculateSumOfBlockingTime(topLevelEvents: Array<{
27
+ start: number;
28
+ end: number;
29
+ duration: number;
30
+ }>, startTimeMs: number, endTimeMs: number): number;
31
+ export { BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime, calculateTbtImpactForEvent, };
@@ -0,0 +1,65 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ const BLOCKING_TIME_THRESHOLD = 50;
5
+ /**
6
+ * For TBT, We only want to consider tasks that fall in our time range
7
+ * - FCP and TTI for navigation mode
8
+ * - Trace start and trace end for timespan mode
9
+ *
10
+ * FCP is picked as `startTimeMs` because there is little risk of user input happening
11
+ * before FCP so Long Queuing Qelay regions do not harm user experience. Developers should be
12
+ * optimizing to reach FCP as fast as possible without having to worry about task lengths.
13
+ *
14
+ * TTI is picked as `endTimeMs` because we want a well defined end point for page load.
15
+ *
16
+ * @param startTimeMs Should be FCP in navigation mode and the trace start time in timespan mode
17
+ * @param endTimeMs Should be TTI in navigation mode and the trace end time in timespan mode
18
+ * @param topLevelEvent Leave unset if `event` is top level. Has no effect if `event` has the same duration as `topLevelEvent`.
19
+ */
20
+ function calculateTbtImpactForEvent(event, startTimeMs, endTimeMs, topLevelEvent) {
21
+ let threshold = BLOCKING_TIME_THRESHOLD;
22
+ // If a task is not top level, it doesn't make sense to subtract the entire 50ms
23
+ // blocking threshold from the event.
24
+ //
25
+ // e.g. A 80ms top level task with two 40ms children should attribute some blocking
26
+ // time to the 40ms tasks even though they do not meet the 50ms threshold.
27
+ //
28
+ // The solution is to scale the threshold for child events to be considered blocking.
29
+ if (topLevelEvent) {
30
+ threshold *= (event.duration / topLevelEvent.duration);
31
+ }
32
+ if (event.duration < threshold) {
33
+ return 0;
34
+ }
35
+ if (event.end < startTimeMs) {
36
+ return 0;
37
+ }
38
+ if (event.start > endTimeMs) {
39
+ return 0;
40
+ }
41
+ // Perform the clipping and then calculate Blocking Region. So if we have a 150ms task
42
+ // [0, 150] and `startTimeMs` is at 50ms, we first clip the task to [50, 150], and then
43
+ // calculate the Blocking Region to be [100, 150]. The rational here is that tasks before
44
+ // the start time are unimportant, so we care whether the main thread is busy more than
45
+ // 50ms at a time only after the start time.
46
+ const clippedStart = Math.max(event.start, startTimeMs);
47
+ const clippedEnd = Math.min(event.end, endTimeMs);
48
+ const clippedDuration = clippedEnd - clippedStart;
49
+ if (clippedDuration < threshold) {
50
+ return 0;
51
+ }
52
+ return clippedDuration - threshold;
53
+ }
54
+ function calculateSumOfBlockingTime(topLevelEvents, startTimeMs, endTimeMs) {
55
+ if (endTimeMs <= startTimeMs) {
56
+ return 0;
57
+ }
58
+ let sumBlockingTime = 0;
59
+ for (const event of topLevelEvents) {
60
+ sumBlockingTime += calculateTbtImpactForEvent(event, startTimeMs, endTimeMs);
61
+ }
62
+ return sumBlockingTime;
63
+ }
64
+ export { BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime, calculateTbtImpactForEvent, };
65
+ //# sourceMappingURL=TBTUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TBTUtils.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/TBTUtils.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC;;;;;;;;;;;;;;GAcG;AACH,SAAS,0BAA0B,CAC/B,KAAqD,EAAE,WA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AAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,0BAA0B,GAC3B,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nconst BLOCKING_TIME_THRESHOLD = 50;\n\n/**\n * For TBT, We only want to consider tasks that fall in our time range\n * - FCP and TTI for navigation mode\n * - Trace start and trace end for timespan mode\n *\n * FCP is picked as `startTimeMs` because there is little risk of user input happening\n * before FCP so Long Queuing Qelay regions do not harm user experience. Developers should be\n * optimizing to reach FCP as fast as possible without having to worry about task lengths.\n *\n * TTI is picked as `endTimeMs` because we want a well defined end point for page load.\n *\n * @param startTimeMs Should be FCP in navigation mode and the trace start time in timespan mode\n * @param endTimeMs Should be TTI in navigation mode and the trace end time in timespan mode\n * @param topLevelEvent Leave unset if `event` is top level. Has no effect if `event` has the same duration as `topLevelEvent`.\n */\nfunction calculateTbtImpactForEvent(\n event: {start: number, end: number, duration: number}, startTimeMs: number, endTimeMs: number,\n topLevelEvent?: {start: number, end: number, duration: number}): number {\n let threshold = BLOCKING_TIME_THRESHOLD;\n\n // If a task is not top level, it doesn't make sense to subtract the entire 50ms\n // blocking threshold from the event.\n //\n // e.g. A 80ms top level task with two 40ms children should attribute some blocking\n // time to the 40ms tasks even though they do not meet the 50ms threshold.\n //\n // The solution is to scale the threshold for child events to be considered blocking.\n if (topLevelEvent) {\n threshold *= (event.duration / topLevelEvent.duration);\n }\n\n if (event.duration < threshold) {\n return 0;\n }\n if (event.end < startTimeMs) {\n return 0;\n }\n if (event.start > endTimeMs) {\n return 0;\n }\n\n // Perform the clipping and then calculate Blocking Region. So if we have a 150ms task\n // [0, 150] and `startTimeMs` is at 50ms, we first clip the task to [50, 150], and then\n // calculate the Blocking Region to be [100, 150]. The rational here is that tasks before\n // the start time are unimportant, so we care whether the main thread is busy more than\n // 50ms at a time only after the start time.\n const clippedStart = Math.max(event.start, startTimeMs);\n const clippedEnd = Math.min(event.end, endTimeMs);\n const clippedDuration = clippedEnd - clippedStart;\n if (clippedDuration < threshold) {\n return 0;\n }\n\n return clippedDuration - threshold;\n}\n\nfunction calculateSumOfBlockingTime(\n topLevelEvents: Array<{start: number, end: number, duration: number}>, startTimeMs: number,\n endTimeMs: number): number {\n if (endTimeMs <= startTimeMs) {\n return 0;\n }\n\n let sumBlockingTime = 0;\n for (const event of topLevelEvents) {\n sumBlockingTime += calculateTbtImpactForEvent(event, startTimeMs, endTimeMs);\n }\n\n return sumBlockingTime;\n}\n\nexport {\n BLOCKING_TIME_THRESHOLD,\n calculateSumOfBlockingTime,\n calculateTbtImpactForEvent,\n};\n"]}
@@ -0,0 +1,16 @@
1
+ import { type Node } from '../BaseNode.js';
2
+ import type * as Lantern from '../types/lantern.js';
3
+ import { type Extras, Metric } from './Metric.js';
4
+ declare class TotalBlockingTime extends Metric {
5
+ static get coefficients(): Lantern.Simulation.MetricCoefficients;
6
+ static getOptimisticGraph(dependencyGraph: Node): Node;
7
+ static getPessimisticGraph(dependencyGraph: Node): Node;
8
+ static getEstimateFromSimulation(simulation: Lantern.Simulation.Result, extras: Extras): Lantern.Simulation.Result;
9
+ static compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result>;
10
+ static getTopLevelEvents(nodeTimings: Lantern.Simulation.Result['nodeTimings'], minDurationMs: number): {
11
+ start: number;
12
+ end: number;
13
+ duration: number;
14
+ }[];
15
+ }
16
+ export { TotalBlockingTime };
@@ -0,0 +1,79 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import { BaseNode } from '../BaseNode.js';
5
+ import { Metric } from './Metric.js';
6
+ import { BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime } from './TBTUtils.js';
7
+ class TotalBlockingTime extends Metric {
8
+ // eslint-disable-next-line @typescript-eslint/naming-convention
9
+ static get coefficients() {
10
+ return {
11
+ intercept: 0,
12
+ optimistic: 0.5,
13
+ pessimistic: 0.5,
14
+ };
15
+ }
16
+ static getOptimisticGraph(dependencyGraph) {
17
+ return dependencyGraph;
18
+ }
19
+ static getPessimisticGraph(dependencyGraph) {
20
+ return dependencyGraph;
21
+ }
22
+ static getEstimateFromSimulation(simulation, extras) {
23
+ if (!extras.fcpResult) {
24
+ throw new Error('missing fcpResult');
25
+ }
26
+ if (!extras.interactiveResult) {
27
+ throw new Error('missing interactiveResult');
28
+ }
29
+ // Intentionally use the opposite FCP estimate. A pessimistic FCP is higher than equal to an
30
+ // optimistic FCP, which means potentially more tasks are excluded from the Total Blocking Time
31
+ // computation. So a more pessimistic FCP gives a more optimistic Total Blocking Time for the
32
+ // same work.
33
+ const fcpTimeInMs = extras.optimistic ? extras.fcpResult.pessimisticEstimate.timeInMs :
34
+ extras.fcpResult.optimisticEstimate.timeInMs;
35
+ // Similarly, we always have pessimistic TTI >= optimistic TTI. Therefore, picking optimistic
36
+ // TTI means our window of interest is smaller and thus potentially more tasks are excluded from
37
+ // Total Blocking Time computation, yielding a lower (more optimistic) Total Blocking Time value
38
+ // for the same work.
39
+ const interactiveTimeMs = extras.optimistic ? extras.interactiveResult.optimisticEstimate.timeInMs :
40
+ extras.interactiveResult.pessimisticEstimate.timeInMs;
41
+ const minDurationMs = BLOCKING_TIME_THRESHOLD;
42
+ const events = TotalBlockingTime.getTopLevelEvents(simulation.nodeTimings, minDurationMs);
43
+ return {
44
+ timeInMs: calculateSumOfBlockingTime(events, fcpTimeInMs, interactiveTimeMs),
45
+ nodeTimings: simulation.nodeTimings,
46
+ };
47
+ }
48
+ static async compute(data, extras) {
49
+ const fcpResult = extras?.fcpResult;
50
+ if (!fcpResult) {
51
+ throw new Error('FCP is required to calculate the TBT metric');
52
+ }
53
+ const interactiveResult = extras?.fcpResult;
54
+ if (!interactiveResult) {
55
+ throw new Error('Interactive is required to calculate the TBT metric');
56
+ }
57
+ return super.compute(data, extras);
58
+ }
59
+ static getTopLevelEvents(nodeTimings, minDurationMs) {
60
+ const events = [];
61
+ for (const [node, timing] of nodeTimings.entries()) {
62
+ if (node.type !== BaseNode.types.CPU) {
63
+ continue;
64
+ }
65
+ // Filtering out events below minimum duration.
66
+ if (timing.duration < minDurationMs) {
67
+ continue;
68
+ }
69
+ events.push({
70
+ start: timing.startTime,
71
+ end: timing.endTime,
72
+ duration: timing.duration,
73
+ });
74
+ }
75
+ return events;
76
+ }
77
+ }
78
+ export { TotalBlockingTime };
79
+ //# sourceMappingURL=TotalBlockingTime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TotalBlockingTime.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/TotalBlockingTime.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,EAAC,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAc,MAAM,EAAC,MAAM,aAAa,CAAC;AAChD,OAAO,EAAC,uBAAuB,EAAE,0BAA0B,EAAC,MAAM,eAAe,CAAC;AAElF,MAAM,iBAAkB,SAAQ,MAAM;IACpC,gEAAgE;IAChE,MAAM,KAAc,YAAY;QAC9B,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG;SACjB,CAAC;IACJ,CAAC;IAED,MAAM,CAAU,kBAAkB,CAAC,eAAqB;QACtD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,CAAU,mBAAmB,CAAC,eAAqB;QACvD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,CAAU,yBAAyB,CAAC,UAAqC,EAAE,MAAc;QAE7F,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,KAA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,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,WAAqD,EAAE,aAAqB;QAEnG,MAAM,MAAM,GAA0D,EAAE,CAAC;QAEzE,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACnD,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;gBACrC,SAAS;YACX,CAAC;YACD,+CAA+C;YAC/C,IAAI,MAAM,CAAC,QAAQ,GAAG,aAAa,EAAE,CAAC;gBACpC,SAAS;YACX,CAAC;YAED,MAAM,CAAC,IAAI,CAAC;gBACV,KAAK,EAAE,MAAM,CAAC,SAAS;gBACvB,GAAG,EAAE,MAAM,CAAC,OAAO;gBACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,OAAO,EAAC,iBAAiB,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {BaseNode, type Node} from '../BaseNode.js';\nimport type * as Lantern from '../types/lantern.js';\n\nimport {type Extras, Metric} from './Metric.js';\nimport {BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime} from './TBTUtils.js';\n\nclass TotalBlockingTime extends Metric {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static override get coefficients(): Lantern.Simulation.MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n static override getOptimisticGraph(dependencyGraph: Node): Node {\n return dependencyGraph;\n }\n\n static override getPessimisticGraph(dependencyGraph: Node): Node {\n return dependencyGraph;\n }\n\n static override getEstimateFromSimulation(simulation: Lantern.Simulation.Result, extras: Extras):\n Lantern.Simulation.Result {\n if (!extras.fcpResult) {\n throw new Error('missing fcpResult');\n }\n if (!extras.interactiveResult) {\n throw new Error('missing interactiveResult');\n }\n\n // Intentionally use the opposite FCP estimate. A pessimistic FCP is higher than equal to an\n // optimistic FCP, which means potentially more tasks are excluded from the Total Blocking Time\n // computation. So a more pessimistic FCP gives a more optimistic Total Blocking Time for the\n // same work.\n const fcpTimeInMs = extras.optimistic ? extras.fcpResult.pessimisticEstimate.timeInMs :\n extras.fcpResult.optimisticEstimate.timeInMs;\n\n // Similarly, we always have pessimistic TTI >= optimistic TTI. Therefore, picking optimistic\n // TTI means our window of interest is smaller and thus potentially more tasks are excluded from\n // Total Blocking Time computation, yielding a lower (more optimistic) Total Blocking Time value\n // for the same work.\n const interactiveTimeMs = extras.optimistic ? extras.interactiveResult.optimisticEstimate.timeInMs :\n extras.interactiveResult.pessimisticEstimate.timeInMs;\n\n const minDurationMs = BLOCKING_TIME_THRESHOLD;\n\n const events = TotalBlockingTime.getTopLevelEvents(\n simulation.nodeTimings,\n minDurationMs,\n );\n\n return {\n timeInMs: calculateSumOfBlockingTime(\n events,\n fcpTimeInMs,\n interactiveTimeMs,\n ),\n nodeTimings: simulation.nodeTimings,\n };\n }\n\n static override async compute(\n data: Lantern.Simulation.MetricComputationDataInput,\n extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result> {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Error('FCP is required to calculate the TBT metric');\n }\n\n const interactiveResult = extras?.fcpResult;\n if (!interactiveResult) {\n throw new Error('Interactive is required to calculate the TBT metric');\n }\n\n return super.compute(data, extras);\n }\n\n static getTopLevelEvents(nodeTimings: Lantern.Simulation.Result['nodeTimings'], minDurationMs: number):\n {start: number, end: number, duration: number}[] {\n const events: Array<{start: number, end: number, duration: number}> = [];\n\n for (const [node, timing] of nodeTimings.entries()) {\n if (node.type !== BaseNode.types.CPU) {\n continue;\n }\n // Filtering out events below minimum duration.\n if (timing.duration < minDurationMs) {\n continue;\n }\n\n events.push({\n start: timing.startTime,\n end: timing.endTime,\n duration: timing.duration,\n });\n }\n\n return events;\n }\n}\n\nexport {TotalBlockingTime};\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type * as Lantern from '../types/lantern.js';
7
+ export { FirstContentfulPaint } from './FirstContentfulPaint.js';
8
+ export { Interactive } from './Interactive.js';
9
+ export { LargestContentfulPaint } from './LargestContentfulPaint.js';
10
+ export { MaxPotentialFID } from './MaxPotentialFID.js';
11
+ export { Metric, Extras } from './Metric.js';
12
+ export { SpeedIndex } from './SpeedIndex.js';
13
+ export * as TBTUtils from './TBTUtils.js';
14
+ export { TotalBlockingTime } from './TotalBlockingTime.js';
15
+ export type Result<T = Lantern.AnyNetworkObject> = Lantern.Metrics.Result<T>;
@@ -0,0 +1,12 @@
1
+ // Copyright 2024 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ export { FirstContentfulPaint } from './FirstContentfulPaint.js';
5
+ export { Interactive } from './Interactive.js';
6
+ export { LargestContentfulPaint } from './LargestContentfulPaint.js';
7
+ export { MaxPotentialFID } from './MaxPotentialFID.js';
8
+ export { Metric } from './Metric.js';
9
+ export { SpeedIndex } from './SpeedIndex.js';
10
+ export * as TBTUtils from './TBTUtils.js';
11
+ export { TotalBlockingTime } from './TotalBlockingTime.js';
12
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/metrics.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAU7B,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAC,MAAM,EAAS,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n/**\n * @license\n * Copyright 2024 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type * as Lantern from '../types/lantern.js';\n\nexport {FirstContentfulPaint} from './FirstContentfulPaint.js';\nexport {Interactive} from './Interactive.js';\nexport {LargestContentfulPaint} from './LargestContentfulPaint.js';\nexport {MaxPotentialFID} from './MaxPotentialFID.js';\nexport {Metric, Extras} from './Metric.js';\nexport {SpeedIndex} from './SpeedIndex.js';\nexport * as TBTUtils from './TBTUtils.js';\nexport {TotalBlockingTime} from './TotalBlockingTime.js';\n\nexport type Result<T = Lantern.AnyNetworkObject> = Lantern.Metrics.Result<T>;\n"]}
@@ -0,0 +1,26 @@
1
+ import type * as Lantern from '../types/lantern.js';
2
+ import { TCPConnection } from './TCPConnection.js';
3
+ export declare class ConnectionPool {
4
+ _options: Required<Lantern.Simulation.Options>;
5
+ _records: Lantern.NetworkRequest[];
6
+ _connectionsByOrigin: Map<string, TCPConnection[]>;
7
+ _connectionsByRequest: Map<Lantern.NetworkRequest, TCPConnection>;
8
+ _connectionsInUse: Set<TCPConnection>;
9
+ _connectionReusedByRequestId: Map<string, boolean>;
10
+ constructor(records: Lantern.NetworkRequest[], options: Required<Lantern.Simulation.Options>);
11
+ connectionsInUse(): TCPConnection[];
12
+ _initializeConnections(): void;
13
+ _findAvailableConnectionWithLargestCongestionWindow(connections: TCPConnection[]): TCPConnection | null;
14
+ /**
15
+ * This method finds an available connection to the origin specified by the network request or null
16
+ * if no connection was available. If returned, connection will not be available for other network
17
+ * records until release is called.
18
+ */
19
+ acquire(request: Lantern.NetworkRequest): TCPConnection | null;
20
+ /**
21
+ * Return the connection currently being used to fetch a request. If no connection
22
+ * currently being used for this request, an error will be thrown.
23
+ */
24
+ acquireActiveConnectionFromRequest(request: Lantern.NetworkRequest): TCPConnection;
25
+ release(request: Lantern.NetworkRequest): void;
26
+ }