@paulirish/trace_engine 0.0.41 → 0.0.42

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/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/generated/protocol.d.ts +79 -3
  3. package/locales/en-US.json +222 -0
  4. package/locales/en-XL.json +222 -0
  5. package/models/cpu_profile/CPUProfileDataModel.d.ts +7 -0
  6. package/models/cpu_profile/CPUProfileDataModel.js +7 -0
  7. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  8. package/models/cpu_profile/ProfileTreeModel.d.ts +1 -1
  9. package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
  10. package/models/trace/LanternComputationData.d.ts +1 -1
  11. package/models/trace/LanternComputationData.js +7 -5
  12. package/models/trace/LanternComputationData.js.map +1 -1
  13. package/models/trace/Processor.d.ts +2 -16
  14. package/models/trace/Processor.js +6 -4
  15. package/models/trace/Processor.js.map +1 -1
  16. package/models/trace/extras/FilmStrip.d.ts +5 -5
  17. package/models/trace/extras/FilmStrip.js +2 -1
  18. package/models/trace/extras/FilmStrip.js.map +1 -1
  19. package/models/trace/extras/MainThreadActivity.d.ts +1 -1
  20. package/models/trace/extras/MainThreadActivity.js +3 -3
  21. package/models/trace/extras/MainThreadActivity.js.map +1 -1
  22. package/models/trace/extras/ThirdParties.d.ts +14 -13
  23. package/models/trace/extras/ThirdParties.js +51 -61
  24. package/models/trace/extras/ThirdParties.js.map +1 -1
  25. package/models/trace/extras/TimelineJSProfile.d.ts +1 -1
  26. package/models/trace/extras/TimelineJSProfile.js +9 -4
  27. package/models/trace/extras/TimelineJSProfile.js.map +1 -1
  28. package/models/trace/extras/TraceTree.d.ts +6 -6
  29. package/models/trace/extras/TraceTree.js +4 -1
  30. package/models/trace/extras/TraceTree.js.map +1 -1
  31. package/models/trace/handlers/AnimationFramesHandler.js +1 -1
  32. package/models/trace/handlers/AnimationFramesHandler.js.map +1 -1
  33. package/models/trace/handlers/ExtensionTraceDataHandler.js +8 -2
  34. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  35. package/models/trace/handlers/FlowsHandler.js.map +1 -1
  36. package/models/trace/handlers/FramesHandler.d.ts +12 -12
  37. package/models/trace/handlers/FramesHandler.js +3 -3
  38. package/models/trace/handlers/FramesHandler.js.map +1 -1
  39. package/models/trace/handlers/LayoutShiftsHandler.d.ts +2 -2
  40. package/models/trace/handlers/LayoutShiftsHandler.js +25 -16
  41. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  42. package/models/trace/handlers/MetaHandler.d.ts +2 -2
  43. package/models/trace/handlers/MetaHandler.js +18 -18
  44. package/models/trace/handlers/MetaHandler.js.map +1 -1
  45. package/models/trace/handlers/NetworkRequestsHandler.js +37 -38
  46. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  47. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +6 -6
  48. package/models/trace/handlers/PageLoadMetricsHandler.js +9 -9
  49. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
  50. package/models/trace/handlers/RendererHandler.js +3 -3
  51. package/models/trace/handlers/RendererHandler.js.map +1 -1
  52. package/models/trace/handlers/SamplesHandler.d.ts +1 -1
  53. package/models/trace/handlers/SamplesHandler.js +50 -42
  54. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  55. package/models/trace/handlers/ScreenshotsHandler.d.ts +6 -3
  56. package/models/trace/handlers/ScreenshotsHandler.js +21 -7
  57. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  58. package/models/trace/handlers/ServerTimingsHandler.js +4 -4
  59. package/models/trace/handlers/ServerTimingsHandler.js.map +1 -1
  60. package/models/trace/handlers/Threads.js +3 -4
  61. package/models/trace/handlers/Threads.js.map +1 -1
  62. package/models/trace/handlers/UserInteractionsHandler.d.ts +2 -2
  63. package/models/trace/handlers/UserInteractionsHandler.js +12 -12
  64. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
  65. package/models/trace/handlers/WarningsHandler.d.ts +2 -2
  66. package/models/trace/handlers/WarningsHandler.js +2 -2
  67. package/models/trace/handlers/WarningsHandler.js.map +1 -1
  68. package/models/trace/handlers/helpers.d.ts +3 -3
  69. package/models/trace/handlers/helpers.js +16 -19
  70. package/models/trace/handlers/helpers.js.map +1 -1
  71. package/models/trace/handlers/types.d.ts +1 -1
  72. package/models/trace/handlers/types.js.map +1 -1
  73. package/models/trace/helpers/SamplesIntegrator.js +52 -13
  74. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  75. package/models/trace/helpers/Timing.d.ts +23 -23
  76. package/models/trace/helpers/Timing.js +11 -11
  77. package/models/trace/helpers/Timing.js.map +1 -1
  78. package/models/trace/helpers/Trace.d.ts +14 -13
  79. package/models/trace/helpers/Trace.js +10 -4
  80. package/models/trace/helpers/Trace.js.map +1 -1
  81. package/models/trace/helpers/TreeHelpers.d.ts +2 -2
  82. package/models/trace/helpers/TreeHelpers.js +4 -4
  83. package/models/trace/helpers/TreeHelpers.js.map +1 -1
  84. package/models/trace/insights/CLSCulprits.d.ts +44 -1
  85. package/models/trace/insights/CLSCulprits.js +44 -2
  86. package/models/trace/insights/CLSCulprits.js.map +1 -1
  87. package/models/trace/insights/Common.d.ts +11 -7
  88. package/models/trace/insights/Common.js +85 -26
  89. package/models/trace/insights/Common.js.map +1 -1
  90. package/models/trace/insights/DOMSize.d.ts +26 -1
  91. package/models/trace/insights/DOMSize.js +44 -7
  92. package/models/trace/insights/DOMSize.js.map +1 -1
  93. package/models/trace/insights/DocumentLatency.d.ts +50 -3
  94. package/models/trace/insights/DocumentLatency.js +51 -4
  95. package/models/trace/insights/DocumentLatency.js.map +1 -1
  96. package/models/trace/insights/FontDisplay.d.ts +8 -2
  97. package/models/trace/insights/FontDisplay.js +10 -4
  98. package/models/trace/insights/FontDisplay.js.map +1 -1
  99. package/models/trace/insights/ForcedReflow.d.ts +30 -0
  100. package/models/trace/insights/ForcedReflow.js +181 -0
  101. package/models/trace/insights/ForcedReflow.js.map +1 -0
  102. package/models/trace/insights/ImageDelivery.d.ts +15 -1
  103. package/models/trace/insights/ImageDelivery.js +21 -1
  104. package/models/trace/insights/ImageDelivery.js.map +1 -1
  105. package/models/trace/insights/InteractionToNextPaint.d.ts +26 -1
  106. package/models/trace/insights/InteractionToNextPaint.js +27 -1
  107. package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
  108. package/models/trace/insights/LCPDiscovery.d.ts +38 -2
  109. package/models/trace/insights/LCPDiscovery.js +38 -2
  110. package/models/trace/insights/LCPDiscovery.js.map +1 -1
  111. package/models/trace/insights/LCPPhases.d.ts +36 -7
  112. package/models/trace/insights/LCPPhases.js +37 -8
  113. package/models/trace/insights/LCPPhases.js.map +1 -1
  114. package/models/trace/insights/LongCriticalNetworkTree.d.ts +22 -0
  115. package/models/trace/insights/LongCriticalNetworkTree.js +40 -0
  116. package/models/trace/insights/LongCriticalNetworkTree.js.map +1 -0
  117. package/models/trace/insights/Models.d.ts +2 -0
  118. package/models/trace/insights/Models.js +2 -0
  119. package/models/trace/insights/Models.js.map +1 -1
  120. package/models/trace/insights/RenderBlocking.d.ts +14 -1
  121. package/models/trace/insights/RenderBlocking.js +14 -1
  122. package/models/trace/insights/RenderBlocking.js.map +1 -1
  123. package/models/trace/insights/SlowCSSSelector.d.ts +27 -2
  124. package/models/trace/insights/SlowCSSSelector.js +27 -2
  125. package/models/trace/insights/SlowCSSSelector.js.map +1 -1
  126. package/models/trace/insights/ThirdParties.d.ts +13 -4
  127. package/models/trace/insights/ThirdParties.js +21 -12
  128. package/models/trace/insights/ThirdParties.js.map +1 -1
  129. package/models/trace/insights/Viewport.d.ts +2 -1
  130. package/models/trace/insights/Viewport.js +2 -1
  131. package/models/trace/insights/Viewport.js.map +1 -1
  132. package/models/trace/insights/insights-tsconfig.json +2 -0
  133. package/models/trace/insights/types.d.ts +23 -8
  134. package/models/trace/insights/types.js.map +1 -1
  135. package/models/trace/lantern/graph/CPUNode.d.ts +1 -1
  136. package/models/trace/lantern/graph/CPUNode.js.map +1 -1
  137. package/models/trace/lantern/graph/NetworkNode.d.ts +1 -1
  138. package/models/trace/lantern/graph/NetworkNode.js.map +1 -1
  139. package/models/trace/types/Configuration.d.ts +15 -0
  140. package/models/trace/types/Configuration.js.map +1 -1
  141. package/models/trace/types/File.d.ts +4 -4
  142. package/models/trace/types/File.js.map +1 -1
  143. package/models/trace/types/Timing.d.ts +7 -13
  144. package/models/trace/types/Timing.js +5 -2
  145. package/models/trace/types/Timing.js.map +1 -1
  146. package/models/trace/types/TraceEvents.d.ts +143 -108
  147. package/models/trace/types/TraceEvents.js +9 -7
  148. package/models/trace/types/TraceEvents.js.map +1 -1
  149. package/package.json +1 -1
  150. package/test/test-trace-engine.mjs +18 -14
