@paulirish/trace_engine 0.0.25 → 0.0.27

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 (176) 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 +36 -2
  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/EnhancedTracesHandler.d.ts +46 -0
  16. package/models/trace/handlers/EnhancedTracesHandler.js +137 -0
  17. package/models/trace/handlers/EnhancedTracesHandler.js.map +1 -0
  18. package/models/trace/handlers/LayoutShiftsHandler.d.ts +1 -1
  19. package/models/trace/handlers/LayoutShiftsHandler.js +1 -1
  20. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  21. package/models/trace/handlers/ModelHandlers.d.ts +1 -0
  22. package/models/trace/handlers/ModelHandlers.js +1 -0
  23. package/models/trace/handlers/ModelHandlers.js.map +1 -1
  24. package/models/trace/handlers/UserInteractionsHandler.d.ts +6 -0
  25. package/models/trace/handlers/UserInteractionsHandler.js +15 -0
  26. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  27. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  28. package/models/trace/handlers/handlers-tsconfig.json +1 -1
  29. package/models/trace/helpers/Timing.d.ts +0 -6
  30. package/models/trace/helpers/Timing.js +0 -76
  31. package/models/trace/helpers/Timing.js.map +1 -1
  32. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  33. package/models/trace/helpers/helpers-tsconfig.json +0 -1
  34. package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  35. package/models/trace/insights/insights-tsconfig.json +0 -1
  36. package/models/trace/lantern/BaseNode.d.ts +91 -0
  37. package/models/trace/lantern/BaseNode.js +268 -0
  38. package/models/trace/lantern/BaseNode.js.map +1 -0
  39. package/models/trace/lantern/CPUNode.d.ts +24 -0
  40. package/models/trace/lantern/CPUNode.js +64 -0
  41. package/models/trace/lantern/CPUNode.js.map +1 -0
  42. package/models/trace/lantern/LanternError.d.ts +3 -0
  43. package/models/trace/lantern/LanternError.js +7 -0
  44. package/models/trace/lantern/LanternError.js.map +1 -0
  45. package/models/trace/lantern/MetricsModule.d.ts +11 -0
  46. package/models/trace/lantern/MetricsModule.js +14 -0
  47. package/models/trace/lantern/MetricsModule.js.map +1 -0
  48. package/models/trace/lantern/NetworkNode.d.ts +22 -0
  49. package/models/trace/lantern/NetworkNode.js +83 -0
  50. package/models/trace/lantern/NetworkNode.js.map +1 -0
  51. package/models/trace/lantern/PageDependencyGraph.d.ts +43 -0
  52. package/models/trace/lantern/PageDependencyGraph.js +509 -0
  53. package/models/trace/lantern/PageDependencyGraph.js.map +1 -0
  54. package/models/trace/lantern/SimulationModule.d.ts +17 -0
  55. package/models/trace/lantern/SimulationModule.js +13 -0
  56. package/models/trace/lantern/SimulationModule.js.map +1 -0
  57. package/models/trace/lantern/bundle-tsconfig.json +1 -0
  58. package/models/trace/lantern/core/LanternError.d.ts +3 -0
  59. package/models/trace/lantern/core/LanternError.js +7 -0
  60. package/models/trace/lantern/core/LanternError.js.map +1 -0
  61. package/models/trace/lantern/core/NetworkAnalyzer.d.ts +112 -0
  62. package/models/trace/lantern/core/NetworkAnalyzer.js +486 -0
  63. package/models/trace/lantern/core/NetworkAnalyzer.js.map +1 -0
  64. package/models/trace/lantern/core/bundle-tsconfig.json +1 -0
  65. package/models/trace/lantern/core/core-tsconfig.json +43 -0
  66. package/models/trace/lantern/core/core.d.ts +2 -0
  67. package/models/trace/lantern/core/core.js +6 -0
  68. package/models/trace/lantern/core/core.js.map +1 -0
  69. package/models/trace/lantern/core/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  70. package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  71. package/models/trace/lantern/graph/BaseNode.d.ts +91 -0
  72. package/models/trace/lantern/graph/BaseNode.js +268 -0
  73. package/models/trace/lantern/graph/BaseNode.js.map +1 -0
  74. package/models/trace/lantern/graph/CPUNode.d.ts +24 -0
  75. package/models/trace/lantern/graph/CPUNode.js +64 -0
  76. package/models/trace/lantern/graph/CPUNode.js.map +1 -0
  77. package/models/trace/lantern/graph/NetworkNode.d.ts +22 -0
  78. package/models/trace/lantern/graph/NetworkNode.js +83 -0
  79. package/models/trace/lantern/graph/NetworkNode.js.map +1 -0
  80. package/models/trace/lantern/graph/PageDependencyGraph.d.ts +43 -0
  81. package/models/trace/lantern/graph/PageDependencyGraph.js +509 -0
  82. package/models/trace/lantern/graph/PageDependencyGraph.js.map +1 -0
  83. package/models/trace/lantern/graph/bundle-tsconfig.json +1 -0
  84. package/models/trace/lantern/graph/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  85. package/models/trace/lantern/graph/graph-tsconfig.json +48 -0
  86. package/models/trace/lantern/graph/graph.d.ts +4 -0
  87. package/models/trace/lantern/graph/graph.js +8 -0
  88. package/models/trace/lantern/graph/graph.js.map +1 -0
  89. package/models/trace/lantern/lantern-tsconfig.json +53 -0
  90. package/models/trace/lantern/lantern.d.ts +6 -0
  91. package/models/trace/lantern/lantern.js +10 -0
  92. package/models/trace/lantern/lantern.js.map +1 -0
  93. package/models/trace/lantern/metrics/FirstContentfulPaint.d.ts +40 -0
  94. package/models/trace/lantern/metrics/FirstContentfulPaint.js +137 -0
  95. package/models/trace/lantern/metrics/FirstContentfulPaint.js.map +1 -0
  96. package/models/trace/lantern/metrics/Interactive.d.ts +12 -0
  97. package/models/trace/lantern/metrics/Interactive.js +67 -0
  98. package/models/trace/lantern/metrics/Interactive.js.map +1 -0
  99. package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +17 -0
  100. package/models/trace/lantern/metrics/LargestContentfulPaint.js +69 -0
  101. package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -0
  102. package/models/trace/lantern/metrics/MaxPotentialFID.d.ts +14 -0
  103. package/models/trace/lantern/metrics/MaxPotentialFID.js +48 -0
  104. package/models/trace/lantern/metrics/MaxPotentialFID.js.map +1 -0
  105. package/models/trace/lantern/metrics/Metric.d.ts +44 -0
  106. package/models/trace/lantern/metrics/Metric.js +70 -0
  107. package/models/trace/lantern/metrics/Metric.js.map +1 -0
  108. package/models/trace/lantern/metrics/SpeedIndex.d.ts +25 -0
  109. package/models/trace/lantern/metrics/SpeedIndex.js +101 -0
  110. package/models/trace/lantern/metrics/SpeedIndex.js.map +1 -0
  111. package/models/trace/lantern/metrics/TBTUtils.d.ts +31 -0
  112. package/models/trace/lantern/metrics/TBTUtils.js +65 -0
  113. package/models/trace/lantern/metrics/TBTUtils.js.map +1 -0
  114. package/models/trace/lantern/metrics/TotalBlockingTime.d.ts +16 -0
  115. package/models/trace/lantern/metrics/TotalBlockingTime.js +78 -0
  116. package/models/trace/lantern/metrics/TotalBlockingTime.js.map +1 -0
  117. package/models/trace/lantern/metrics/bundle-tsconfig.json +1 -0
  118. package/models/trace/lantern/metrics/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  119. package/models/trace/lantern/metrics/metrics-tsconfig.json +58 -0
  120. package/models/trace/lantern/metrics/metrics.d.ts +8 -0
  121. package/models/trace/lantern/metrics/metrics.js +12 -0
  122. package/models/trace/lantern/metrics/metrics.js.map +1 -0
  123. package/models/trace/lantern/simulation/ConnectionPool.d.ts +26 -0
  124. package/models/trace/lantern/simulation/ConnectionPool.js +116 -0
  125. package/models/trace/lantern/simulation/ConnectionPool.js.map +1 -0
  126. package/models/trace/lantern/simulation/Constants.d.ts +31 -0
  127. package/models/trace/lantern/simulation/Constants.js +43 -0
  128. package/models/trace/lantern/simulation/Constants.js.map +1 -0
  129. package/models/trace/lantern/simulation/DNSCache.d.ts +22 -0
  130. package/models/trace/lantern/simulation/DNSCache.js +48 -0
  131. package/models/trace/lantern/simulation/DNSCache.js.map +1 -0
  132. package/models/trace/lantern/simulation/NetworkAnalyzer.d.ts +112 -0
  133. package/models/trace/lantern/simulation/NetworkAnalyzer.js +486 -0
  134. package/models/trace/lantern/simulation/NetworkAnalyzer.js.map +1 -0
  135. package/models/trace/lantern/simulation/SimulationTimingMap.d.ts +69 -0
  136. package/models/trace/lantern/simulation/SimulationTimingMap.js +134 -0
  137. package/models/trace/lantern/simulation/SimulationTimingMap.js.map +1 -0
  138. package/models/trace/lantern/simulation/Simulator.d.ts +84 -0
  139. package/models/trace/lantern/simulation/Simulator.js +449 -0
  140. package/models/trace/lantern/simulation/Simulator.js.map +1 -0
  141. package/models/trace/lantern/simulation/TCPConnection.d.ts +48 -0
  142. package/models/trace/lantern/simulation/TCPConnection.js +158 -0
  143. package/models/trace/lantern/simulation/TCPConnection.js.map +1 -0
  144. package/models/trace/lantern/simulation/bundle-tsconfig.json +1 -0
  145. package/models/trace/lantern/simulation/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  146. package/models/trace/lantern/simulation/simulation-tsconfig.json +50 -0
  147. package/models/trace/lantern/simulation/simulation.d.ts +6 -0
  148. package/models/trace/lantern/simulation/simulation.js +10 -0
  149. package/models/trace/lantern/simulation/simulation.js.map +1 -0
  150. package/models/trace/lantern/types/bundle-tsconfig.json +1 -0
  151. package/models/trace/lantern/types/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
  152. package/models/trace/lantern/types/lantern.d.ts +199 -0
  153. package/models/trace/lantern/types/lantern.js +24 -0
  154. package/models/trace/lantern/types/lantern.js.map +1 -0
  155. package/models/trace/lantern/types/types-tsconfig.json +42 -0
  156. package/models/trace/lantern/types/types.d.ts +1 -0
  157. package/models/trace/lantern/types/types.js +5 -0
  158. package/models/trace/lantern/types/types.js.map +1 -0
  159. package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  160. package/models/trace/root-causes/root-causes-tsconfig.json +0 -1
  161. package/models/trace/trace-tsconfig.json +4 -1
  162. package/models/trace/trace.d.ts +3 -1
  163. package/models/trace/trace.js +3 -1
  164. package/models/trace/trace.js.map +1 -1
  165. package/models/trace/types/Extensions.d.ts +2 -3
  166. package/models/trace/types/Extensions.js +2 -11
  167. package/models/trace/types/Extensions.js.map +1 -1
  168. package/models/trace/types/File.d.ts +1 -0
  169. package/models/trace/types/File.js.map +1 -1
  170. package/models/trace/types/TraceEvents.d.ts +49 -0
  171. package/models/trace/types/TraceEvents.js +33 -0
  172. package/models/trace/types/TraceEvents.js.map +1 -1
  173. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
  174. package/models/trace/types/types-tsconfig.json +0 -1
  175. package/package.json +1 -1
  176. package/PAUL.readme.md +0 -5
