@paulirish/trace_engine 0.0.48 → 0.0.49

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 (139) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/core/platform/TypedArrayUtilities.d.ts +2 -1
  3. package/core/platform/TypedArrayUtilities.js +9 -4
  4. package/core/platform/TypedArrayUtilities.js.map +1 -1
  5. package/generated/protocol.d.ts +19 -2
  6. package/locales/af.json +229 -16
  7. package/locales/am.json +231 -18
  8. package/locales/ar.json +229 -16
  9. package/locales/as.json +231 -18
  10. package/locales/az.json +231 -18
  11. package/locales/be.json +228 -15
  12. package/locales/bg.json +229 -16
  13. package/locales/bn.json +229 -16
  14. package/locales/bs.json +229 -16
  15. package/locales/ca.json +229 -16
  16. package/locales/cs.json +228 -15
  17. package/locales/cy.json +231 -18
  18. package/locales/da.json +230 -17
  19. package/locales/de.json +228 -15
  20. package/locales/el.json +229 -16
  21. package/locales/en-GB.json +229 -16
  22. package/locales/en-US.json +30 -3
  23. package/locales/en-XL.json +30 -3
  24. package/locales/es-419.json +229 -16
  25. package/locales/es.json +228 -15
  26. package/locales/et.json +230 -17
  27. package/locales/eu.json +231 -18
  28. package/locales/fa.json +230 -17
  29. package/locales/fi.json +229 -16
  30. package/locales/fil.json +231 -18
  31. package/locales/fr-CA.json +230 -17
  32. package/locales/fr.json +230 -17
  33. package/locales/gl.json +228 -15
  34. package/locales/gu.json +230 -17
  35. package/locales/he.json +229 -16
  36. package/locales/hi.json +230 -17
  37. package/locales/hr.json +229 -16
  38. package/locales/hu.json +229 -16
  39. package/locales/hy.json +228 -15
  40. package/locales/id.json +228 -15
  41. package/locales/is.json +229 -16
  42. package/locales/it.json +232 -19
  43. package/locales/ja.json +228 -15
  44. package/locales/ka.json +230 -17
  45. package/locales/kk.json +230 -17
  46. package/locales/km.json +231 -18
  47. package/locales/kn.json +228 -15
  48. package/locales/ko.json +229 -16
  49. package/locales/ky.json +230 -17
  50. package/locales/lo.json +229 -16
  51. package/locales/lt.json +229 -16
  52. package/locales/lv.json +230 -17
  53. package/locales/mk.json +229 -16
  54. package/locales/ml.json +230 -17
  55. package/locales/mn.json +229 -16
  56. package/locales/mr.json +230 -17
  57. package/locales/ms.json +229 -16
  58. package/locales/my.json +231 -18
  59. package/locales/ne.json +229 -16
  60. package/locales/nl.json +229 -16
  61. package/locales/no.json +229 -16
  62. package/locales/or.json +231 -18
  63. package/locales/pa.json +228 -15
  64. package/locales/pl.json +230 -17
  65. package/locales/pt-PT.json +229 -16
  66. package/locales/pt.json +229 -16
  67. package/locales/ro.json +228 -15
  68. package/locales/ru.json +230 -17
  69. package/locales/si.json +231 -18
  70. package/locales/sk.json +229 -16
  71. package/locales/sl.json +230 -17
  72. package/locales/sq.json +229 -16
  73. package/locales/sr-Latn.json +229 -16
  74. package/locales/sr.json +229 -16
  75. package/locales/sv.json +229 -16
  76. package/locales/sw.json +231 -18
  77. package/locales/ta.json +230 -17
  78. package/locales/te.json +231 -18
  79. package/locales/th.json +229 -16
  80. package/locales/tr.json +230 -17
  81. package/locales/uk.json +229 -16
  82. package/locales/ur.json +230 -17
  83. package/locales/uz.json +229 -16
  84. package/locales/vi.json +230 -17
  85. package/locales/zh-HK.json +229 -16
  86. package/locales/zh-TW.json +230 -17
  87. package/locales/zh.json +228 -15
  88. package/locales/zu.json +230 -17
  89. package/models/trace/Processor.js +5 -3
  90. package/models/trace/Processor.js.map +1 -1
  91. package/models/trace/extras/ScriptDuplication.d.ts +27 -8
  92. package/models/trace/extras/ScriptDuplication.js +27 -26
  93. package/models/trace/extras/ScriptDuplication.js.map +1 -1
  94. package/models/trace/extras/StackTraceForEvent.js +7 -0
  95. package/models/trace/extras/StackTraceForEvent.js.map +1 -1
  96. package/models/trace/handlers/ExtensionTraceDataHandler.js +14 -9
  97. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  98. package/models/trace/handlers/MetaHandler.d.ts +13 -0
  99. package/models/trace/handlers/MetaHandler.js +27 -0
  100. package/models/trace/handlers/MetaHandler.js.map +1 -1
  101. package/models/trace/helpers/Network.d.ts +18 -0
  102. package/models/trace/helpers/Network.js +57 -0
  103. package/models/trace/helpers/Network.js.map +1 -1
  104. package/models/trace/helpers/SamplesIntegrator.js +1 -1
  105. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  106. package/models/trace/helpers/Trace.js +4 -0
  107. package/models/trace/helpers/Trace.js.map +1 -1
  108. package/models/trace/insights/DocumentLatency.d.ts +2 -1
  109. package/models/trace/insights/DocumentLatency.js +3 -0
  110. package/models/trace/insights/DocumentLatency.js.map +1 -1
  111. package/models/trace/insights/{DuplicateJavaScript.d.ts → DuplicatedJavaScript.d.ts} +6 -1
  112. package/models/trace/insights/{DuplicateJavaScript.js → DuplicatedJavaScript.js} +15 -6
  113. package/models/trace/insights/DuplicatedJavaScript.js.map +1 -0
  114. package/models/trace/insights/FontDisplay.d.ts +1 -2
  115. package/models/trace/insights/FontDisplay.js.map +1 -1
  116. package/models/trace/insights/ForcedReflow.d.ts +23 -3
  117. package/models/trace/insights/ForcedReflow.js +63 -107
  118. package/models/trace/insights/ForcedReflow.js.map +1 -1
  119. package/models/trace/insights/Models.d.ts +2 -1
  120. package/models/trace/insights/Models.js +2 -1
  121. package/models/trace/insights/Models.js.map +1 -1
  122. package/models/trace/insights/NetworkDependencyTree.d.ts +2 -1
  123. package/models/trace/insights/NetworkDependencyTree.js +9 -4
  124. package/models/trace/insights/NetworkDependencyTree.js.map +1 -1
  125. package/models/trace/insights/Statistics.d.ts +4 -0
  126. package/models/trace/insights/Statistics.js +7 -0
  127. package/models/trace/insights/Statistics.js.map +1 -1
  128. package/models/trace/insights/UseCache.d.ts +69 -0
  129. package/models/trace/insights/UseCache.js +189 -0
  130. package/models/trace/insights/UseCache.js.map +1 -0
  131. package/models/trace/insights/insights-tsconfig.json +2 -1
  132. package/models/trace/insights/types.d.ts +1 -13
  133. package/models/trace/insights/types.js.map +1 -1
  134. package/models/trace/types/TraceEvents.d.ts +16 -4
  135. package/models/trace/types/TraceEvents.js +4 -1
  136. package/models/trace/types/TraceEvents.js.map +1 -1
  137. package/package.json +1 -1
  138. package/test/test-trace-engine.mjs +2 -1
  139. package/models/trace/insights/DuplicateJavaScript.js.map +0 -1