@@ -9,12 +9,59 @@ export declare const UIStrings: {
9
9
  *@description Description of an insight that provides a breakdown for how long it took to download the main document.
10
10
  */
11
11
  description: string;
12
+ /**
13
+ * @description Text to tell the user that the document request does not have redirects.
14
+ */
15
+ passingRedirects: string;
16
+ /**
17
+ * @description Text to tell the user that the document request had redirects.
18
+ */
19
+ failedRedirects: string;
20
+ /**
21
+ * @description Text to tell the user that the time starting the document request to when the server started responding is acceptable.
22
+ */
23
+ passingServerResponseTime: string;
24
+ /**
25
+ * @description Text to tell the user that the time starting the document request to when the server started responding is not acceptable.
26
+ */
27
+ failedServerResponseTime: string;
28
+ /**
29
+ * @description Text to tell the user that text compression (like gzip) was applied.
30
+ */
31
+ passingTextCompression: string;
32
+ /**
33
+ * @description Text to tell the user that text compression (like gzip) was not applied.
34
+ */
35
+ failedTextCompression: string;
36
+ /**
37
+ * @description Text for a label describing a network request event as having redirects.
38
+ */
39
+ redirectsLabel: string;
40
+ /**
41
+ * @description Text for a label describing a network request event as taking too long to start delivery by the server.
42
+ */
43
+ serverResponseTimeLabel: string;
44
+ /**
45
+ * @description Text for a label describing a network request event as taking longer to download because it wasn't compressed.
46
+ */
47
+ uncompressedDownload: string;
48
+ /**
49
+ *@description Text for a screen-reader label to tell the user that the icon represents a successful insight check
50
+ *@example {Server response time} PH1
51
+ */
52
+ successAriaLabel: string;
53
+ /**
54
+ *@description Text for a screen-reader label to tell the user that the icon represents an unsuccessful insight check
55
+ *@example {Server response time} PH1
56
+ */
57
+ failedAriaLabel: string;
12
58
  };