@@ -0,0 +1,44 @@
1
+ import * as Graph from '../graph/graph.js';
2
+ import type * as Simulation from '../simulation/simulation.js';
3
+ import type * as Types from '../types/types.js';
4
+ export interface MetricComputationDataInput {
5
+ simulator: Simulation.Simulator;
6
+ graph: Graph.Node<unknown>;
7
+ processedNavigation: Types.Simulation.ProcessedNavigation;
8
+ }
9
+ export interface MetricCoefficients {
10
+ intercept: number;
11
+ optimistic: number;
12
+ pessimistic: number;
13
+ }
14
+ export interface MetricResult<T = Types.AnyNetworkObject> {
15
+ timing: number;
16
+ timestamp?: never;
17
+ optimisticEstimate: Simulation.Result<T>;
18
+ pessimisticEstimate: Simulation.Result<T>;
19
+ optimisticGraph: Graph.Node<T>;
20
+ pessimisticGraph: Graph.Node;
21
+ }
22
+ export interface Extras {
23
+ optimistic: boolean;
24
+ fcpResult?: MetricResult;
25
+ lcpResult?: MetricResult;
26
+ interactiveResult?: MetricResult;
27
+ observedSpeedIndex?: number;
28
+ }
29
+ declare class Metric {
30
+ static getScriptUrls(dependencyGraph: Graph.Node, treatNodeAsRenderBlocking?: (node: Graph.NetworkNode) => boolean): Set<string>;
31
+ static get coefficients(): MetricCoefficients;
32
+ /**
33
+ * Returns the coefficients, scaled by the throttling settings if needed by the metric.
34
+ * Some lantern metrics (speed-index) use components in their estimate that are not
35
+ * from the simulator. In this case, we need to adjust the coefficients as the target throttling
36
+ * settings change.
37
+ */
38
+ static getScaledCoefficients(rttMs: number): MetricCoefficients;
39
+ static getOptimisticGraph(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node;
40
+ static getPessimisticGraph(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node;
41
+ static getEstimateFromSimulation(simulationResult: Simulation.Result, extras: Extras): Simulation.Result;
42
+ static compute(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<MetricResult>;
43
+ }
44
+ export { Metric };
@@ -0,0 +1,70 @@
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 * as Graph from '../graph/graph.js';
5
+ class Metric {
6
+ static getScriptUrls(dependencyGraph, treatNodeAsRenderBlocking) {
7
+ const scriptUrls = new Set();
8
+ dependencyGraph.traverse(node => {
9
+ if (node.type !== Graph.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
+ static get coefficients() {
22
+ throw new Error('coefficients unimplemented!');
23
+ }
24
+ /* eslint-disable @typescript-eslint/no-unused-vars */
25
+ /**
26
+ * Returns the coefficients, scaled by the throttling settings if needed by the metric.
27
+ * Some lantern metrics (speed-index) use components in their estimate that are not
28
+ * from the simulator. In this case, we need to adjust the coefficients as the target throttling
29
+ * settings change.
30
+ */
31
+ static getScaledCoefficients(rttMs) {
32
+ return this.coefficients;
33
+ }
34
+ static getOptimisticGraph(dependencyGraph, processedNavigation) {
35
+ throw new Error('Optimistic graph unimplemented!');
36
+ }
37
+ static getPessimisticGraph(dependencyGraph, processedNavigation) {
38
+ throw new Error('Pessmistic graph unimplemented!');
39
+ }
40
+ static getEstimateFromSimulation(simulationResult, extras) {
41
+ return simulationResult;
42
+ }
43
+ /* eslint-enable @typescript-eslint/no-unused-vars */
44
+ static async compute(data, extras) {
45
+ const { simulator, graph, processedNavigation } = data;
46
+ const metricName = this.name.replace('Lantern', '');
47
+ const optimisticGraph = this.getOptimisticGraph(graph, processedNavigation);
48
+ const pessimisticGraph = this.getPessimisticGraph(graph, processedNavigation);
49
+ let simulateOptions = { label: `optimistic${metricName}` };
50
+ const optimisticSimulation = simulator.simulate(optimisticGraph, simulateOptions);
51
+ simulateOptions = { label: `pessimistic${metricName}` };
52
+ const pessimisticSimulation = simulator.simulate(pessimisticGraph, simulateOptions);
53
+ const optimisticEstimate = this.getEstimateFromSimulation(optimisticSimulation, { ...extras, optimistic: true });
54
+ const pessimisticEstimate = this.getEstimateFromSimulation(pessimisticSimulation, { ...extras, optimistic: false });
55
+ const coefficients = this.getScaledCoefficients(simulator.rtt);
56
+ // Estimates under 1s don't really follow the normal curve fit, minimize the impact of the intercept
57
+ const interceptMultiplier = coefficients.intercept > 0 ? Math.min(1, optimisticEstimate.timeInMs / 1000) : 1;
58
+ const timing = coefficients.intercept * interceptMultiplier +
59
+ coefficients.optimistic * optimisticEstimate.timeInMs + coefficients.pessimistic * pessimisticEstimate.timeInMs;
60
+ return {
61
+ timing,
62
+ optimisticEstimate,
63
+ pessimisticEstimate,
64
+ optimisticGraph,
65
+ pessimisticGraph,
66
+ };
67
+ }
68
+ }
69
+ export { Metric };
70
+ //# 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,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAiC3C,MAAM,MAAM;IACV,MAAM,CAAC,aAAa,CAAC,eAA2B,EAAE,yBAAgE;QAEhH,MAAM,UAAU,GAAgB,IAAI,GAAG,EAAE,CAAC;QAE1C,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;gBAC/C,OAAO;YACT,CAAC;YACD,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;gBAC3C,OAAO;YACT,CAAC;YACD,IAAI,yBAAyB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,KAAK,YAAY;QACrB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;IAED,sDAAsD;IAEtD;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAa;QACxC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,eAA2B,EAAE,mBAAyD;QAE9G,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,mBAAmB,CAA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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 * as Graph from '../graph/graph.js';\nimport type * as Simulation from '../simulation/simulation.js';\nimport type * as Types from '../types/types.js';\n\nexport interface MetricComputationDataInput {\n simulator: Simulation.Simulator;\n graph: Graph.Node<unknown>;\n processedNavigation: Types.Simulation.ProcessedNavigation;\n}\n\nexport interface MetricCoefficients {\n intercept: number;\n optimistic: number;\n pessimistic: number;\n}\n\nexport interface MetricResult<T = Types.AnyNetworkObject> {\n timing: number;\n timestamp?: never;\n optimisticEstimate: Simulation.Result<T>;\n pessimisticEstimate: Simulation.Result<T>;\n optimisticGraph: Graph.Node<T>;\n pessimisticGraph: Graph.Node;\n}\n\nexport interface Extras {\n optimistic: boolean;\n fcpResult?: MetricResult;\n lcpResult?: MetricResult;\n interactiveResult?: MetricResult;\n observedSpeedIndex?: number;\n}\n\nclass Metric {\n static getScriptUrls(dependencyGraph: Graph.Node, treatNodeAsRenderBlocking?: (node: Graph.NetworkNode) => boolean):\n Set<string> {\n const scriptUrls: Set<string> = new Set();\n\n dependencyGraph.traverse(node => {\n if (node.type !== Graph.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 static get coefficients(): 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): MetricCoefficients {\n return this.coefficients;\n }\n\n static getOptimisticGraph(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation):\n Graph.Node {\n throw new Error('Optimistic graph unimplemented!');\n }\n\n static getPessimisticGraph(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation):\n Graph.Node {\n throw new Error('Pessmistic graph unimplemented!');\n }\n\n static getEstimateFromSimulation(simulationResult: Simulation.Result, extras: Extras): Simulation.Result {\n return simulationResult;\n }\n\n /* eslint-enable @typescript-eslint/no-unused-vars */\n\n static async compute(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<MetricResult> {\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 * as Graph from '../graph/graph.js';
2
+ import type * as Simulation from '../simulation/simulation.js';
3
+ import { type Extras, Metric, type MetricCoefficients, type MetricComputationDataInput, type MetricResult } from './Metric.js';
4
+ declare class SpeedIndex extends Metric {
5
+ static get coefficients(): MetricCoefficients;
6
+ static getScaledCoefficients(rttMs: number): MetricCoefficients;
7
+ static getOptimisticGraph(dependencyGraph: Graph.Node): Graph.Node;
8
+ static getPessimisticGraph(dependencyGraph: Graph.Node): Graph.Node;
9
+ static getEstimateFromSimulation(simulationResult: Simulation.Result, extras: Extras): Simulation.Result;
10
+ static compute(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<MetricResult>;
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: Simulation.Result['nodeTimings'], fcpTimeInMs: number): number;
24
+ }
25
+ export { SpeedIndex };
@@ -0,0 +1,101 @@
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 * as Graph from '../graph/graph.js';
5
+ import { Metric, } from './Metric.js';
6
+ const mobileSlow4GRtt = 150;
7
+ class SpeedIndex extends Metric {
8
+ static get coefficients() {
9
+ return {
10
+ // Note that the optimistic estimate is based on the real observed speed index rather than a
11
+ // real lantern graph (and the final estimate will be Math.max(FCP, Speed Index)).
12
+ intercept: 0,
13
+ optimistic: 1.4,
14
+ pessimistic: 0.4,
15
+ };
16
+ }
17
+ static getScaledCoefficients(rttMs) {
18
+ // We want to scale our default coefficients based on the speed of the connection.
19
+ // We will linearly interpolate coefficients for the passed-in rttMs based on two pre-determined points:
20
+ // 1. Baseline point of 30 ms RTT where Speed Index should be a ~50/50 blend of optimistic/pessimistic.
21
+ // 30 ms was based on a typical home WiFi connection's actual RTT.
22
+ // Coefficients here follow from the fact that the optimistic estimate should be very close
23
+ // to reality at this connection speed and the pessimistic estimate compensates for minor
24
+ // connection speed differences.
25
+ // 2. Default throttled point of 150 ms RTT where the default coefficients have been determined to be most accurate.
26
+ // Coefficients here were determined through thorough analysis and linear regression on the
27
+ // lantern test data set. See core/scripts/test-lantern.sh for more detail.
28
+ // While the coefficients haven't been analyzed at the interpolated points, it's our current best effort.
29
+ const defaultCoefficients = this.coefficients;
30
+ const defaultRttExcess = mobileSlow4GRtt - 30;
31
+ const multiplier = Math.max((rttMs - 30) / defaultRttExcess, 0);
32
+ return {
33
+ intercept: defaultCoefficients.intercept * multiplier,
34
+ optimistic: 0.5 + (defaultCoefficients.optimistic - 0.5) * multiplier,
35
+ pessimistic: 0.5 + (defaultCoefficients.pessimistic - 0.5) * multiplier,
36
+ };
37
+ }
38
+ static getOptimisticGraph(dependencyGraph) {
39
+ return dependencyGraph;
40
+ }
41
+ static getPessimisticGraph(dependencyGraph) {
42
+ return dependencyGraph;
43
+ }
44
+ static getEstimateFromSimulation(simulationResult, extras) {
45
+ if (!extras.fcpResult) {
46
+ throw new Error('missing fcpResult');
47
+ }
48
+ if (extras.observedSpeedIndex === undefined) {
49
+ throw new Error('missing observedSpeedIndex');
50
+ }
51
+ const fcpTimeInMs = extras.fcpResult.pessimisticEstimate.timeInMs;
52
+ const estimate = extras.optimistic ?
53
+ extras.observedSpeedIndex :
54
+ SpeedIndex.computeLayoutBasedSpeedIndex(simulationResult.nodeTimings, fcpTimeInMs);
55
+ return {
56
+ timeInMs: estimate,
57
+ nodeTimings: simulationResult.nodeTimings,
58
+ };
59
+ }
60
+ static async compute(data, extras) {
61
+ const fcpResult = extras?.fcpResult;
62
+ if (!fcpResult) {
63
+ throw new Error('FCP is required to calculate the SpeedIndex metric');
64
+ }
65
+ const metricResult = await super.compute(data, extras);
66
+ metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
67
+ return metricResult;
68
+ }
69
+ /**
70
+ * Approximate speed index using layout events from the simulated node timings.
71
+ * The layout-based speed index is the weighted average of the endTime of CPU nodes that contained
72
+ * a 'Layout' task. log(duration) is used as the weight to stand for "significance" to the page.
73
+ *
74
+ * If no layout events can be found or the endTime of a CPU task is too early, FCP is used instead.
75
+ *
76
+ * This approach was determined after evaluating the accuracy/complexity tradeoff of many
77
+ * different methods. Read more in the evaluation doc.
78
+ *
79
+ * @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
80
+ */
81
+ static computeLayoutBasedSpeedIndex(nodeTimings, fcpTimeInMs) {
82
+ const layoutWeights = [];
83
+ for (const [node, timing] of nodeTimings.entries()) {
84
+ if (node.type !== Graph.BaseNode.types.CPU) {
85
+ continue;
86
+ }
87
+ if (node.childEvents.some(x => x.name === 'Layout')) {
88
+ const timingWeight = Math.max(Math.log2(timing.endTime - timing.startTime), 0);
89
+ layoutWeights.push({ time: timing.endTime, weight: timingWeight });
90
+ }
91
+ }
92
+ const totalWeightedTime = layoutWeights.map(evt => evt.weight * Math.max(evt.time, fcpTimeInMs)).reduce((a, b) => a + b, 0);
93
+ const totalWeight = layoutWeights.map(evt => evt.weight).reduce((a, b) => a + b, 0);
94
+ if (!totalWeight) {
95
+ return fcpTimeInMs;
96
+ }
97
+ return totalWeightedTime / totalWeight;
98
+ }
99
+ }
100
+ export { SpeedIndex };
101
+ //# 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,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAEL,MAAM,GAIP,MAAM,aAAa,CAAC;AAErB,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,UAAW,SAAQ,MAAM;IAC7B,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;QACjD,kFAAkF;QAClF,wGAAwG;QACxG,yGAAyG;QACzG,uEAAuE;QACvE,gGAAgG;QAChG,8FAA8F;QAC9F,qCAAqC;QACrC,sHAAsH;QACtH,gGAAgG;QAChG,gFAAgF;QAChF,yGAAyG;QACzG,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,CAAC;QAC9C,MAAM,gBAAgB,GAAG,eAAe,GAAG,EAAE,CAAC;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,CAAC,CAAC;QAEhE,OAAO;YACL,SAAS,EAAE,mBAAmB,CAAC,SAAS,GAAG,UAAU;YACrD,UAAU,EAAE,GAAG,GAAG,CAAC,mBAAmB,CAAC,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AAC,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 * as Graph from '../graph/graph.js';\nimport type * as Simulation from '../simulation/simulation.js';\n\nimport {\n type Extras,\n Metric,\n type MetricCoefficients,\n type MetricComputationDataInput,\n type MetricResult,\n} from './Metric.js';\n\nconst mobileSlow4GRtt = 150;\n\nclass SpeedIndex extends Metric {\n static override get coefficients(): 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): MetricCoefficients {\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: Graph.Node): Graph.Node {\n return dependencyGraph;\n }\n\n static override getPessimisticGraph(dependencyGraph: Graph.Node): Graph.Node {\n return dependencyGraph;\n }\n\n static override getEstimateFromSimulation(simulationResult: Simulation.Result, extras: Extras): 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(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>):\n Promise<MetricResult> {\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: Simulation.Result['nodeTimings'], fcpTimeInMs: number): number {\n const layoutWeights: Array<{time: number, weight: number}> = [];\n for (const [node, timing] of nodeTimings.entries()) {\n if (node.type !== Graph.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,WAAmB,EAAE,SAAiB,EAC7F,aAA8D;IAChE,IAAI,SAAS,GAAG,uBAAuB,CAAC;IAExC,gFAAgF;IAChF,qCAAqC;IACrC,EAAE;IACF,mFAAmF;IACnF,0EAA0E;IAC1E,EAAE;IACF,qFAAqF;IACrF,IAAI,aAAa,EAAE,CAAC;QAClB,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,KAAK,CAAC,QAAQ,GAAG,SAAS,EAAE,CAAC;QAC/B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,KAAK,CAAC,GAAG,GAAG,WAAW,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC;QAC5B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,yFAAyF;IACzF,uFAAuF;IACvF,4CAA4C;IAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAClD,MAAM,eAAe,GAAG,UAAU,GAAG,YAAY,CAAC;IAClD,IAAI,eAAe,GAAG,SAAS,EAAE,CAAC;QAChC,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,eAAe,GAAG,SAAS,CAAC;AACrC,CAAC;AAED,SAAS,0BAA0B,CAC/B,cAAqE,EAAE,WAAmB,EAC1F,SAAiB;IACnB,IAAI,SAAS,IAAI,WAAW,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACnC,eAAe,IAAI,0BAA0B,CAAC,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 * as Graph from '../graph/graph.js';
2
+ import type * as Simulation from '../simulation/simulation.js';
3
+ import { type Extras, Metric, type MetricCoefficients, type MetricComputationDataInput, type MetricResult } from './Metric.js';
4
+ declare class TotalBlockingTime extends Metric {
5
+ static get coefficients(): MetricCoefficients;
6
+ static getOptimisticGraph(dependencyGraph: Graph.Node): Graph.Node;
7
+ static getPessimisticGraph(dependencyGraph: Graph.Node): Graph.Node;
8
+ static getEstimateFromSimulation(simulation: Simulation.Result, extras: Extras): Simulation.Result;
9
+ static compute(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<MetricResult>;
10
+ static getTopLevelEvents(nodeTimings: Simulation.Result['nodeTimings'], minDurationMs: number): {
11
+ start: number;
12
+ end: number;
13
+ duration: number;
14
+ }[];
15
+ }
16
+ export { TotalBlockingTime };
@@ -0,0 +1,78 @@
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 * as Graph from '../graph/graph.js';
5
+ import { Metric, } from './Metric.js';
6
+ import { BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime } from './TBTUtils.js';
7
+ class TotalBlockingTime extends Metric {
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
+ if (!extras.interactiveResult) {
26
+ throw new Error('missing interactiveResult');
27
+ }
28
+ // Intentionally use the opposite FCP estimate. A pessimistic FCP is higher than equal to an
29
+ // optimistic FCP, which means potentially more tasks are excluded from the Total Blocking Time
30
+ // computation. So a more pessimistic FCP gives a more optimistic Total Blocking Time for the
31
+ // same work.
32
+ const fcpTimeInMs = extras.optimistic ? extras.fcpResult.pessimisticEstimate.timeInMs :
33
+ extras.fcpResult.optimisticEstimate.timeInMs;
34
+ // Similarly, we always have pessimistic TTI >= optimistic TTI. Therefore, picking optimistic
35
+ // TTI means our window of interest is smaller and thus potentially more tasks are excluded from
36
+ // Total Blocking Time computation, yielding a lower (more optimistic) Total Blocking Time value
37
+ // for the same work.
38
+ const interactiveTimeMs = extras.optimistic ? extras.interactiveResult.optimisticEstimate.timeInMs :
39
+ extras.interactiveResult.pessimisticEstimate.timeInMs;
40
+ const minDurationMs = BLOCKING_TIME_THRESHOLD;
41
+ const events = TotalBlockingTime.getTopLevelEvents(simulation.nodeTimings, minDurationMs);
42
+ return {
43
+ timeInMs: calculateSumOfBlockingTime(events, fcpTimeInMs, interactiveTimeMs),
44
+ nodeTimings: simulation.nodeTimings,
45
+ };
46
+ }
47
+ static async compute(data, extras) {
48
+ const fcpResult = extras?.fcpResult;
49
+ if (!fcpResult) {
50
+ throw new Error('FCP is required to calculate the TBT metric');
51
+ }
52
+ const interactiveResult = extras?.fcpResult;
53
+ if (!interactiveResult) {
54
+ throw new Error('Interactive is required to calculate the TBT metric');
55
+ }
56
+ return super.compute(data, extras);
57
+ }
58
+ static getTopLevelEvents(nodeTimings, minDurationMs) {
59
+ const events = [];
60
+ for (const [node, timing] of nodeTimings.entries()) {
61
+ if (node.type !== Graph.BaseNode.types.CPU) {
62
+ continue;
63
+ }
64
+ // Filtering out events below minimum duration.
65
+ if (timing.duration < minDurationMs) {
66
+ continue;
67
+ }
68
+ events.push({
69
+ start: timing.startTime,
70
+ end: timing.endTime,
71
+ duration: timing.duration,
72
+ });
73
+ }
74
+ return events;
75
+ }
76
+ }
77
+ export { TotalBlockingTime };
78
+ //# sourceMappingURL=TotalBlockingTime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TotalBlockingTime.js","sourceRoot":"","sources":["../../../../../../../../front_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K,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 * as Graph from '../graph/graph.js';\nimport type * as Simulation from '../simulation/simulation.js';\n\nimport {\n type Extras,\n Metric,\n type MetricCoefficients,\n type MetricComputationDataInput,\n type MetricResult,\n} from './Metric.js';\nimport {BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime} from './TBTUtils.js';\n\nclass TotalBlockingTime extends Metric {\n static override get coefficients(): MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n static override getOptimisticGraph(dependencyGraph: Graph.Node): Graph.Node {\n return dependencyGraph;\n }\n\n static override getPessimisticGraph(dependencyGraph: Graph.Node): Graph.Node {\n return dependencyGraph;\n }\n\n static override getEstimateFromSimulation(simulation: Simulation.Result, extras: Extras): 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(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>):\n Promise<MetricResult> {\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: 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 !== Graph.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 @@
1
+ {"compilerOptions":{"composite":true,"outDir":".","baseUrl":".","rootDir":"../../../../../../../../front_end/models/trace/lantern/metrics"},"files":["../../../../../../../../front_end/models/trace/lantern/metrics/metrics.ts"],"references":[{"path":"./metrics-tsconfig.json"}]}
@@ -0,0 +1,42 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "outDir": ".",
22
+ "rootDir": "../../../../../../../../front_end/models/trace/lantern/metrics",
23
+ "skipLibCheck": true,
24
+ "sourceMap": true,
25
+ "strict": true,
26
+ "target": "esnext",
27
+ "tsBuildInfoFile": "devtools_entrypoint-bundle-typescript-tsconfig.json.tsbuildinfo",
28
+ "typeRoots": [],
29
+ "useUnknownInCatchVariables": false
30
+ },
31
+ "files": [
32
+ "../../../../../../../../front_end/models/trace/lantern/metrics/metrics.ts",
33
+ "../../../../../../../../front_end/legacy/legacy-defs.d.ts",
34
+ "../../../../../../../../front_end/global_typings/global_defs.d.ts",
35
+ "../../../../../../../../node_modules/@types/filesystem/index.d.ts"
36
+ ],
37
+ "references": [
38
+ {
39
+ "path": "./metrics-tsconfig.json"
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "outDir": ".",
22
+ "rootDir": "../../../../../../../../front_end/models/trace/lantern/metrics",
23
+ "skipLibCheck": true,
24
+ "sourceMap": true,
25
+ "strict": true,
26
+ "target": "esnext",
27
+ "tsBuildInfoFile": "metrics-tsconfig.json.tsbuildinfo",
28
+ "typeRoots": [],
29
+ "useUnknownInCatchVariables": false
30
+ },
31
+ "files": [
32
+ "../../../../../../../../front_end/models/trace/lantern/metrics/FirstContentfulPaint.ts",
33
+ "../../../../../../../../front_end/models/trace/lantern/metrics/Interactive.ts",
34
+ "../../../../../../../../front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts",
35
+ "../../../../../../../../front_end/models/trace/lantern/metrics/MaxPotentialFID.ts",
36
+ "../../../../../../../../front_end/models/trace/lantern/metrics/Metric.ts",
37
+ "../../../../../../../../front_end/models/trace/lantern/metrics/SpeedIndex.ts",
38
+ "../../../../../../../../front_end/models/trace/lantern/metrics/TBTUtils.ts",
39
+ "../../../../../../../../front_end/models/trace/lantern/metrics/TotalBlockingTime.ts",
40
+ "../../../../../../../../front_end/legacy/legacy-defs.d.ts",
41
+ "../../../../../../../../front_end/global_typings/global_defs.d.ts",
42
+ "../../../../../../../../node_modules/@types/filesystem/index.d.ts"
43
+ ],
44
+ "references": [
45
+ {
46
+ "path": "../core/bundle-tsconfig.json"
47
+ },
48
+ {
49
+ "path": "../graph/bundle-tsconfig.json"
50
+ },
51
+ {
52
+ "path": "../simulation/bundle-tsconfig.json"
53
+ },
54
+ {
55
+ "path": "../types/bundle-tsconfig.json"
56
+ }
57
+ ]
58
+ }
@@ -0,0 +1,8 @@
1
+ export * from './FirstContentfulPaint.js';
2
+ export * from './Interactive.js';
3
+ export * from './LargestContentfulPaint.js';
4
+ export * from './MaxPotentialFID.js';
5
+ export * from './Metric.js';
6
+ export * from './SpeedIndex.js';
7
+ export * from './TotalBlockingTime.js';
8
+ export * as TBTUtils from './TBTUtils.js';
@@ -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 * from './FirstContentfulPaint.js';
5
+ export * from './Interactive.js';
6
+ export * from './LargestContentfulPaint.js';
7
+ export * from './MaxPotentialFID.js';
8
+ export * from './Metric.js';
9
+ export * from './SpeedIndex.js';
10
+ export * from './TotalBlockingTime.js';
11
+ export * as TBTUtils from './TBTUtils.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;AAE7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,eAAe,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\nexport * from './FirstContentfulPaint.js';\nexport * from './Interactive.js';\nexport * from './LargestContentfulPaint.js';\nexport * from './MaxPotentialFID.js';\nexport * from './Metric.js';\nexport * from './SpeedIndex.js';\nexport * from './TotalBlockingTime.js';\nexport * as TBTUtils from './TBTUtils.js';\n"]}