@@ -2,6 +2,8 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  // import * as i18n from '../../../core/i18n/i18n.js';
5
+ import * as Platform from '../../../core/platform/platform.js';
6
+ import * as Extras from '../extras/extras.js';
5
7
  import * as Helpers from '../helpers/helpers.js';
6
8
  import * as Types from '../types/types.js';
7
9
  import { InsightCategory, } from './types.js';
@@ -26,45 +28,27 @@ export const UIStrings = {
26
28
  * @description Text to describe the total reflow time
27
29
  */
28
30
  totalReflowTime: 'Total reflow time',
31
+ /**
32
+ * @description Text to describe CPU processor tasks that could not be attributed to any specific source code.
33
+ */
34
+ unattributed: 'Unattributed',
29
35
  };
30
36
  // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/ForcedReflow.ts', UIStrings);
31
37
  export const i18nString = (i18nId, values) => ({i18nId, values}); // i18n.i18n.getLocalizedString.bind(undefined, str_);
32
- function aggregateForcedReflow(data, entryToNodeMap) {
38
+ function getCallFrameId(callFrame) {
39
+ return callFrame.scriptId + ':' + callFrame.lineNumber + ':' + callFrame.columnNumber;
40
+ }
41
+ function getLargestTopLevelFunctionData(forcedReflowEvents, traceParsedData) {
42
+ const entryToNodeMap = traceParsedData.Renderer.entryToNode;
33
43
  const dataByTopLevelFunction = new Map();
34
- const bottomUpDataMap = new Map();
35
- const forcedReflowEvents = data.get('FORCED_REFLOW');
36
- if (!forcedReflowEvents || forcedReflowEvents.length === 0) {
37
- return [undefined, []];
44
+ if (forcedReflowEvents.length === 0) {
45
+ return;
38
46
  }
39
- forcedReflowEvents.forEach(e => {
47
+ for (const event of forcedReflowEvents) {
40
48
  // Gather the stack traces by searching in the tree
41
- const traceNode = entryToNodeMap.get(e);
49
+ const traceNode = entryToNodeMap.get(event);
42
50
  if (!traceNode) {
43
- return;
44
- }
45
- // Compute call stack fully
46
- const bottomUpData = [];
47
- let currentNode = traceNode;
48
- let previousNode;
49
- const childStack = [];
50
- // Some profileCalls maybe constructed as its children in hierarchy tree
51
- while (currentNode.children.length > 0) {
52
- const childNode = currentNode.children[0];
53
- if (!previousNode) {
54
- previousNode = childNode;
55
- }
56
- const eventData = childNode.entry;
57
- if (Types.Events.isProfileCall(eventData)) {
58
- childStack.push(eventData.callFrame);
59
- }
60
- currentNode = childNode;
61
- }
62
- // In order to avoid too much information, we only contain 2 levels bottomUp data,
63
- while (childStack.length > 0 && bottomUpData.length < 2) {
64
- const traceData = childStack.pop();
65
- if (traceData) {
66
- bottomUpData.push(traceData);
67
- }
51
+ continue;
68
52
  }
69
53
  let node = traceNode.parent;
70
54
  let topLevelFunctionCall;
@@ -72,9 +56,8 @@ function aggregateForcedReflow(data, entryToNodeMap) {
72
56
  while (node) {
73
57
  const eventData = node.entry;
74
58
  if (Types.Events.isProfileCall(eventData)) {
75
- if (bottomUpData.length < 2) {
76
- bottomUpData.push(eventData.callFrame);
77
- }
59
+ topLevelFunctionCall = eventData.callFrame;
60
+ topLevelFunctionCallEvent = eventData;
78
61
  }
79
62
  else {
80
63
  // We have finished searching bottom up data
@@ -82,72 +65,30 @@ function aggregateForcedReflow(data, entryToNodeMap) {
82
65
  Types.Events.objectIsCallFrame(eventData.args.data)) {
83
66
  topLevelFunctionCall = eventData.args.data;
84
67
  topLevelFunctionCallEvent = eventData;
85
- if (bottomUpData.length === 0) {
86
- bottomUpData.push(topLevelFunctionCall);
87
- }
88
- }
89
- else {
90
- // Sometimes the top level task can be other JSInvocation event
91
- // then we use the top level profile call as topLevelFunctionCall's data
92
- const previousData = previousNode?.entry;
93
- if (previousData && Types.Events.isProfileCall(previousData)) {
94
- topLevelFunctionCall = previousData.callFrame;
95
- topLevelFunctionCallEvent = previousNode?.entry;
96
- }
97
68
  }
98
69
  break;
99
70
  }
100
- previousNode = node;
101
71
  node = node.parent;
102
72
  }
103
- if (!topLevelFunctionCall || !topLevelFunctionCallEvent || bottomUpData.length === 0) {
104
- return;
73
+ if (!topLevelFunctionCall || !topLevelFunctionCallEvent) {
74
+ continue;
105
75
  }
106
- const bottomUpDataId = bottomUpData[0].scriptId + ':' + bottomUpData[0].lineNumber + ':' + bottomUpData[0].columnNumber + ':';
107
- const data = bottomUpDataMap.get(bottomUpDataId) ?? {
108
- bottomUpData: bottomUpData[0],
109
- totalTime: 0,
110
- relatedEvents: [],
111
- };
112
- data.totalTime += (e.dur ?? 0);
113
- data.relatedEvents.push(e);
114
- bottomUpDataMap.set(bottomUpDataId, data);
115
- const aggregatedDataId = topLevelFunctionCall.scriptId + ':' + topLevelFunctionCall.lineNumber + ':' + topLevelFunctionCall.columnNumber;
116
- if (!dataByTopLevelFunction.has(aggregatedDataId)) {
117
- dataByTopLevelFunction.set(aggregatedDataId, {
118
- topLevelFunctionCall,
119
- totalReflowTime: 0,
120
- bottomUpData: new Set(),
121
- topLevelFunctionCallEvents: [],
122
- });
123
- }
124
- const aggregatedData = dataByTopLevelFunction.get(aggregatedDataId);
125
- if (aggregatedData) {
126
- aggregatedData.totalReflowTime += (e.dur ?? 0);
127
- aggregatedData.bottomUpData.add(bottomUpDataId);
128
- aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);
129
- }
130
- });
131
- let topTimeConsumingDataId = '';
132
- let maxTime = 0;
133
- dataByTopLevelFunction.forEach((value, key) => {
134
- if (value.totalReflowTime > maxTime) {
135
- maxTime = value.totalReflowTime;
136
- topTimeConsumingDataId = key;
76
+ const aggregatedDataId = getCallFrameId(topLevelFunctionCall);
77
+ const aggregatedData = Platform.MapUtilities.getWithDefault(dataByTopLevelFunction, aggregatedDataId, () => ({
78
+ topLevelFunctionCall,
79
+ totalReflowTime: 0,
80
+ topLevelFunctionCallEvents: [],
81
+ }));
82
+ aggregatedData.totalReflowTime += (event.dur ?? 0);
83
+ aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);
84
+ }
85
+ let topTimeConsumingData = undefined;
86
+ dataByTopLevelFunction.forEach(data => {
87
+ if (!topTimeConsumingData || data.totalReflowTime > topTimeConsumingData.totalReflowTime) {
88
+ topTimeConsumingData = data;
137
89
  }
138
90
  });
139
- const aggregatedBottomUpData = [];
140
- const topLevelFunctionCallData = dataByTopLevelFunction.get(topTimeConsumingDataId);
141
- const dataSet = dataByTopLevelFunction.get(topTimeConsumingDataId)?.bottomUpData;
142
- if (dataSet) {
143
- dataSet.forEach(value => {
144
- const callStackData = bottomUpDataMap.get(value);
145
- if (callStackData && callStackData.totalTime > Helpers.Timing.milliToMicro(Types.Timing.Milli(1))) {
146
- aggregatedBottomUpData.push(callStackData);
147
- }
148
- });
149
- }
150
- return [topLevelFunctionCallData, aggregatedBottomUpData];
91
+ return topTimeConsumingData;
151
92
  }
152
93
  function finalize(partialModel) {
153
94
  return {
@@ -156,26 +97,41 @@ function finalize(partialModel) {
156
97
  title: i18nString(UIStrings.title),
157
98
  description: i18nString(UIStrings.description),
158
99
  category: InsightCategory.ALL,
159
- state: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0 ?
160
- 'fail' :
161
- 'pass',
100
+ state: partialModel.aggregatedBottomUpData.length !== 0 ? 'fail' : 'pass',
162
101
  ...partialModel,
163
102
  };
164
103
  }
165
- export function generateInsight(traceParsedData, _context) {
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');
104
+ function getBottomCallFrameForEvent(event, traceParsedData) {
105
+ const profileStackTrace = Extras.StackTraceForEvent.get(event, traceParsedData);
106
+ const eventStackTrace = Helpers.Trace.getZeroIndexedStackTraceForEvent(event);
107
+ return profileStackTrace?.callFrames[0] ?? eventStackTrace?.[0] ?? null;
108
+ }
109
+ export function generateInsight(traceParsedData, context) {
110
+ const isWithinContext = (event) => {
111
+ const frameId = Helpers.Trace.frameIDForEvent(event);
112
+ if (frameId !== context.frameId) {
113
+ return false;
114
+ }
115
+ return Helpers.Timing.eventIsInBounds(event, context.bounds);
116
+ };
117
+ const bottomUpDataMap = new Map();
118
+ const events = traceParsedData.Warnings.perWarning.get('FORCED_REFLOW')?.filter(isWithinContext) ?? [];
119
+ for (const event of events) {
120
+ const bottomCallFrame = getBottomCallFrameForEvent(event, traceParsedData);
121
+ const bottomCallId = bottomCallFrame ? getCallFrameId(bottomCallFrame) : 'UNATTRIBUTED';
122
+ const bottomUpData = Platform.MapUtilities.getWithDefault(bottomUpDataMap, bottomCallId, () => ({
123
+ bottomUpData: bottomCallFrame,
124
+ totalTime: 0,
125
+ relatedEvents: [],
126
+ }));
127
+ bottomUpData.totalTime += event.dur ?? 0;
128
+ bottomUpData.relatedEvents.push(event);
173
129
  }
174
- const [topLevelFunctionCallData, aggregatedBottomUpData] = aggregateForcedReflow(warningsData.perWarning, entryToNodeMap);
130
+ const topLevelFunctionCallData = getLargestTopLevelFunctionData(events, traceParsedData);
175
131
  return finalize({
176
- relatedEvents: topLevelFunctionCallData?.topLevelFunctionCallEvents,
132
+ relatedEvents: events,
177
133
  topLevelFunctionCallData,
178
- aggregatedBottomUpData,
134
+ aggregatedBottomUpData: [...bottomUpDataMap.values()],
179
135
  });
180
136
  }
181
137
  //# sourceMappingURL=ForcedReflow.js.map
@@ -1 +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,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAInD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CA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C,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 * as Handlers from '../handlers/handlers.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 InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n} from './types.js';\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} as const;\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: Array<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 insightKey: InsightKeys.FORCED_REFLOW,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n state: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0 ?\n 'fail' :\n 'pass',\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n traceParsedData: Handlers.Types.ParsedTrace, _context: InsightSetContext): 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"]}
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,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC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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 type * as Protocol from '../../../generated/protocol.js';\nimport * as Extras from '../extras/extras.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n} from './types.js';\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 * @description Text to describe CPU processor tasks that could not be attributed to any specific source code.\n */\n unattributed: 'Unattributed',\n} as const;\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\nexport interface BottomUpCallStack {\n /**\n * `null` indicates that this data is for unattributed force reflows.\n */\n bottomUpData: Types.Events.CallFrame|Protocol.Runtime.CallFrame|null;\n totalTime: number;\n relatedEvents: Types.Events.Event[];\n}\n\nexport interface ForcedReflowAggregatedData {\n topLevelFunctionCall: Types.Events.CallFrame|Protocol.Runtime.CallFrame;\n totalReflowTime: number;\n topLevelFunctionCallEvents: Types.Events.Event[];\n}\n\nfunction getCallFrameId(callFrame: Types.Events.CallFrame|Protocol.Runtime.CallFrame): string {\n return callFrame.scriptId + ':' + callFrame.lineNumber + ':' + callFrame.columnNumber;\n}\n\nfunction getLargestTopLevelFunctionData(\n forcedReflowEvents: Types.Events.Event[], traceParsedData: Handlers.Types.ParsedTrace): ForcedReflowAggregatedData|\n undefined {\n const entryToNodeMap = traceParsedData.Renderer.entryToNode;\n const dataByTopLevelFunction = new Map<string, ForcedReflowAggregatedData>();\n if (forcedReflowEvents.length === 0) {\n return;\n }\n\n for (const event of forcedReflowEvents) {\n // Gather the stack traces by searching in the tree\n const traceNode = entryToNodeMap.get(event);\n if (!traceNode) {\n continue;\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 topLevelFunctionCall = eventData.callFrame;\n topLevelFunctionCallEvent = eventData;\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 }\n break;\n }\n node = node.parent;\n }\n\n if (!topLevelFunctionCall || !topLevelFunctionCallEvent) {\n continue;\n }\n\n const aggregatedDataId = getCallFrameId(topLevelFunctionCall);\n const aggregatedData =\n Platform.MapUtilities.getWithDefault(dataByTopLevelFunction, aggregatedDataId, () => ({\n topLevelFunctionCall,\n totalReflowTime: 0,\n topLevelFunctionCallEvents: [],\n }));\n aggregatedData.totalReflowTime += (event.dur ?? 0);\n aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);\n }\n\n let topTimeConsumingData: ForcedReflowAggregatedData|undefined = undefined;\n dataByTopLevelFunction.forEach(data => {\n if (!topTimeConsumingData || data.totalReflowTime > topTimeConsumingData.totalReflowTime) {\n topTimeConsumingData = data;\n }\n });\n\n return topTimeConsumingData;\n}\n\nfunction finalize(partialModel: PartialInsightModel<ForcedReflowInsightModel>): ForcedReflowInsightModel {\n return {\n insightKey: InsightKeys.FORCED_REFLOW,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n state: partialModel.aggregatedBottomUpData.length !== 0 ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nfunction getBottomCallFrameForEvent(event: Types.Events.Event, traceParsedData: Handlers.Types.ParsedTrace):\n Types.Events.CallFrame|Protocol.Runtime.CallFrame|null {\n const profileStackTrace = Extras.StackTraceForEvent.get(event, traceParsedData);\n const eventStackTrace = Helpers.Trace.getZeroIndexedStackTraceForEvent(event);\n\n return profileStackTrace?.callFrames[0] ?? eventStackTrace?.[0] ?? null;\n}\n\nexport function generateInsight(\n traceParsedData: Handlers.Types.ParsedTrace, context: InsightSetContext): ForcedReflowInsightModel {\n const isWithinContext = (event: Types.Events.Event): boolean => {\n const frameId = Helpers.Trace.frameIDForEvent(event);\n if (frameId !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n };\n\n const bottomUpDataMap = new Map<string, BottomUpCallStack>();\n const events = traceParsedData.Warnings.perWarning.get('FORCED_REFLOW')?.filter(isWithinContext) ?? [];\n for (const event of events) {\n const bottomCallFrame = getBottomCallFrameForEvent(event, traceParsedData);\n const bottomCallId = bottomCallFrame ? getCallFrameId(bottomCallFrame) : 'UNATTRIBUTED';\n const bottomUpData =\n Platform.MapUtilities.getWithDefault(bottomUpDataMap, bottomCallId, () => ({\n bottomUpData: bottomCallFrame,\n totalTime: 0,\n relatedEvents: [],\n }));\n bottomUpData.totalTime += event.dur ?? 0;\n bottomUpData.relatedEvents.push(event);\n }\n\n const topLevelFunctionCallData = getLargestTopLevelFunctionData(events, traceParsedData);\n\n return finalize({\n relatedEvents: events,\n topLevelFunctionCallData,\n aggregatedBottomUpData: [...bottomUpDataMap.values()],\n });\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  export * as CLSCulprits from './CLSCulprits.js';
2
2
  export * as DocumentLatency from './DocumentLatency.js';
3
3
  export * as DOMSize from './DOMSize.js';
4
- export * as DuplicateJavaScript from './DuplicateJavaScript.js';
4
+ export * as DuplicatedJavaScript from './DuplicatedJavaScript.js';
5
5
  export * as FontDisplay from './FontDisplay.js';
6
6
  export * as ForcedReflow from './ForcedReflow.js';
7
7
  export * as ImageDelivery from './ImageDelivery.js';
@@ -12,4 +12,5 @@ export * as NetworkDependencyTree from './NetworkDependencyTree.js';
12
12
  export * as RenderBlocking from './RenderBlocking.js';
13
13
  export * as SlowCSSSelector from './SlowCSSSelector.js';
14
14
  export * as ThirdParties from './ThirdParties.js';
15
+ export * as UseCache from './UseCache.js';
15
16
  export * as Viewport from './Viewport.js';
@@ -4,7 +4,7 @@
4
4
  export * as CLSCulprits from './CLSCulprits.js';
5
5
  export * as DocumentLatency from './DocumentLatency.js';
6
6
  export * as DOMSize from './DOMSize.js';
7
- export * as DuplicateJavaScript from './DuplicateJavaScript.js';
7
+ export * as DuplicatedJavaScript from './DuplicatedJavaScript.js';
8
8
  export * as FontDisplay from './FontDisplay.js';
9
9
  export * as ForcedReflow from './ForcedReflow.js';
10
10
  export * as ImageDelivery from './ImageDelivery.js';
@@ -15,5 +15,6 @@ export * as NetworkDependencyTree from './NetworkDependencyTree.js';
15
15
  export * as RenderBlocking from './RenderBlocking.js';
16
16
  export * as SlowCSSSelector from './SlowCSSSelector.js';
17
17
  export * as ThirdParties from './ThirdParties.js';
18
+ export * as UseCache from './UseCache.js';
18
19
  export * as Viewport from './Viewport.js';
19
20
  //# sourceMappingURL=Models.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Models.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Models.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,mBAAmB,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,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 * as CLSCulprits from './CLSCulprits.js';\nexport * as DocumentLatency from './DocumentLatency.js';\nexport * as DOMSize from './DOMSize.js';\nexport * as DuplicateJavaScript from './DuplicateJavaScript.js';\nexport * as FontDisplay from './FontDisplay.js';\nexport * as ForcedReflow from './ForcedReflow.js';\nexport * as ImageDelivery from './ImageDelivery.js';\nexport * as InteractionToNextPaint from './InteractionToNextPaint.js';\nexport * as LCPDiscovery from './LCPDiscovery.js';\nexport * as LCPPhases from './LCPPhases.js';\nexport * as NetworkDependencyTree from './NetworkDependencyTree.js';\nexport * as RenderBlocking from './RenderBlocking.js';\nexport * as SlowCSSSelector from './SlowCSSSelector.js';\nexport * as ThirdParties from './ThirdParties.js';\nexport * as Viewport from './Viewport.js';\n"]}
1
+ {"version":3,"file":"Models.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Models.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,oBAAoB,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,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 * as CLSCulprits from './CLSCulprits.js';\nexport * as DocumentLatency from './DocumentLatency.js';\nexport * as DOMSize from './DOMSize.js';\nexport * as DuplicatedJavaScript from './DuplicatedJavaScript.js';\nexport * as FontDisplay from './FontDisplay.js';\nexport * as ForcedReflow from './ForcedReflow.js';\nexport * as ImageDelivery from './ImageDelivery.js';\nexport * as InteractionToNextPaint from './InteractionToNextPaint.js';\nexport * as LCPDiscovery from './LCPDiscovery.js';\nexport * as LCPPhases from './LCPPhases.js';\nexport * as NetworkDependencyTree from './NetworkDependencyTree.js';\nexport * as RenderBlocking from './RenderBlocking.js';\nexport * as SlowCSSSelector from './SlowCSSSelector.js';\nexport * as ThirdParties from './ThirdParties.js';\nexport * as UseCache from './UseCache.js';\nexport * as Viewport from './Viewport.js';\n"]}
@@ -30,10 +30,11 @@ export interface CriticalRequestNode {
30
30
  timeFromInitialRequest: Types.Timing.Micro;
31
31
  children: CriticalRequestNode[];
32
32
  isLongest?: boolean;
33
- chain?: Types.Events.SyntheticNetworkRequest[];
33
+ relatedRequests: Set<Types.Events.SyntheticNetworkRequest>;
34
34
  }
35
35
  export type NetworkDependencyTreeInsightModel = InsightModel<typeof UIStrings, {
36
36
  rootNodes: CriticalRequestNode[];
37
37
  maxTime: Types.Timing.Micro;
38
+ fail: boolean;
38
39
  }>;
39
40
  export declare function generateInsight(_parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): NetworkDependencyTreeInsightModel;
@@ -45,7 +45,7 @@ function finalize(partialModel) {
45
45
  title: i18nString(UIStrings.title),
46
46
  description: i18nString(UIStrings.description),
47
47
  category: InsightCategory.LCP,
48
- state: partialModel.rootNodes.length > 0 ? 'fail' : 'pass',
48
+ state: partialModel.fail ? 'fail' : 'pass',
49
49
  ...partialModel,
50
50
  };
51
51
  }
@@ -81,16 +81,21 @@ export function generateInsight(_parsedTrace, context) {
81
81
  return finalize({
82
82
  rootNodes: [],
83
83
  maxTime: Types.Timing.Micro(0),
84
+ fail: false,
84
85
  });
85
86
  }
86
87
  const rootNodes = [];
87
88
  const relatedEvents = new Map();
88
89
  let maxTime = Types.Timing.Micro(0);
90
+ let fail = false;
89
91
  let longestChain = [];
90
92
  function addChain(path) {
91
93
  if (path.length === 0) {
92
94
  return;
93
95
  }
96
+ if (path.length >= 2) {
97
+ fail = true;
98
+ }
94
99
  const initialRequest = path[0];
95
100
  const lastRequest = path[path.length - 1];
96
101
  const totalChainTime = Types.Timing.Micro(lastRequest.ts + lastRequest.dur - initialRequest.ts);
@@ -109,12 +114,11 @@ export function generateInsight(_parsedTrace, context) {
109
114
  request,
110
115
  timeFromInitialRequest,
111
116
  children: [],
117
+ relatedRequests: new Set(),
112
118
  };
113
119
  currentNodes.push(found);
114
120
  }
115
- if (request === lastRequest) {
116
- found.chain = path;
117
- }
121
+ path.forEach(request => found?.relatedRequests.add(request));
118
122
  // TODO(b/372897712) Switch the UIString to markdown.
119
123
  relatedEvents.set(request, depth < 2 ? [] : [i18nString(UIStrings.warningDescription)]);
120
124
  currentNodes = found.children;
@@ -164,6 +168,7 @@ export function generateInsight(_parsedTrace, context) {
164
168
  return finalize({
165
169
  rootNodes,
166
170
  maxTime,
171
+ fail,
167
172
  relatedEvents,
168
173
  });
169
174
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NetworkDependencyTree.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/NetworkDependencyTree.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAGnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,GAOhB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,yBAAyB;IAChC;;OAEG;IACH,WAAW,EACP,0QAA0Q;IAC9Q;;OAEG;IACH,kBAAkB,EACd,sLAAsL;IAC1L;;OAEG;IACH,uBAAuB,EAAE,qDAAqD;IAC9E;;;OAGG;IACH,sBAAsB,EAAE,4BAA4B;CAC5C,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,gDAAgD,EAAE,SAAS,CAAC,CAAC;AACtG,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,C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AAE,CAAC;QAC5B,IAAI,YAAY,GAAG,SAAS,CAAC;QAC7B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;YACnC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;YAClE,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;gBACvB,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,SAAS;QACT,OAAO;QACP,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2025 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 Protocol from '../../../generated/protocol.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type InsightSetContextWithNavigation,\n type PartialInsightModel,\n type RelatedEventsMap,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that recommends avoiding chaining critical requests.\n */\n title: 'Network dependency tree',\n /**\n * @description Description of an insight that recommends avoiding chaining critical requests.\n */\n description:\n '[Avoid chaining critical requests](https://developer.chrome.com/docs/lighthouse/performance/critical-request-chains) by reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load.',\n /**\n * @description Description of the warning that recommends avoiding chaining critical requests.\n */\n warningDescription:\n 'Avoid chaining critical requests by reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load.',\n /**\n * @description Text status indicating that there isn't long chaining critical network requests.\n */\n noNetworkDependencyTree: 'No rendering tasks impacted by network dependencies',\n /**\n * @description Text for the maximum critical path latency. This refers to the longest chain of network requests that\n * the browser must download before it can render the page.\n */\n maxCriticalPathLatency: 'Max critical path latency:'\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/NetworkDependencyTree.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n// XHRs are fetched at High priority, but we exclude them, as they are unlikely to be critical\n// Images are also non-critical.\nconst nonCriticalResourceTypes = new Set<Protocol.Network.ResourceType>([\n Protocol.Network.ResourceType.Image,\n Protocol.Network.ResourceType.XHR,\n Protocol.Network.ResourceType.Fetch,\n Protocol.Network.ResourceType.EventSource,\n]);\n\nexport interface CriticalRequestNode {\n request: Types.Events.SyntheticNetworkRequest;\n timeFromInitialRequest: Types.Timing.Micro;\n children: CriticalRequestNode[];\n isLongest?: boolean;\n chain?: Types.Events.SyntheticNetworkRequest[];\n}\n\nexport type NetworkDependencyTreeInsightModel = InsightModel<typeof UIStrings, {\n rootNodes: CriticalRequestNode[],\n maxTime: Types.Timing.Micro,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<NetworkDependencyTreeInsightModel>):\n NetworkDependencyTreeInsightModel {\n return {\n insightKey: InsightKeys.NETWORK_DEPENDENCY_TREE,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.LCP,\n state: partialModel.rootNodes.length > 0 ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nfunction isCritical(request: Types.Events.SyntheticNetworkRequest, context: InsightSetContextWithNavigation): boolean {\n // The main resource is always critical.\n if (request.args.data.requestId === context.navigationId) {\n return true;\n }\n\n // Treat any preloaded resource as non-critical\n if (request.args.data.isLinkPreload) {\n return false;\n }\n\n // Iframes are considered High Priority but they are not render blocking\n const isIframe = request.args.data.resourceType === Protocol.Network.ResourceType.Document &&\n request.args.data.frame !== context.frameId;\n\n if (nonCriticalResourceTypes.has(request.args.data.resourceType) || isIframe ||\n // Treat any missed images, primarily favicons, as non-critical resources\n request.args.data.mimeType.startsWith('image/')) {\n return false;\n }\n\n // Requests that have no initiatorRequest are typically ambiguous late-load assets.\n // Even on the off chance they were important, we don't have any parent to display for them.\n const initiatorUrl =\n request.args.data.initiator?.url || Helpers.Trace.getZeroIndexedStackTraceForEvent(request)?.at(0)?.url;\n if (!initiatorUrl) {\n return false;\n }\n\n const isBlocking = Helpers.Network.isSyntheticNetworkRequestEventRenderBlocking(request);\n const isHighPriority = Helpers.Network.isSyntheticNetworkRequestHighPriority(request);\n return isHighPriority || isBlocking;\n}\n\nexport function generateInsight(\n _parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): NetworkDependencyTreeInsightModel {\n if (!context.navigation) {\n return finalize({\n rootNodes: [],\n maxTime: Types.Timing.Micro(0),\n });\n }\n\n const rootNodes: CriticalRequestNode[] = [];\n const relatedEvents: RelatedEventsMap = new Map();\n let maxTime = Types.Timing.Micro(0);\n\n let longestChain: Types.Events.SyntheticNetworkRequest[] = [];\n\n function addChain(path: Types.Events.SyntheticNetworkRequest[]): void {\n if (path.length === 0) {\n return;\n }\n const initialRequest = path[0];\n const lastRequest = path[path.length - 1];\n const totalChainTime = Types.Timing.Micro(lastRequest.ts + lastRequest.dur - initialRequest.ts);\n if (totalChainTime > maxTime) {\n maxTime = totalChainTime;\n longestChain = path;\n }\n\n let currentNodes = rootNodes;\n\n for (let depth = 0; depth < path.length; ++depth) {\n const request = path[depth];\n // find the request\n let found = currentNodes.find(node => node.request === request);\n\n if (!found) {\n const timeFromInitialRequest = Types.Timing.Micro(request.ts + request.dur - initialRequest.ts);\n found = {\n request,\n timeFromInitialRequest,\n children: [],\n };\n currentNodes.push(found);\n }\n\n if (request === lastRequest) {\n found.chain = path;\n }\n // TODO(b/372897712) Switch the UIString to markdown.\n relatedEvents.set(request, depth < 2 ? [] : [i18nString(UIStrings.warningDescription)]);\n\n currentNodes = found.children;\n }\n }\n // By default `traverse` will discover nodes in BFS-order regardless of dependencies, but\n // here we need traversal in a topological sort order. We'll visit a node only when its\n // dependencies have been met.\n const seenNodes = new Set<Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>>();\n function getNextNodes(node: Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>):\n Array<Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>> {\n return node.getDependents().filter(n => n.getDependencies().every(d => seenNodes.has(d)));\n }\n\n context.lantern?.graph.traverse((node, traversalPath) => {\n seenNodes.add(node);\n if (node.type !== 'network') {\n return;\n }\n const networkNode = node;\n if (!isCritical(networkNode.rawRequest, context)) {\n return;\n }\n\n const networkPath = traversalPath.filter(node => node.type === 'network').reverse().map(node => node.rawRequest);\n\n // Ignore if some ancestor is not a critical request.\n if (networkPath.some(request => (!isCritical(request, context)))) {\n return;\n }\n\n // Ignore non-network things (like data urls).\n if (node.isNonNetworkProtocol) {\n return;\n }\n\n addChain(networkPath);\n }, getNextNodes);\n\n // Mark the longest chain\n if (longestChain.length > 0) {\n let currentNodes = rootNodes;\n for (const request of longestChain) {\n const found = currentNodes.find(node => node.request === request);\n if (found) {\n found.isLongest = true;\n currentNodes = found.children;\n } else {\n console.error('Some request in the longest chain is not found');\n }\n }\n }\n\n return finalize({\n rootNodes,\n maxTime,\n relatedEvents,\n });\n}\n"]}
1
+ {"version":3,"file":"NetworkDependencyTree.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/NetworkDependencyTree.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAGnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,GAOhB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAA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AAO;QACT,CAAC;QAED,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEjH,qDAAqD;QACrD,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACjE,OAAO;QACT,CAAC;QAED,8CAA8C;QAC9C,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,QAAQ,CAAC,WAAW,CAAC,CAAC;IACxB,CAAC,EAAE,YAAY,CAAC,CAAC;IAEjB,yBAAyB;IACzB,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,IAAI,YAAY,GAAG,SAAS,CAAC;QAC7B,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;YACnC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;YAClE,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC;gBACvB,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;YAClE,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,SAAS;QACT,OAAO;QACP,IAAI;QACJ,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2025 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 Protocol from '../../../generated/protocol.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type InsightSetContextWithNavigation,\n type PartialInsightModel,\n type RelatedEventsMap,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that recommends avoiding chaining critical requests.\n */\n title: 'Network dependency tree',\n /**\n * @description Description of an insight that recommends avoiding chaining critical requests.\n */\n description:\n '[Avoid chaining critical requests](https://developer.chrome.com/docs/lighthouse/performance/critical-request-chains) by reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load.',\n /**\n * @description Description of the warning that recommends avoiding chaining critical requests.\n */\n warningDescription:\n 'Avoid chaining critical requests by reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load.',\n /**\n * @description Text status indicating that there isn't long chaining critical network requests.\n */\n noNetworkDependencyTree: 'No rendering tasks impacted by network dependencies',\n /**\n * @description Text for the maximum critical path latency. This refers to the longest chain of network requests that\n * the browser must download before it can render the page.\n */\n maxCriticalPathLatency: 'Max critical path latency:'\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/NetworkDependencyTree.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n// XHRs are fetched at High priority, but we exclude them, as they are unlikely to be critical\n// Images are also non-critical.\nconst nonCriticalResourceTypes = new Set<Protocol.Network.ResourceType>([\n Protocol.Network.ResourceType.Image,\n Protocol.Network.ResourceType.XHR,\n Protocol.Network.ResourceType.Fetch,\n Protocol.Network.ResourceType.EventSource,\n]);\n\nexport interface CriticalRequestNode {\n request: Types.Events.SyntheticNetworkRequest;\n timeFromInitialRequest: Types.Timing.Micro;\n children: CriticalRequestNode[];\n isLongest?: boolean;\n // Store all the requests that appear in any chains this request appears in.\n // Use set to avoid duplication.\n relatedRequests: Set<Types.Events.SyntheticNetworkRequest>;\n}\n\nexport type NetworkDependencyTreeInsightModel = InsightModel<typeof UIStrings, {\n rootNodes: CriticalRequestNode[],\n maxTime: Types.Timing.Micro,\n fail: boolean,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<NetworkDependencyTreeInsightModel>):\n NetworkDependencyTreeInsightModel {\n return {\n insightKey: InsightKeys.NETWORK_DEPENDENCY_TREE,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.LCP,\n state: partialModel.fail ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nfunction isCritical(request: Types.Events.SyntheticNetworkRequest, context: InsightSetContextWithNavigation): boolean {\n // The main resource is always critical.\n if (request.args.data.requestId === context.navigationId) {\n return true;\n }\n\n // Treat any preloaded resource as non-critical\n if (request.args.data.isLinkPreload) {\n return false;\n }\n\n // Iframes are considered High Priority but they are not render blocking\n const isIframe = request.args.data.resourceType === Protocol.Network.ResourceType.Document &&\n request.args.data.frame !== context.frameId;\n\n if (nonCriticalResourceTypes.has(request.args.data.resourceType) || isIframe ||\n // Treat any missed images, primarily favicons, as non-critical resources\n request.args.data.mimeType.startsWith('image/')) {\n return false;\n }\n\n // Requests that have no initiatorRequest are typically ambiguous late-load assets.\n // Even on the off chance they were important, we don't have any parent to display for them.\n const initiatorUrl =\n request.args.data.initiator?.url || Helpers.Trace.getZeroIndexedStackTraceForEvent(request)?.at(0)?.url;\n if (!initiatorUrl) {\n return false;\n }\n\n const isBlocking = Helpers.Network.isSyntheticNetworkRequestEventRenderBlocking(request);\n const isHighPriority = Helpers.Network.isSyntheticNetworkRequestHighPriority(request);\n return isHighPriority || isBlocking;\n}\n\nexport function generateInsight(\n _parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): NetworkDependencyTreeInsightModel {\n if (!context.navigation) {\n return finalize({\n rootNodes: [],\n maxTime: Types.Timing.Micro(0),\n fail: false,\n });\n }\n\n const rootNodes: CriticalRequestNode[] = [];\n const relatedEvents: RelatedEventsMap = new Map();\n let maxTime = Types.Timing.Micro(0);\n let fail = false;\n\n let longestChain: Types.Events.SyntheticNetworkRequest[] = [];\n\n function addChain(path: Types.Events.SyntheticNetworkRequest[]): void {\n if (path.length === 0) {\n return;\n }\n if (path.length >= 2) {\n fail = true;\n }\n const initialRequest = path[0];\n const lastRequest = path[path.length - 1];\n const totalChainTime = Types.Timing.Micro(lastRequest.ts + lastRequest.dur - initialRequest.ts);\n if (totalChainTime > maxTime) {\n maxTime = totalChainTime;\n longestChain = path;\n }\n\n let currentNodes = rootNodes;\n\n for (let depth = 0; depth < path.length; ++depth) {\n const request = path[depth];\n // find the request\n let found = currentNodes.find(node => node.request === request);\n\n if (!found) {\n const timeFromInitialRequest = Types.Timing.Micro(request.ts + request.dur - initialRequest.ts);\n found = {\n request,\n timeFromInitialRequest,\n children: [],\n relatedRequests: new Set(),\n };\n currentNodes.push(found);\n }\n\n path.forEach(request => found?.relatedRequests.add(request));\n\n // TODO(b/372897712) Switch the UIString to markdown.\n relatedEvents.set(request, depth < 2 ? [] : [i18nString(UIStrings.warningDescription)]);\n\n currentNodes = found.children;\n }\n }\n // By default `traverse` will discover nodes in BFS-order regardless of dependencies, but\n // here we need traversal in a topological sort order. We'll visit a node only when its\n // dependencies have been met.\n const seenNodes = new Set<Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>>();\n function getNextNodes(node: Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>):\n Array<Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>> {\n return node.getDependents().filter(n => n.getDependencies().every(d => seenNodes.has(d)));\n }\n\n context.lantern?.graph.traverse((node, traversalPath) => {\n seenNodes.add(node);\n if (node.type !== 'network') {\n return;\n }\n const networkNode = node;\n if (!isCritical(networkNode.rawRequest, context)) {\n return;\n }\n\n const networkPath = traversalPath.filter(node => node.type === 'network').reverse().map(node => node.rawRequest);\n\n // Ignore if some ancestor is not a critical request.\n if (networkPath.some(request => (!isCritical(request, context)))) {\n return;\n }\n\n // Ignore non-network things (like data urls).\n if (node.isNonNetworkProtocol) {\n return;\n }\n\n addChain(networkPath);\n }, getNextNodes);\n\n // Mark the longest chain\n if (longestChain.length > 0) {\n let currentNodes = rootNodes;\n for (const request of longestChain) {\n const found = currentNodes.find(node => node.request === request);\n if (found) {\n found.isLongest = true;\n currentNodes = found.children;\n } else {\n console.error('Some request in the longest chain is not found');\n }\n }\n }\n\n return finalize({\n rootNodes,\n maxTime,\n fail,\n relatedEvents,\n });\n}\n"]}
@@ -12,3 +12,7 @@ export declare function getLogNormalScore({ median, p10 }: {
12
12
  median: number;
13
13
  p10: number;
14
14
  }, value: number): number;
15
+ /**
16
+ * Interpolates the y value at a point x on the line defined by (x0, y0) and (x1, y1)
17
+ */
18
+ export declare function linearInterpolation(x0: number, y0: number, x1: number, y1: number, x: number): number;
@@ -83,4 +83,11 @@ export function getLogNormalScore({ median, p10 }, value) {
83
83
  }
84
84
  return score;
85
85
  }
86
+ /**
87
+ * Interpolates the y value at a point x on the line defined by (x0, y0) and (x1, y1)
88
+ */
89
+ export function linearInterpolation(x0, y0, x1, y1, x) {
90
+ const slope = (y1 - y0) / (x1 - x0);
91
+ return y0 + (x - x0) * slope;
92
+ }
86
93
  //# sourceMappingURL=Statistics.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Statistics.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Statistics.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,wIAAwI;AAExI;;;;GAIG;AAEH,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,uDAAuD,CAAC;AAClF,MAAM,iBAAiB,GAAG,qDAAqD,CAAC;AAChF,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,iBAAiB,GAAG,wDAAwD,CAAC;AAEnF;;;;GAIG;AACH,SAAS,GAAG,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GAAG,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n// Lifted from Lighthouse: https://github.com/GoogleChrome/lighthouse/blob/36cac182a6c637b1671c57326d7c0241633d0076/shared/statistics.js\n\n/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// The exact double values for the max and min scores possible in each range.\nconst MIN_PASSING_SCORE = 0.90000000000000002220446049250313080847263336181640625;\nconst MAX_AVERAGE_SCORE = 0.899999999999999911182158029987476766109466552734375;\nconst MIN_AVERAGE_SCORE = 0.5;\nconst MAX_FAILING_SCORE = 0.499999999999999944488848768742172978818416595458984375;\n\n/**\n * Approximates the Gauss error function, the probability that a random variable\n * from the standard normal distribution lies within [-x, x]. Moved from\n * traceviewer.b.math.erf, based on Abramowitz and Stegun, formula 7.1.26.\n */\nfunction erf(x: number): number {\n // erf(-x) = -erf(x);\n const sign = Math.sign(x);\n x = Math.abs(x);\n\n const a1 = 0.254829592;\n const a2 = -0.284496736;\n const a3 = 1.421413741;\n const a4 = -1.453152027;\n const a5 = 1.061405429;\n const p = 0.3275911;\n const t = 1 / (1 + p * x);\n const y = t * (a1 + t * (a2 + t * (a3 + t * (a4 + t * a5))));\n return sign * (1 - y * Math.exp(-x * x));\n}\n\n/**\n * Returns the score (1 - percentile) of `value` in a log-normal distribution\n * specified by the `median` value, at which the score will be 0.5, and a 10th\n * percentile value, at which the score will be 0.9. The score represents the\n * amount of the distribution greater than `value`. All values should be in the\n * same units (e.g. milliseconds). See\n * https://www.desmos.com/calculator/o98tbeyt1t\n * for an interactive view of the relationship between these parameters and the\n * typical parameterization (location and shape) of the log-normal distribution.\n */\nexport function getLogNormalScore({median, p10}: {median: number, p10: number}, value: number): number {\n // Required for the log-normal distribution.\n if (median <= 0) {\n throw new Error('median must be greater than zero');\n }\n if (p10 <= 0) {\n throw new Error('p10 must be greater than zero');\n }\n // Not strictly required, but if p10 > median, it flips around and becomes the p90 point.\n if (p10 >= median) {\n throw new Error('p10 must be less than the median');\n }\n\n // Non-positive values aren't in the distribution, so always 1.\n if (value <= 0) {\n return 1;\n }\n\n // Closest double to `erfc-1(1/5)`.\n const INVERSE_ERFC_ONE_FIFTH = 0.9061938024368232;\n\n // Shape (σ) is `|log(p10/median) / (sqrt(2)*erfc^-1(1/5))|` and\n // standardizedX is `1/2 erfc(log(value/median) / (sqrt(2)*σ))`, so simplify a bit.\n const xRatio = Math.max(Number.MIN_VALUE, value / median); // value and median are > 0, so is ratio.\n const xLogRatio = Math.log(xRatio);\n const p10Ratio = Math.max(Number.MIN_VALUE, p10 / median); // p10 and median are > 0, so is ratio.\n const p10LogRatio = -Math.log(p10Ratio); // negate to keep σ positive.\n const standardizedX = xLogRatio * INVERSE_ERFC_ONE_FIFTH / p10LogRatio;\n const complementaryPercentile = (1 - erf(standardizedX)) / 2;\n\n // Clamp to avoid floating-point out-of-bounds issues and keep score in expected range.\n let score;\n if (value <= p10) {\n // Passing. Clamp to [0.9, 1].\n score = Math.max(MIN_PASSING_SCORE, Math.min(1, complementaryPercentile));\n } else if (value <= median) {\n // Average. Clamp to [0.5, 0.9).\n score = Math.max(MIN_AVERAGE_SCORE, Math.min(MAX_AVERAGE_SCORE, complementaryPercentile));\n } else {\n // Failing. Clamp to [0, 0.5).\n score = Math.max(0, Math.min(MAX_FAILING_SCORE, complementaryPercentile));\n }\n return score;\n}\n"]}
1
+ {"version":3,"file":"Statistics.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Statistics.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,wIAAwI;AAExI;;;;GAIG;AAEH,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,uDAAuD,CAAC;AAClF,MAAM,iBAAiB,G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,uBAAuB,CAAC,CAAC,CAAC;IAC5F,CAAC;SAAM,CAAC;QACN,8BAA8B;QAC9B,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,EAAU,EAAE,CAAS;IAC3F,MAAM,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC;AAC/B,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n// Lifted from Lighthouse: https://github.com/GoogleChrome/lighthouse/blob/36cac182a6c637b1671c57326d7c0241633d0076/shared/statistics.js\n\n/**\n * @license\n * Copyright 2017 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// The exact double values for the max and min scores possible in each range.\nconst MIN_PASSING_SCORE = 0.90000000000000002220446049250313080847263336181640625;\nconst MAX_AVERAGE_SCORE = 0.899999999999999911182158029987476766109466552734375;\nconst MIN_AVERAGE_SCORE = 0.5;\nconst MAX_FAILING_SCORE = 0.499999999999999944488848768742172978818416595458984375;\n\n/**\n * Approximates the Gauss error function, the probability that a random variable\n * from the standard normal distribution lies within [-x, x]. Moved from\n * traceviewer.b.math.erf, based on Abramowitz and Stegun, formula 7.1.26.\n */\nfunction erf(x: number): number {\n // erf(-x) = -erf(x);\n const sign = Math.sign(x);\n x = Math.abs(x);\n\n const a1 = 0.254829592;\n const a2 = -0.284496736;\n const a3 = 1.421413741;\n const a4 = -1.453152027;\n const a5 = 1.061405429;\n const p = 0.3275911;\n const t = 1 / (1 + p * x);\n const y = t * (a1 + t * (a2 + t * (a3 + t * (a4 + t * a5))));\n return sign * (1 - y * Math.exp(-x * x));\n}\n\n/**\n * Returns the score (1 - percentile) of `value` in a log-normal distribution\n * specified by the `median` value, at which the score will be 0.5, and a 10th\n * percentile value, at which the score will be 0.9. The score represents the\n * amount of the distribution greater than `value`. All values should be in the\n * same units (e.g. milliseconds). See\n * https://www.desmos.com/calculator/o98tbeyt1t\n * for an interactive view of the relationship between these parameters and the\n * typical parameterization (location and shape) of the log-normal distribution.\n */\nexport function getLogNormalScore({median, p10}: {median: number, p10: number}, value: number): number {\n // Required for the log-normal distribution.\n if (median <= 0) {\n throw new Error('median must be greater than zero');\n }\n if (p10 <= 0) {\n throw new Error('p10 must be greater than zero');\n }\n // Not strictly required, but if p10 > median, it flips around and becomes the p90 point.\n if (p10 >= median) {\n throw new Error('p10 must be less than the median');\n }\n\n // Non-positive values aren't in the distribution, so always 1.\n if (value <= 0) {\n return 1;\n }\n\n // Closest double to `erfc-1(1/5)`.\n const INVERSE_ERFC_ONE_FIFTH = 0.9061938024368232;\n\n // Shape (σ) is `|log(p10/median) / (sqrt(2)*erfc^-1(1/5))|` and\n // standardizedX is `1/2 erfc(log(value/median) / (sqrt(2)*σ))`, so simplify a bit.\n const xRatio = Math.max(Number.MIN_VALUE, value / median); // value and median are > 0, so is ratio.\n const xLogRatio = Math.log(xRatio);\n const p10Ratio = Math.max(Number.MIN_VALUE, p10 / median); // p10 and median are > 0, so is ratio.\n const p10LogRatio = -Math.log(p10Ratio); // negate to keep σ positive.\n const standardizedX = xLogRatio * INVERSE_ERFC_ONE_FIFTH / p10LogRatio;\n const complementaryPercentile = (1 - erf(standardizedX)) / 2;\n\n // Clamp to avoid floating-point out-of-bounds issues and keep score in expected range.\n let score;\n if (value <= p10) {\n // Passing. Clamp to [0.9, 1].\n score = Math.max(MIN_PASSING_SCORE, Math.min(1, complementaryPercentile));\n } else if (value <= median) {\n // Average. Clamp to [0.5, 0.9).\n score = Math.max(MIN_AVERAGE_SCORE, Math.min(MAX_AVERAGE_SCORE, complementaryPercentile));\n } else {\n // Failing. Clamp to [0, 0.5).\n score = Math.max(0, Math.min(MAX_FAILING_SCORE, complementaryPercentile));\n }\n return score;\n}\n\n/**\n * Interpolates the y value at a point x on the line defined by (x0, y0) and (x1, y1)\n */\nexport function linearInterpolation(x0: number, y0: number, x1: number, y1: number, x: number): number {\n const slope = (y1 - y0) / (x1 - x0);\n return y0 + (x - x0) * slope;\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import type * as Handlers from '../handlers/handlers.js';
2
+ import * as Helpers from '../helpers/helpers.js';
3
+ import type * as Types from '../types/types.js';
4
+ import { type InsightModel, type InsightSetContext } from './types.js';
5
+ export declare const UIStrings: {
6
+ /**
7
+ * @description Title of an insight that provides information and suggestions of resources that could improve their caching.
8
+ */
9
+ readonly title: "Use efficient cache lifetimes";
10
+ /**
11
+ * @description Text to tell the user about how caching can help improve performance.
12
+ */
13
+ readonly description: "A long cache lifetime can speed up repeat visits to your page. [Learn more](https://web.dev/uses-long-cache-ttl/).";
14
+ /**
15
+ * @description Column for a font loaded by the page to render text.
16
+ */
17
+ readonly requestColumn: "Request";
18
+ /**
19
+ * @description Column for a resource cache's Time To Live.
20
+ */
21
+ readonly cacheTTL: "Cache TTL";
22
+ /**
23
+ * @description Text describing that there were no requests found that need caching.
24
+ */
25
+ readonly noRequestsToCache: "No requests with inefficient cache policies";
26
+ /**
27
+ * @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.
28
+ * @example {5} PH1
29
+ */
30
+ readonly others: "{PH1} others";
31
+ };
32
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
33
+ export type UseCacheInsightModel = InsightModel<typeof UIStrings, {
34
+ requests: Array<{
35
+ request: Types.Events.SyntheticNetworkRequest;
36
+ ttl: number;
37
+ wastedBytes: number;
38
+ }>;
39
+ totalWastedBytes: number;
40
+ }>;
41
+ /**
42
+ * Determines if a request is "cacheable".
43
+ * A request is "cacheable" if it is of the appropriate protocol and resource type
44
+ * (see Helpers.Network.NON_NETWORK_SCHEMES and Helpers.Network.STATIC_RESOURCE_TYPE)
45
+ * and has the appropriate statusCodes.
46
+ */
47
+ export declare function isCacheable(request: Types.Events.SyntheticNetworkRequest): boolean;
48
+ /**
49
+ * Returns max-age if defined, otherwise expires header if defined, and null if not.
50
+ */
51
+ export declare function computeCacheLifetimeInSeconds(headers: Array<{
52
+ name: string;
53
+ value: string;
54
+ }>, cacheControl: Helpers.Network.CacheControl | null): number | null;
55
+ export declare function getCombinedHeaders(responseHeaders: Array<{
56
+ name: string;
57
+ value: string;
58
+ }>): Map<string, string>;
59
+ /**
60
+ * Returns whether a request contains headers that disable caching.
61
+ * Disabled caching is checked on the 'cache-control' and 'pragma' headers.
62
+ */
63
+ export declare function cachingDisabled(headers: Map<string, string> | null, parsedCacheControl: Helpers.Network.CacheControl | null): boolean;
64
+ export interface CacheableRequest {
65
+ request: Types.Events.SyntheticNetworkRequest;
66
+ ttl: number;
67
+ wastedBytes: number;
68
+ }
69
+ export declare function generateInsight(parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): UseCacheInsightModel;