13
- export type DocumentLatencyInsightModel = InsightModel<{
59
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
60
+ export type DocumentLatencyInsightModel = InsightModel<typeof UIStrings, {
14
61
  data?: {
15
- serverResponseTime: Types.Timing.MilliSeconds;
62
+ serverResponseTime: Types.Timing.Milli;
16
63
  serverResponseTooSlow: boolean;
17
- redirectDuration: Types.Timing.MilliSeconds;
64
+ redirectDuration: Types.Timing.Milli;
18
65
  uncompressedResponseBytes: number;
19
66
  documentRequest?: Types.Events.SyntheticNetworkRequest;
20
67
  };
@@ -4,7 +4,7 @@
4
4
  // import * as i18n from '../../../core/i18n/i18n.js';
5
5
  import * as Helpers from '../helpers/helpers.js';
6
6
  import * as Types from '../types/types.js';
7
- import { InsightCategory } from './types.js';
7
+ import { InsightCategory, InsightWarning } from './types.js';
8
8
  export const UIStrings = {
9
9
  /**
10
10
  *@description Title of an insight that provides a breakdown for how long it took to download the main document.
@@ -14,9 +14,55 @@ export const UIStrings = {
14
14
  *@description Description of an insight that provides a breakdown for how long it took to download the main document.
15
15
  */
16
16
  description: 'Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.',
17
+ /**
18
+ * @description Text to tell the user that the document request does not have redirects.
19
+ */
20
+ passingRedirects: 'Avoids redirects',
21
+ /**
22
+ * @description Text to tell the user that the document request had redirects.
23
+ */
24
+ failedRedirects: 'Had redirects',
25
+ /**
26
+ * @description Text to tell the user that the time starting the document request to when the server started responding is acceptable.
27
+ */
28
+ passingServerResponseTime: 'Server responds quickly',
29
+ /**
30
+ * @description Text to tell the user that the time starting the document request to when the server started responding is not acceptable.
31
+ */
32
+ failedServerResponseTime: 'Server responded slowly',
33
+ /**
34
+ * @description Text to tell the user that text compression (like gzip) was applied.
35
+ */
36
+ passingTextCompression: 'Applies text compression',
37
+ /**
38
+ * @description Text to tell the user that text compression (like gzip) was not applied.
39
+ */
40
+ failedTextCompression: 'No compression applied',
41
+ /**
42
+ * @description Text for a label describing a network request event as having redirects.
43
+ */
44
+ redirectsLabel: 'Redirects',
45
+ /**
46
+ * @description Text for a label describing a network request event as taking too long to start delivery by the server.
47
+ */
48
+ serverResponseTimeLabel: 'Server response time',
49
+ /**
50
+ * @description Text for a label describing a network request event as taking longer to download because it wasn't compressed.
51
+ */
52
+ uncompressedDownload: 'Uncompressed download',
53
+ /**
54
+ *@description Text for a screen-reader label to tell the user that the icon represents a successful insight check
55
+ *@example {Server response time} PH1
56
+ */
57
+ successAriaLabel: 'Insight check passed: {PH1}',
58
+ /**
59
+ *@description Text for a screen-reader label to tell the user that the icon represents an unsuccessful insight check
60
+ *@example {Server response time} PH1
61
+ */
62
+ failedAriaLabel: 'Insight check failed: {PH1}',
17
63
  };
18
64
  // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/DocumentLatency.ts', UIStrings);
19
- const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
65
+ export const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
20
66
  // Due to the way that DevTools throttling works we cannot see if server response took less than ~570ms.
21
67
  // We set our failure threshold to 600ms to avoid those false positives but we want devs to shoot for 100ms.
22
68
  const TOO_SLOW_THRESHOLD_MS = 600;
@@ -102,6 +148,7 @@ function finalize(partialModel) {
102
148
  partialModel.data.uncompressedResponseBytes > 0;
103
149
  }
104
150
  return {
151
+ strings: UIStrings,
105
152
  title: i18nString(UIStrings.title),
106
153
  description: i18nString(UIStrings.description),
107
154
  category: InsightCategory.ALL,
@@ -115,7 +162,7 @@ export function generateInsight(parsedTrace, context) {
115
162
  }
116
163
  const documentRequest = parsedTrace.NetworkRequests.byTime.find(req => req.args.data.requestId === context.navigationId);
117
164
  if (!documentRequest) {
118
- throw new Error('missing document request');
165
+ return finalize({ warnings: [InsightWarning.NO_DOCUMENT_REQUEST] });
119
166
  }
120
167
  const serverResponseTime = getServerResponseTime(documentRequest);
121
168
  if (serverResponseTime === null) {
@@ -137,7 +184,7 @@ export function generateInsight(parsedTrace, context) {
137
184
  data: {
138
185
  serverResponseTime,
139
186
  serverResponseTooSlow,
140
- redirectDuration: Types.Timing.MilliSeconds(redirectDuration),
187
+ redirectDuration: Types.Timing.Milli(redirectDuration),
141
188
  uncompressedResponseBytes: getCompressionSavings(documentRequest),
142
189
  documentRequest,
143
190
  },
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentLatency.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DocumentLatency.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,eAAe,EAA+D,MAAM,YAAY,CAAC;AAEzG,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,0BAA0B;IACjC;;OAEG;IACH,WAAW,EACP,8JAA8J;CACnK,CAAC;AAEF,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,0CAA0C,EAAE,SAAS,CAAC,CAAC;AAChG,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAEtE,wGAAwG;AACxG,4GAA4G;AAC5G,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,qCAAqC;AACrC,MAAM,yBAAyB,GAAG,IAAI,CAAC;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AAE,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACxG,gBAAgB,IAAI,gBAAgB,CAAC;IAErC,MAAM,aAAa,GAAG;QACpB,GAAG,EAAE,gBAA6C;QAClD,GAAG,EAAE,gBAA6C;KACnD,CAAC;IAEF,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,CAAC,eAAe,CAAC;QAChC,IAAI,EAAE;YACJ,kBAAkB;YAClB,qBAAqB;YACrB,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC;YAC7D,yBAAyB,EAAE,qBAAqB,CAAC,eAAe,CAAC;YACjE,eAAe;SAChB;QACD,aAAa;KACd,CAAC,CAAC;AACL,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 i18n from '../../../core/i18n/i18n.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {InsightCategory, type InsightModel, type InsightSetContext, type RequiredData} from './types.js';\n\nexport const UIStrings = {\n /**\n *@description Title of an insight that provides a breakdown for how long it took to download the main document.\n */\n title: 'Document request latency',\n /**\n *@description Description of an insight that provides a breakdown for how long it took to download the main document.\n */\n description:\n 'Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/DocumentLatency.ts', UIStrings);\nconst i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n// Due to the way that DevTools throttling works we cannot see if server response took less than ~570ms.\n// We set our failure threshold to 600ms to avoid those false positives but we want devs to shoot for 100ms.\nconst TOO_SLOW_THRESHOLD_MS = 600;\nconst TARGET_MS = 100;\n\n// Threshold for compression savings.\nconst IGNORE_THRESHOLD_IN_BYTES = 1400;\n\nexport type DocumentLatencyInsightModel = InsightModel<{\n data?: {\n serverResponseTime: Types.Timing.MilliSeconds,\n serverResponseTooSlow: boolean,\n redirectDuration: Types.Timing.MilliSeconds,\n uncompressedResponseBytes: number,\n documentRequest?: Types.Events.SyntheticNetworkRequest,\n },\n}>;\n\nexport function deps(): ['Meta', 'NetworkRequests'] {\n return ['Meta', 'NetworkRequests'];\n}\n\nfunction getServerResponseTime(request: Types.Events.SyntheticNetworkRequest): Types.Timing.MilliSeconds|null {\n const timing = request.args.data.timing;\n if (!timing) {\n return null;\n }\n\n const ms = Helpers.Timing.microToMilli(request.args.data.syntheticData.waiting);\n return Math.round(ms) as Types.Timing.MilliSeconds;\n}\n\nfunction getCompressionSavings(request: Types.Events.SyntheticNetworkRequest): number {\n // Check from headers if compression was already applied.\n // Older devtools logs are lower case, while modern logs are Cased-Like-This.\n const patterns = [\n /^content-encoding$/i,\n /^x-content-encoding-over-network$/i,\n ];\n const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];\n const isCompressed = request.args.data.responseHeaders.some(\n header => patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value));\n if (isCompressed) {\n return 0;\n }\n\n // We don't know how many bytes this asset used on the network, but we can guess it was\n // roughly the size of the content gzipped.\n // See https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/optimize-encoding-and-transfer for specific CSS/Script examples\n // See https://discuss.httparchive.org/t/file-size-and-compression-savings/145 for fallback multipliers\n // See https://letstalkaboutwebperf.com/en/gzip-brotli-server-config/ for MIME types to compress\n const originalSize = request.args.data.decodedBodyLength;\n let estimatedSavings = 0;\n switch (request.args.data.mimeType) {\n case 'text/css':\n // Stylesheets tend to compress extremely well.\n estimatedSavings = Math.round(originalSize * 0.8);\n break;\n case 'text/html':\n case 'text/javascript':\n // Scripts and HTML compress fairly well too.\n estimatedSavings = Math.round(originalSize * 0.67);\n break;\n case 'text/plain':\n case 'text/xml':\n case 'text/x-component':\n case 'application/javascript':\n case 'application/json':\n case 'application/manifest+json':\n case 'application/vnd.api+json':\n case 'application/xml':\n case 'application/xhtml+xml':\n case 'application/rss+xml':\n case 'application/atom+xml':\n case 'application/vnd.ms-fontobject':\n case 'application/x-font-ttf':\n case 'application/x-font-opentype':\n case 'application/x-font-truetype':\n case 'image/svg+xml':\n case 'image/x-icon':\n case 'image/vnd.microsoft.icon':\n case 'font/ttf':\n case 'font/eot':\n case 'font/otf':\n case 'font/opentype':\n // Use the average savings in HTTPArchive.\n estimatedSavings = Math.round(originalSize * 0.5);\n break;\n default: // Any other MIME types are likely already compressed.\n }\n // Check if the estimated savings are greater than the byte ignore threshold.\n // Note that the estimated gzip savings are always more than 10%, so there is\n // no percent threshold.\n return estimatedSavings < IGNORE_THRESHOLD_IN_BYTES ? 0 : estimatedSavings;\n}\n\nfunction finalize(partialModel: Omit<DocumentLatencyInsightModel, 'title'|'description'|'category'|'shouldShow'>):\n DocumentLatencyInsightModel {\n let hasFailure = false;\n if (partialModel.data) {\n hasFailure = partialModel.data.redirectDuration > 0 || partialModel.data.serverResponseTooSlow ||\n partialModel.data.uncompressedResponseBytes > 0;\n }\n\n return {\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n shouldShow: hasFailure,\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DocumentLatencyInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const documentRequest =\n parsedTrace.NetworkRequests.byTime.find(req => req.args.data.requestId === context.navigationId);\n if (!documentRequest) {\n throw new Error('missing document request');\n }\n\n const serverResponseTime = getServerResponseTime(documentRequest);\n if (serverResponseTime === null) {\n throw new Error('missing document request timing');\n }\n\n const serverResponseTooSlow = serverResponseTime > TOO_SLOW_THRESHOLD_MS;\n\n let overallSavingsMs = 0;\n if (serverResponseTime > TOO_SLOW_THRESHOLD_MS) {\n overallSavingsMs = Math.max(serverResponseTime - TARGET_MS, 0);\n }\n\n const redirectDuration = Math.round(documentRequest.args.data.syntheticData.redirectionDuration / 1000);\n overallSavingsMs += redirectDuration;\n\n const metricSavings = {\n FCP: overallSavingsMs as Types.Timing.MilliSeconds,\n LCP: overallSavingsMs as Types.Timing.MilliSeconds,\n };\n\n return finalize({\n relatedEvents: [documentRequest],\n data: {\n serverResponseTime,\n serverResponseTooSlow,\n redirectDuration: Types.Timing.MilliSeconds(redirectDuration),\n uncompressedResponseBytes: getCompressionSavings(documentRequest),\n documentRequest,\n },\n metricSavings,\n });\n}\n"]}
1
+ {"version":3,"file":"DocumentLatency.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DocumentLatency.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,EAGf,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,0BAA0B;IACjC;;OAEG;IACH,WAAW,EACP,8JAA8J;IAClK;;OAEG;IACH,gBAAgB,EAAE,kBAAkB;IACpC;;OAEG;IACH,eAAe,EAAE,eAAe;IAChC;;OAEG;IACH,yBAAyB,EAAE,yBAAyB;IACpD;;OAEG;IACH,wBAAwB,EAAE,yBAAyB;IACnD;;OAEG;IACH,sBAAsB,EAAE,0BAA0B;IAClD;;OAEG;IACH,qBAAqB,EAAE,wBAAwB;IAC/C;;OAEG;IACH,cAAc,EAAE,WAAW;IAC3B;;OAEG;IACH,uBAAuB,EAAE,sBAAsB;IAC/C;;OAEG;IACH,oBAAoB,EAAE,uBAAuB;IAC7C;;;OAGG;IACH,gBAAgB,EAAE,6BAA6B;IAC/C;;;O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AC;QACrB,OAAO,QAAQ,CAAC,EAAC,QAAQ,EAAE,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAC,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,eAAe,CAAC,CAAC;IAClE,IAAI,kBAAkB,KAAK,IAAI,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,qBAAqB,GAAG,kBAAkB,GAAG,qBAAqB,CAAC;IAEzE,IAAI,gBAAgB,GAAG,CAAC,CAAC;IACzB,IAAI,kBAAkB,GAAG,qBAAqB,EAAE,CAAC;QAC/C,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACxG,gBAAgB,IAAI,gBAAgB,CAAC;IAErC,MAAM,aAAa,GAAG;QACpB,GAAG,EAAE,gBAAsC;QAC3C,GAAG,EAAE,gBAAsC;KAC5C,CAAC;IAEF,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,CAAC,eAAe,CAAC;QAChC,IAAI,EAAE;YACJ,kBAAkB;YAClB,qBAAqB;YACrB,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC;YACtD,yBAAyB,EAAE,qBAAqB,CAAC,eAAe,CAAC;YACjE,eAAe;SAChB;QACD,aAAa;KACd,CAAC,CAAC;AACL,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 i18n from '../../../core/i18n/i18n.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n type InsightModel,\n type InsightSetContext,\n InsightWarning,\n type PartialInsightModel,\n type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /**\n *@description Title of an insight that provides a breakdown for how long it took to download the main document.\n */\n title: 'Document request latency',\n /**\n *@description Description of an insight that provides a breakdown for how long it took to download the main document.\n */\n description:\n 'Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.',\n /**\n * @description Text to tell the user that the document request does not have redirects.\n */\n passingRedirects: 'Avoids redirects',\n /**\n * @description Text to tell the user that the document request had redirects.\n */\n failedRedirects: 'Had redirects',\n /**\n * @description Text to tell the user that the time starting the document request to when the server started responding is acceptable.\n */\n passingServerResponseTime: 'Server responds quickly',\n /**\n * @description Text to tell the user that the time starting the document request to when the server started responding is not acceptable.\n */\n failedServerResponseTime: 'Server responded slowly',\n /**\n * @description Text to tell the user that text compression (like gzip) was applied.\n */\n passingTextCompression: 'Applies text compression',\n /**\n * @description Text to tell the user that text compression (like gzip) was not applied.\n */\n failedTextCompression: 'No compression applied',\n /**\n * @description Text for a label describing a network request event as having redirects.\n */\n redirectsLabel: 'Redirects',\n /**\n * @description Text for a label describing a network request event as taking too long to start delivery by the server.\n */\n serverResponseTimeLabel: 'Server response time',\n /**\n * @description Text for a label describing a network request event as taking longer to download because it wasn't compressed.\n */\n uncompressedDownload: 'Uncompressed download',\n /**\n *@description Text for a screen-reader label to tell the user that the icon represents a successful insight check\n *@example {Server response time} PH1\n */\n successAriaLabel: 'Insight check passed: {PH1}',\n /**\n *@description Text for a screen-reader label to tell the user that the icon represents an unsuccessful insight check\n *@example {Server response time} PH1\n */\n failedAriaLabel: 'Insight check failed: {PH1}',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/DocumentLatency.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n// Due to the way that DevTools throttling works we cannot see if server response took less than ~570ms.\n// We set our failure threshold to 600ms to avoid those false positives but we want devs to shoot for 100ms.\nconst TOO_SLOW_THRESHOLD_MS = 600;\nconst TARGET_MS = 100;\n\n// Threshold for compression savings.\nconst IGNORE_THRESHOLD_IN_BYTES = 1400;\n\nexport type DocumentLatencyInsightModel = InsightModel<typeof UIStrings, {\n data?: {\n serverResponseTime: Types.Timing.Milli,\n serverResponseTooSlow: boolean,\n redirectDuration: Types.Timing.Milli,\n uncompressedResponseBytes: number,\n documentRequest?: Types.Events.SyntheticNetworkRequest,\n },\n}>;\n\nexport function deps(): ['Meta', 'NetworkRequests'] {\n return ['Meta', 'NetworkRequests'];\n}\n\nfunction getServerResponseTime(request: Types.Events.SyntheticNetworkRequest): Types.Timing.Milli|null {\n const timing = request.args.data.timing;\n if (!timing) {\n return null;\n }\n\n const ms = Helpers.Timing.microToMilli(request.args.data.syntheticData.waiting);\n return Math.round(ms) as Types.Timing.Milli;\n}\n\nfunction getCompressionSavings(request: Types.Events.SyntheticNetworkRequest): number {\n // Check from headers if compression was already applied.\n // Older devtools logs are lower case, while modern logs are Cased-Like-This.\n const patterns = [\n /^content-encoding$/i,\n /^x-content-encoding-over-network$/i,\n ];\n const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];\n const isCompressed = request.args.data.responseHeaders.some(\n header => patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value));\n if (isCompressed) {\n return 0;\n }\n\n // We don't know how many bytes this asset used on the network, but we can guess it was\n // roughly the size of the content gzipped.\n // See https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/optimize-encoding-and-transfer for specific CSS/Script examples\n // See https://discuss.httparchive.org/t/file-size-and-compression-savings/145 for fallback multipliers\n // See https://letstalkaboutwebperf.com/en/gzip-brotli-server-config/ for MIME types to compress\n const originalSize = request.args.data.decodedBodyLength;\n let estimatedSavings = 0;\n switch (request.args.data.mimeType) {\n case 'text/css':\n // Stylesheets tend to compress extremely well.\n estimatedSavings = Math.round(originalSize * 0.8);\n break;\n case 'text/html':\n case 'text/javascript':\n // Scripts and HTML compress fairly well too.\n estimatedSavings = Math.round(originalSize * 0.67);\n break;\n case 'text/plain':\n case 'text/xml':\n case 'text/x-component':\n case 'application/javascript':\n case 'application/json':\n case 'application/manifest+json':\n case 'application/vnd.api+json':\n case 'application/xml':\n case 'application/xhtml+xml':\n case 'application/rss+xml':\n case 'application/atom+xml':\n case 'application/vnd.ms-fontobject':\n case 'application/x-font-ttf':\n case 'application/x-font-opentype':\n case 'application/x-font-truetype':\n case 'image/svg+xml':\n case 'image/x-icon':\n case 'image/vnd.microsoft.icon':\n case 'font/ttf':\n case 'font/eot':\n case 'font/otf':\n case 'font/opentype':\n // Use the average savings in HTTPArchive.\n estimatedSavings = Math.round(originalSize * 0.5);\n break;\n default: // Any other MIME types are likely already compressed.\n }\n // Check if the estimated savings are greater than the byte ignore threshold.\n // Note that the estimated gzip savings are always more than 10%, so there is\n // no percent threshold.\n return estimatedSavings < IGNORE_THRESHOLD_IN_BYTES ? 0 : estimatedSavings;\n}\n\nfunction finalize(partialModel: PartialInsightModel<DocumentLatencyInsightModel>): DocumentLatencyInsightModel {\n let hasFailure = false;\n if (partialModel.data) {\n hasFailure = partialModel.data.redirectDuration > 0 || partialModel.data.serverResponseTooSlow ||\n partialModel.data.uncompressedResponseBytes > 0;\n }\n\n return {\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n shouldShow: hasFailure,\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DocumentLatencyInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const documentRequest =\n parsedTrace.NetworkRequests.byTime.find(req => req.args.data.requestId === context.navigationId);\n if (!documentRequest) {\n return finalize({warnings: [InsightWarning.NO_DOCUMENT_REQUEST]});\n }\n\n const serverResponseTime = getServerResponseTime(documentRequest);\n if (serverResponseTime === null) {\n throw new Error('missing document request timing');\n }\n\n const serverResponseTooSlow = serverResponseTime > TOO_SLOW_THRESHOLD_MS;\n\n let overallSavingsMs = 0;\n if (serverResponseTime > TOO_SLOW_THRESHOLD_MS) {\n overallSavingsMs = Math.max(serverResponseTime - TARGET_MS, 0);\n }\n\n const redirectDuration = Math.round(documentRequest.args.data.syntheticData.redirectionDuration / 1000);\n overallSavingsMs += redirectDuration;\n\n const metricSavings = {\n FCP: overallSavingsMs as Types.Timing.Milli,\n LCP: overallSavingsMs as Types.Timing.Milli,\n };\n\n return finalize({\n relatedEvents: [documentRequest],\n data: {\n serverResponseTime,\n serverResponseTooSlow,\n redirectDuration: Types.Timing.Milli(redirectDuration),\n uncompressedResponseBytes: getCompressionSavings(documentRequest),\n documentRequest,\n },\n metricSavings,\n });\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import * as Platform from '../../../core/platform/platform.js';
1
2
  import * as Types from '../types/types.js';
2
3
  import { type InsightModel, type InsightSetContext, type RequiredData } from './types.js';
3
4
  export declare const UIStrings: {
@@ -7,13 +8,18 @@ export declare const UIStrings: {
7
8
  * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.
8
9
  */
9
10
  description: string;
11
+ /** Column for a font loaded by the page to render text. */
12
+ fontColumn: string;
13
+ /** Column for the amount of time wasted. */
14
+ wastedTimeColumn: string;
10
15
  };
16
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Platform.UIString.LocalizedString;
11
17
  export declare function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'];
12
- export type FontDisplayInsightModel = InsightModel<{
18
+ export type FontDisplayInsightModel = InsightModel<typeof UIStrings, {
13
19
  fonts: Array<{
14
20
  request: Types.Events.SyntheticNetworkRequest;
15
21
  display: string;
16
- wastedTime: Types.Timing.MilliSeconds;
22
+ wastedTime: Types.Timing.Milli;
17
23
  }>;
18
24
  }>;
19
25
  export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel;
@@ -13,14 +13,19 @@ export const UIStrings = {
13
13
  * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.
14
14
  */
15
15
  description: 'Consider setting [`font-display`](https://developer.chrome.com/blog/font-display) to `swap` or `optional` to ensure text is consistently visible. `swap` can be further optimized to mitigate layout shifts with [font metric overrides](https://developer.chrome.com/blog/font-fallbacks).',
16
+ /** Column for a font loaded by the page to render text. */
17
+ fontColumn: 'Font',
18
+ /** Column for the amount of time wasted. */
19
+ wastedTimeColumn: 'Wasted time',
16
20
  };
17
21
  // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/FontDisplay.ts', UIStrings);
18
- const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
22
+ export const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
19
23
  export function deps() {
20
24
  return ['Meta', 'NetworkRequests', 'LayoutShifts'];
21
25
  }
22
26
  function finalize(partialModel) {
23
27
  return {
28
+ strings: UIStrings,
24
29
  title: i18nString(UIStrings.title),
25
30
  description: i18nString(UIStrings.description),
26
31
  category: InsightCategory.INP,
@@ -40,11 +45,12 @@ export function generateInsight(parsedTrace, context) {
40
45
  continue;
41
46
  }
42
47
  const display = event.args.display;
43
- let wastedTime = Types.Timing.MilliSeconds(0);
48
+ let wastedTime = Types.Timing.Milli(0);
44
49
  if (/^(block|fallback|auto)$/.test(display)) {
45
- const wastedTimeMicro = Types.Timing.MicroSeconds(request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);
50
+ const wastedTimeMicro = Types.Timing.Micro(request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);
46
51
  // TODO(crbug.com/352244504): should really end at the time of the next Commit trace event.
47
- wastedTime = Platform.NumberUtilities.floor(Helpers.Timing.microToMilli(wastedTimeMicro), 1 / 5);
52
+ wastedTime =
53
+ Platform.NumberUtilities.floor(Helpers.Timing.microToMilli(wastedTimeMicro), 1 / 5);
48
54
  // All browsers wait for no more than 3s.
49
55
  wastedTime = Math.min(wastedTime, 3000);
50
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FontDis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,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAA8B,CAAC;IAEvF,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACxC,KAAK;QACL,aAAa,EAAE,EAAC,GAAG,EAAE,OAAO,EAAC;KAC9B,CAAC,CAAC;AACL,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 i18n from '../../../core/i18n/i18n.js';\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {InsightCategory, type InsightModel, type InsightSetContext, type RequiredData} from './types.js';\n\nexport const UIStrings = {\n /** Title of an insight that provides details about the fonts used on the page, and the value of their `font-display` properties. */\n title: 'Font display',\n /**\n * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.\n */\n description:\n 'Consider setting [`font-display`](https://developer.chrome.com/blog/font-display) to `swap` or `optional` to ensure text is consistently visible. `swap` can be further optimized to mitigate layout shifts with [font metric overrides](https://developer.chrome.com/blog/font-fallbacks).',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/FontDisplay.ts', UIStrings);\nconst i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'] {\n return ['Meta', 'NetworkRequests', 'LayoutShifts'];\n}\n\nexport type FontDisplayInsightModel = InsightModel<{\n fonts: Array<{\n request: Types.Events.SyntheticNetworkRequest,\n display: string,\n wastedTime: Types.Timing.MilliSeconds,\n }>,\n}>;\n\nfunction finalize(partialModel: Omit<FontDisplayInsightModel, 'title'|'description'|'category'|'shouldShow'>):\n FontDisplayInsightModel {\n return {\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n shouldShow: Boolean(partialModel.fonts.find(font => font.wastedTime > 0)),\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel {\n const fonts = [];\n for (const event of parsedTrace.LayoutShifts.beginRemoteFontLoadEvents) {\n if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {\n continue;\n }\n\n const requestId = `${event.pid}.${event.args.id}`;\n const request = parsedTrace.NetworkRequests.byId.get(requestId);\n if (!request) {\n continue;\n }\n\n const display = event.args.display;\n let wastedTime = Types.Timing.MilliSeconds(0);\n\n if (/^(block|fallback|auto)$/.test(display)) {\n const wastedTimeMicro = Types.Timing.MicroSeconds(\n request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);\n // TODO(crbug.com/352244504): should really end at the time of the next Commit trace event.\n wastedTime = Platform.NumberUtilities.floor(Helpers.Timing.microToMilli(wastedTimeMicro), 1 / 5) as\n Types.Timing.MilliSeconds;\n // All browsers wait for no more than 3s.\n wastedTime = Math.min(wastedTime, 3000) as Types.Timing.MilliSeconds;\n }\n\n fonts.push({\n request,\n display,\n wastedTime,\n });\n }\n\n fonts.sort((a, b) => b.wastedTime - a.wastedTime);\n\n const savings = Math.max(...fonts.map(f => f.wastedTime)) as Types.Timing.MilliSeconds;\n\n return finalize({\n relatedEvents: fonts.map(f => f.request),\n fonts,\n metricSavings: {FCP: savings},\n });\n}\n"]}
1
+ {"version":3,"file":"FontDisplay.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/FontDisplay.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,Q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AC;IAElD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAuB,CAAC;IAEhF,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACxC,KAAK;QACL,aAAa,EAAE,EAAC,GAAG,EAAE,OAAO,EAAC;KAC9B,CAAC,CAAC;AACL,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 i18n from '../../../core/i18n/i18n.js';\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /** Title of an insight that provides details about the fonts used on the page, and the value of their `font-display` properties. */\n title: 'Font display',\n /**\n * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.\n */\n description:\n 'Consider setting [`font-display`](https://developer.chrome.com/blog/font-display) to `swap` or `optional` to ensure text is consistently visible. `swap` can be further optimized to mitigate layout shifts with [font metric overrides](https://developer.chrome.com/blog/font-fallbacks).',\n /** Column for a font loaded by the page to render text. */\n fontColumn: 'Font',\n /** Column for the amount of time wasted. */\n wastedTimeColumn: 'Wasted time',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/FontDisplay.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'] {\n return ['Meta', 'NetworkRequests', 'LayoutShifts'];\n}\n\nexport type FontDisplayInsightModel = InsightModel<typeof UIStrings, {\n fonts: Array<{\n request: Types.Events.SyntheticNetworkRequest,\n display: string,\n wastedTime: Types.Timing.Milli,\n }>,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<FontDisplayInsightModel>): FontDisplayInsightModel {\n return {\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n shouldShow: Boolean(partialModel.fonts.find(font => font.wastedTime > 0)),\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel {\n const fonts = [];\n for (const event of parsedTrace.LayoutShifts.beginRemoteFontLoadEvents) {\n if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {\n continue;\n }\n\n const requestId = `${event.pid}.${event.args.id}`;\n const request = parsedTrace.NetworkRequests.byId.get(requestId);\n if (!request) {\n continue;\n }\n\n const display = event.args.display;\n let wastedTime = Types.Timing.Milli(0);\n\n if (/^(block|fallback|auto)$/.test(display)) {\n const wastedTimeMicro = Types.Timing.Micro(\n request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);\n // TODO(crbug.com/352244504): should really end at the time of the next Commit trace event.\n wastedTime =\n Platform.NumberUtilities.floor(Helpers.Timing.microToMilli(wastedTimeMicro), 1 / 5) as Types.Timing.Milli;\n // All browsers wait for no more than 3s.\n wastedTime = Math.min(wastedTime, 3000) as Types.Timing.Milli;\n }\n\n fonts.push({\n request,\n display,\n wastedTime,\n });\n }\n\n fonts.sort((a, b) => b.wastedTime - a.wastedTime);\n\n const savings = Math.max(...fonts.map(f => f.wastedTime)) as Types.Timing.Milli;\n\n return finalize({\n relatedEvents: fonts.map(f => f.request),\n fonts,\n metricSavings: {FCP: savings},\n });\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { type BottomUpCallStack, type ForcedReflowAggregatedData, type InsightModel, type RequiredData } from './types.js';
2
+ export declare function deps(): ['Warnings', 'Renderer'];
3
+ export declare const UIStrings: {
4
+ /**
5
+ *@description Title of an insight that provides details about Forced reflow.
6
+ */
7
+ title: string;
8
+ /**
9
+ * @description Text to describe the forced reflow.
10
+ */
11
+ description: string;
12
+ /**
13
+ *@description Title of a list to provide related stack trace data
14
+ */
15
+ relatedStackTrace: string;
16
+ /**
17
+ *@description Text to describe the top time-consuming function call
18
+ */
19
+ topTimeConsumingFunctionCall: string;
20
+ /**
21
+ * @description Text to describe the total reflow time
22
+ */
23
+ totalReflowTime: string;
24
+ };
25
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
26
+ export type ForcedReflowInsightModel = InsightModel<typeof UIStrings, {
27
+ topLevelFunctionCallData: ForcedReflowAggregatedData | undefined;
28
+ aggregatedBottomUpData: BottomUpCallStack[];
29
+ }>;
30
+ export declare function generateInsight(traceParsedData: RequiredData<typeof deps>): ForcedReflowInsightModel;
@@ -0,0 +1,181 @@
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 i18n from '../../../core/i18n/i18n.js';
5
+ import * as Helpers from '../helpers/helpers.js';
6
+ import * as Types from '../types/types.js';
7
+ import { InsightCategory, } from './types.js';
8
+ export function deps() {
9
+ return ['Warnings', 'Renderer'];
10
+ }
11
+ export const UIStrings = {
12
+ /**
13
+ *@description Title of an insight that provides details about Forced reflow.
14
+ */
15
+ title: 'Forced reflow',
16
+ /**
17
+ * @description Text to describe the forced reflow.
18
+ */
19
+ description: 'Many APIs, typically reading layout geometry, force the rendering engine to pause script execution in order to calculate the style and layout. Learn more about [forced reflow](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing#avoid-forced-synchronous-layouts) and its mitigations.',
20
+ /**
21
+ *@description Title of a list to provide related stack trace data
22
+ */
23
+ relatedStackTrace: 'Stack trace',
24
+ /**
25
+ *@description Text to describe the top time-consuming function call
26
+ */
27
+ topTimeConsumingFunctionCall: 'Top function call',
28
+ /**
29
+ * @description Text to describe the total reflow time
30
+ */
31
+ totalReflowTime: 'Total reflow time',
32
+ };
33
+ // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/ForcedReflow.ts', UIStrings);
34
+ export const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
35
+ function aggregateForcedReflow(data, entryToNodeMap) {
36
+ const dataByTopLevelFunction = new Map();
37
+ const bottomUpDataMap = new Map();
38
+ const forcedReflowEvents = data.get('FORCED_REFLOW');
39
+ if (!forcedReflowEvents || forcedReflowEvents.length === 0) {
40
+ return [undefined, []];
41
+ }
42
+ forcedReflowEvents.forEach(e => {
43
+ // Gather the stack traces by searching in the tree
44
+ const traceNode = entryToNodeMap.get(e);
45
+ if (!traceNode) {
46
+ return;
47
+ }
48
+ // Compute call stack fully
49
+ const bottomUpData = [];
50
+ let currentNode = traceNode;
51
+ let previousNode;
52
+ const childStack = [];
53
+ // Some profileCalls maybe constructed as its children in hierarchy tree
54
+ while (currentNode.children.length > 0) {
55
+ const childNode = currentNode.children[0];
56
+ if (!previousNode) {
57
+ previousNode = childNode;
58
+ }
59
+ const eventData = childNode.entry;
60
+ if (Types.Events.isProfileCall(eventData)) {
61
+ childStack.push(eventData.callFrame);
62
+ }
63
+ currentNode = childNode;
64
+ }
65
+ // In order to avoid too much information, we only contain 2 levels bottomUp data,
66
+ while (childStack.length > 0 && bottomUpData.length < 2) {
67
+ const traceData = childStack.pop();
68
+ if (traceData) {
69
+ bottomUpData.push(traceData);
70
+ }
71
+ }
72
+ let node = traceNode.parent;
73
+ let topLevelFunctionCall;
74
+ let topLevelFunctionCallEvent;
75
+ while (node) {
76
+ const eventData = node.entry;
77
+ if (Types.Events.isProfileCall(eventData)) {
78
+ if (bottomUpData.length < 2) {
79
+ bottomUpData.push(eventData.callFrame);
80
+ }
81
+ }
82
+ else {
83
+ // We have finished searching bottom up data
84
+ if (Types.Events.isFunctionCall(eventData) && eventData.args.data &&
85
+ Types.Events.objectIsCallFrame(eventData.args.data)) {
86
+ topLevelFunctionCall = eventData.args.data;
87
+ topLevelFunctionCallEvent = eventData;
88
+ if (bottomUpData.length === 0) {
89
+ bottomUpData.push(topLevelFunctionCall);
90
+ }
91
+ }
92
+ else {
93
+ // Sometimes the top level task can be other JSInvocation event
94
+ // then we use the top level profile call as topLevelFunctionCall's data
95
+ const previousData = previousNode?.entry;
96
+ if (previousData && Types.Events.isProfileCall(previousData)) {
97
+ topLevelFunctionCall = previousData.callFrame;
98
+ topLevelFunctionCallEvent = previousNode?.entry;
99
+ }
100
+ }
101
+ break;
102
+ }
103
+ previousNode = node;
104
+ node = node.parent;
105
+ }
106
+ if (!topLevelFunctionCall || !topLevelFunctionCallEvent || bottomUpData.length === 0) {
107
+ return;
108
+ }
109
+ const bottomUpDataId = bottomUpData[0].scriptId + ':' + bottomUpData[0].lineNumber + ':' + bottomUpData[0].columnNumber + ':';
110
+ const data = bottomUpDataMap.get(bottomUpDataId) ?? {
111
+ bottomUpData: bottomUpData[0],
112
+ totalTime: 0,
113
+ relatedEvents: [],
114
+ };
115
+ data.totalTime += (e.dur ?? 0);
116
+ data.relatedEvents.push(e);
117
+ bottomUpDataMap.set(bottomUpDataId, data);
118
+ const aggregatedDataId = topLevelFunctionCall.scriptId + ':' + topLevelFunctionCall.lineNumber + ':' + topLevelFunctionCall.columnNumber;
119
+ if (!dataByTopLevelFunction.has(aggregatedDataId)) {
120
+ dataByTopLevelFunction.set(aggregatedDataId, {
121
+ topLevelFunctionCall,
122
+ totalReflowTime: 0,
123
+ bottomUpData: new Set(),
124
+ topLevelFunctionCallEvents: [],
125
+ });
126
+ }
127
+ const aggregatedData = dataByTopLevelFunction.get(aggregatedDataId);
128
+ if (aggregatedData) {
129
+ aggregatedData.totalReflowTime += (e.dur ?? 0);
130
+ aggregatedData.bottomUpData.add(bottomUpDataId);
131
+ aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);
132
+ }
133
+ });
134
+ let topTimeConsumingDataId = '';
135
+ let maxTime = 0;
136
+ dataByTopLevelFunction.forEach((value, key) => {
137
+ if (value.totalReflowTime > maxTime) {
138
+ maxTime = value.totalReflowTime;
139
+ topTimeConsumingDataId = key;
140
+ }
141
+ });
142
+ const aggregatedBottomUpData = [];
143
+ const topLevelFunctionCallData = dataByTopLevelFunction.get(topTimeConsumingDataId);
144
+ const dataSet = dataByTopLevelFunction.get(topTimeConsumingDataId)?.bottomUpData;
145
+ if (dataSet) {
146
+ dataSet.forEach(value => {
147
+ const callStackData = bottomUpDataMap.get(value);
148
+ if (callStackData && callStackData.totalTime > Helpers.Timing.milliToMicro(Types.Timing.Milli(1))) {
149
+ aggregatedBottomUpData.push(callStackData);
150
+ }
151
+ });
152
+ }
153
+ return [topLevelFunctionCallData, aggregatedBottomUpData];
154
+ }
155
+ function finalize(partialModel) {
156
+ return {
157
+ strings: UIStrings,
158
+ title: i18nString(UIStrings.title),
159
+ description: i18nString(UIStrings.description),
160
+ category: InsightCategory.ALL,
161
+ shouldShow: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0,
162
+ ...partialModel,
163
+ };
164
+ }
165
+ export function generateInsight(traceParsedData) {
166
+ const warningsData = traceParsedData.Warnings;
167
+ const entryToNodeMap = traceParsedData.Renderer.entryToNode;
168
+ if (!warningsData) {
169
+ throw new Error('no warnings data');
170
+ }
171
+ if (!entryToNodeMap) {
172
+ throw new Error('no renderer data');
173
+ }
174
+ const [topLevelFunctionCallData, aggregatedBottomUpData] = aggregateForcedReflow(warningsData.perWarning, entryToNodeMap);
175
+ return finalize({
176
+ relatedEvents: topLevelFunctionCallData?.topLevelFunctionCallEvents,
177
+ topLevelFunctionCallData,
178
+ aggregatedBottomUpData,
179
+ });
180
+ }
181
+ //# sourceMappingURL=ForcedReflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForcedReflow.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/ForcedReflow.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO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AM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC;IAC9C,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC;IAE5D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,wBAAwB,EAAE,sBAAsB,CAAC,GACpD,qBAAqB,CAAC,YAAY,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAEnE,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,wBAAwB,EAAE,0BAA0B;QACnE,wBAAwB;QACxB,sBAAsB;KACvB,CAAC,CAAC;AACL,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 i18n from '../../../core/i18n/i18n.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport type {Warning} from '../handlers/WarningsHandler.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n type BottomUpCallStack,\n type ForcedReflowAggregatedData,\n InsightCategory,\n type InsightModel,\n type PartialInsightModel,\n type RequiredData,\n} from './types.js';\n\nexport function deps(): ['Warnings', 'Renderer'] {\n return ['Warnings', 'Renderer'];\n}\n\nexport const UIStrings = {\n /**\n *@description Title of an insight that provides details about Forced reflow.\n */\n title: 'Forced reflow',\n /**\n * @description Text to describe the forced reflow.\n */\n description:\n 'Many APIs, typically reading layout geometry, force the rendering engine to pause script execution in order to calculate the style and layout. Learn more about [forced reflow](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing#avoid-forced-synchronous-layouts) and its mitigations.',\n /**\n *@description Title of a list to provide related stack trace data\n */\n relatedStackTrace: 'Stack trace',\n /**\n *@description Text to describe the top time-consuming function call\n */\n topTimeConsumingFunctionCall: 'Top function call',\n /**\n * @description Text to describe the total reflow time\n */\n totalReflowTime: 'Total reflow time',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/ForcedReflow.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type ForcedReflowInsightModel = InsightModel<typeof UIStrings, {\n topLevelFunctionCallData: ForcedReflowAggregatedData | undefined,\n aggregatedBottomUpData: BottomUpCallStack[],\n}>;\n\nfunction aggregateForcedReflow(\n data: Map<Warning, Types.Events.Event[]>,\n entryToNodeMap: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>):\n [ForcedReflowAggregatedData|undefined, BottomUpCallStack[]] {\n const dataByTopLevelFunction = new Map<string, ForcedReflowAggregatedData>();\n const bottomUpDataMap = new Map<string, BottomUpCallStack>();\n const forcedReflowEvents = data.get('FORCED_REFLOW');\n if (!forcedReflowEvents || forcedReflowEvents.length === 0) {\n return [undefined, []];\n }\n\n forcedReflowEvents.forEach(e => {\n // Gather the stack traces by searching in the tree\n const traceNode = entryToNodeMap.get(e);\n\n if (!traceNode) {\n return;\n }\n // Compute call stack fully\n const bottomUpData: (Types.Events.CallFrame|Protocol.Runtime.CallFrame)[] = [];\n let currentNode = traceNode;\n let previousNode;\n const childStack: Protocol.Runtime.CallFrame[] = [];\n\n // Some profileCalls maybe constructed as its children in hierarchy tree\n while (currentNode.children.length > 0) {\n const childNode = currentNode.children[0];\n if (!previousNode) {\n previousNode = childNode;\n }\n const eventData = childNode.entry;\n if (Types.Events.isProfileCall(eventData)) {\n childStack.push(eventData.callFrame);\n }\n currentNode = childNode;\n }\n\n // In order to avoid too much information, we only contain 2 levels bottomUp data,\n while (childStack.length > 0 && bottomUpData.length < 2) {\n const traceData = childStack.pop();\n if (traceData) {\n bottomUpData.push(traceData);\n }\n }\n\n let node = traceNode.parent;\n let topLevelFunctionCall;\n let topLevelFunctionCallEvent: Types.Events.Event|undefined;\n while (node) {\n const eventData = node.entry;\n if (Types.Events.isProfileCall(eventData)) {\n if (bottomUpData.length < 2) {\n bottomUpData.push(eventData.callFrame);\n }\n } else {\n // We have finished searching bottom up data\n if (Types.Events.isFunctionCall(eventData) && eventData.args.data &&\n Types.Events.objectIsCallFrame(eventData.args.data)) {\n topLevelFunctionCall = eventData.args.data;\n topLevelFunctionCallEvent = eventData;\n if (bottomUpData.length === 0) {\n bottomUpData.push(topLevelFunctionCall);\n }\n } else {\n // Sometimes the top level task can be other JSInvocation event\n // then we use the top level profile call as topLevelFunctionCall's data\n const previousData = previousNode?.entry;\n if (previousData && Types.Events.isProfileCall(previousData)) {\n topLevelFunctionCall = previousData.callFrame;\n topLevelFunctionCallEvent = previousNode?.entry;\n }\n }\n break;\n }\n previousNode = node;\n node = node.parent;\n }\n\n if (!topLevelFunctionCall || !topLevelFunctionCallEvent || bottomUpData.length === 0) {\n return;\n }\n const bottomUpDataId =\n bottomUpData[0].scriptId + ':' + bottomUpData[0].lineNumber + ':' + bottomUpData[0].columnNumber + ':';\n\n const data = bottomUpDataMap.get(bottomUpDataId) ?? {\n bottomUpData: bottomUpData[0],\n totalTime: 0,\n relatedEvents: [],\n };\n data.totalTime += (e.dur ?? 0);\n data.relatedEvents.push(e);\n bottomUpDataMap.set(bottomUpDataId, data);\n\n const aggregatedDataId =\n topLevelFunctionCall.scriptId + ':' + topLevelFunctionCall.lineNumber + ':' + topLevelFunctionCall.columnNumber;\n if (!dataByTopLevelFunction.has(aggregatedDataId)) {\n dataByTopLevelFunction.set(aggregatedDataId, {\n topLevelFunctionCall,\n totalReflowTime: 0,\n bottomUpData: new Set<string>(),\n topLevelFunctionCallEvents: [],\n });\n }\n const aggregatedData = dataByTopLevelFunction.get(aggregatedDataId);\n if (aggregatedData) {\n aggregatedData.totalReflowTime += (e.dur ?? 0);\n aggregatedData.bottomUpData.add(bottomUpDataId);\n aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);\n }\n });\n\n let topTimeConsumingDataId = '';\n let maxTime = 0;\n dataByTopLevelFunction.forEach((value, key) => {\n if (value.totalReflowTime > maxTime) {\n maxTime = value.totalReflowTime;\n topTimeConsumingDataId = key;\n }\n });\n\n const aggregatedBottomUpData: BottomUpCallStack[] = [];\n const topLevelFunctionCallData = dataByTopLevelFunction.get(topTimeConsumingDataId);\n const dataSet = dataByTopLevelFunction.get(topTimeConsumingDataId)?.bottomUpData;\n if (dataSet) {\n dataSet.forEach(value => {\n const callStackData = bottomUpDataMap.get(value);\n if (callStackData && callStackData.totalTime > Helpers.Timing.milliToMicro(Types.Timing.Milli(1))) {\n aggregatedBottomUpData.push(callStackData);\n }\n });\n }\n\n return [topLevelFunctionCallData, aggregatedBottomUpData];\n}\n\nfunction finalize(partialModel: PartialInsightModel<ForcedReflowInsightModel>): ForcedReflowInsightModel {\n return {\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n shouldShow: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0,\n ...partialModel,\n };\n}\n\nexport function generateInsight(traceParsedData: RequiredData<typeof deps>): ForcedReflowInsightModel {\n const warningsData = traceParsedData.Warnings;\n const entryToNodeMap = traceParsedData.Renderer.entryToNode;\n\n if (!warningsData) {\n throw new Error('no warnings data');\n }\n\n if (!entryToNodeMap) {\n throw new Error('no renderer data');\n }\n\n const [topLevelFunctionCallData, aggregatedBottomUpData] =\n aggregateForcedReflow(warningsData.perWarning, entryToNodeMap);\n\n return finalize({\n relatedEvents: topLevelFunctionCallData?.topLevelFunctionCallEvents,\n topLevelFunctionCallData,\n aggregatedBottomUpData,\n });\n}\n"]}
@@ -31,7 +31,21 @@ export declare const UIStrings: {
31
31
  * @example {100x50} PH3
32
32
  */
33
33
  useResponsiveSize: string;
34
+ /**
35
+ * @description Column header for a table column containing network requests for images which can improve their file size (e.g. use a different format, increase compression, etc).
36
+ */
37
+ optimizeFile: string;
38
+ /**
39
+ * @description Table row value representing the remaining items not shown in the table due to size constraints. This row will always represent at least 2 items.
40
+ * @example {5} PH1
41
+ */
42
+ others: string;
43
+ /**
44
+ * @description Text status indicating that no potential optimizations were found for any image file
45
+ */
46
+ noOptimizableImages: string;
34
47
  };
48
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
35
49
  export declare function deps(): ['NetworkRequests', 'Meta', 'ImagePainting'];
36
50
  export declare enum ImageOptimizationType {
37
51
  ADJUST_COMPRESSION = "ADJUST_COMPRESSION",
@@ -66,7 +80,7 @@ export interface OptimizableImage {
66
80
  */
67
81
  largestImagePaint: Types.Events.PaintImage;
68
82
  }
69
- export type ImageDeliveryInsightModel = InsightModel<{
83
+ export type ImageDeliveryInsightModel = InsightModel<typeof UIStrings, {
70
84
  optimizableImages: OptimizableImage[];
71
85
  totalByteSavings: number;
72
86
  }>;