@paulirish/trace_engine 0.0.36 → 0.0.37
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.
- package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
- package/generated/protocol.d.ts +21 -3
- package/models/trace/Processor.d.ts +1 -1
- package/models/trace/Processor.js +4 -4
- package/models/trace/Processor.js.map +1 -1
- package/models/trace/extras/TimelineJSProfile.d.ts +13 -0
- package/models/trace/extras/TimelineJSProfile.js +55 -0
- package/models/trace/extras/TimelineJSProfile.js.map +1 -0
- package/models/trace/extras/TraceFilter.d.ts +21 -0
- package/models/trace/extras/TraceFilter.js +51 -0
- package/models/trace/extras/TraceFilter.js.map +1 -0
- package/models/trace/extras/TraceTree.d.ts +91 -0
- package/models/trace/extras/TraceTree.js +515 -0
- package/models/trace/extras/TraceTree.js.map +1 -0
- package/models/trace/extras/extras-tsconfig.json +3 -0
- package/models/trace/extras/extras.js.map +1 -1
- package/models/trace/handlers/LargestImagePaintHandler.d.ts +7 -1
- package/models/trace/handlers/LargestImagePaintHandler.js +43 -1
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -1
- package/models/trace/handlers/MetaHandler.js +2 -3
- package/models/trace/handlers/MetaHandler.js.map +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.js +2 -0
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
- package/models/trace/insights/CLSCulprits.d.ts +57 -0
- package/models/trace/insights/CLSCulprits.js +335 -0
- package/models/trace/insights/CLSCulprits.js.map +1 -0
- package/models/trace/insights/Common.d.ts +2 -10
- package/models/trace/insights/Common.js +1 -36
- package/models/trace/insights/Common.js.map +1 -1
- package/models/trace/insights/DocumentLatency.d.ts +3 -3
- package/models/trace/insights/DocumentLatency.js.map +1 -1
- package/models/trace/insights/FontDisplay.d.ts +3 -3
- package/models/trace/insights/FontDisplay.js.map +1 -1
- package/models/trace/insights/InteractionToNextPaint.d.ts +3 -3
- package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
- package/models/trace/insights/LCPDiscovery.d.ts +13 -0
- package/models/trace/insights/LCPDiscovery.js +60 -0
- package/models/trace/insights/LCPDiscovery.js.map +1 -0
- package/models/trace/insights/LCPPhases.d.ts +34 -0
- package/models/trace/insights/LCPPhases.js +97 -0
- package/models/trace/insights/LCPPhases.js.map +1 -0
- package/models/trace/insights/Models.d.ts +10 -0
- package/models/trace/insights/Models.js +14 -0
- package/models/trace/insights/Models.js.map +1 -0
- package/models/trace/insights/RenderBlocking.d.ts +4 -4
- package/models/trace/insights/RenderBlocking.js +1 -16
- package/models/trace/insights/RenderBlocking.js.map +1 -1
- package/models/trace/insights/SlowCSSSelector.d.ts +3 -3
- package/models/trace/insights/SlowCSSSelector.js.map +1 -1
- package/models/trace/insights/ThirdParties.d.ts +13 -0
- package/models/trace/insights/ThirdParties.js +42 -0
- package/models/trace/insights/ThirdParties.js.map +1 -0
- package/models/trace/insights/Viewport.d.ts +3 -3
- package/models/trace/insights/Viewport.js.map +1 -1
- package/models/trace/insights/insights-tsconfig.json +5 -4
- package/models/trace/insights/insights.d.ts +1 -1
- package/models/trace/insights/insights.js +1 -1
- package/models/trace/insights/insights.js.map +1 -1
- package/models/trace/insights/types.d.ts +9 -9
- package/models/trace/insights/types.js.map +1 -1
- package/models/trace/trace-tsconfig.json +6 -0
- package/models/trace/types/TraceEvents.d.ts +22 -5
- package/models/trace/types/TraceEvents.js +5 -3
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/package.json +1 -1
- package/test/test-trace-engine.mjs +12 -16
|
@@ -0,0 +1,335 @@
|
|
|
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 Platform from '../../../core/platform/platform.js';
|
|
5
|
+
import * as Helpers from '../helpers/helpers.js';
|
|
6
|
+
import * as Types from '../types/types.js';
|
|
7
|
+
export function deps() {
|
|
8
|
+
return ['Meta', 'Animations', 'LayoutShifts', 'NetworkRequests'];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Each failure reason is represented by a bit flag. The bit shift operator '<<' is used to define
|
|
12
|
+
* which bit corresponds to each failure reason.
|
|
13
|
+
* https://source.chromium.org/search?q=f:compositor_animations.h%20%22enum%20FailureReason%22
|
|
14
|
+
* @type {{flag: number, failure: AnimationFailureReasons}[]}
|
|
15
|
+
*/
|
|
16
|
+
const ACTIONABLE_FAILURE_REASONS = [
|
|
17
|
+
{
|
|
18
|
+
flag: 1 << 0,
|
|
19
|
+
failure: "ACCELERATED_ANIMATIONS_DISABLED" /* AnimationFailureReasons.ACCELERATED_ANIMATIONS_DISABLED */,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
flag: 1 << 1,
|
|
23
|
+
failure: "EFFECT_SUPPRESSED_BY_DEVTOOLS" /* AnimationFailureReasons.EFFECT_SUPPRESSED_BY_DEVTOOLS */,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
flag: 1 << 2,
|
|
27
|
+
failure: "INVALID_ANIMATION_OR_EFFECT" /* AnimationFailureReasons.INVALID_ANIMATION_OR_EFFECT */,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
flag: 1 << 3,
|
|
31
|
+
failure: "EFFECT_HAS_UNSUPPORTED_TIMING_PARAMS" /* AnimationFailureReasons.EFFECT_HAS_UNSUPPORTED_TIMING_PARAMS */,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
flag: 1 << 4,
|
|
35
|
+
failure: "EFFECT_HAS_NON_REPLACE_COMPOSITE_MODE" /* AnimationFailureReasons.EFFECT_HAS_NON_REPLACE_COMPOSITE_MODE */,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
flag: 1 << 5,
|
|
39
|
+
failure: "TARGET_HAS_INVALID_COMPOSITING_STATE" /* AnimationFailureReasons.TARGET_HAS_INVALID_COMPOSITING_STATE */,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
flag: 1 << 6,
|
|
43
|
+
failure: "TARGET_HAS_INCOMPATIBLE_ANIMATIONS" /* AnimationFailureReasons.TARGET_HAS_INCOMPATIBLE_ANIMATIONS */,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
flag: 1 << 7,
|
|
47
|
+
failure: "TARGET_HAS_CSS_OFFSET" /* AnimationFailureReasons.TARGET_HAS_CSS_OFFSET */,
|
|
48
|
+
},
|
|
49
|
+
// The failure 1 << 8 is marked as obsolete in Blink
|
|
50
|
+
{
|
|
51
|
+
flag: 1 << 9,
|
|
52
|
+
failure: "ANIMATION_AFFECTS_NON_CSS_PROPERTIES" /* AnimationFailureReasons.ANIMATION_AFFECTS_NON_CSS_PROPERTIES */,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
flag: 1 << 10,
|
|
56
|
+
failure: "TRANSFORM_RELATED_PROPERTY_CANNOT_BE_ACCELERATED_ON_TARGET" /* AnimationFailureReasons.TRANSFORM_RELATED_PROPERTY_CANNOT_BE_ACCELERATED_ON_TARGET */,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
flag: 1 << 11,
|
|
60
|
+
failure: "TRANSFROM_BOX_SIZE_DEPENDENT" /* AnimationFailureReasons.TRANSFROM_BOX_SIZE_DEPENDENT */,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
flag: 1 << 12,
|
|
64
|
+
failure: "FILTER_RELATED_PROPERTY_MAY_MOVE_PIXELS" /* AnimationFailureReasons.FILTER_RELATED_PROPERTY_MAY_MOVE_PIXELS */,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
flag: 1 << 13,
|
|
68
|
+
failure: "UNSUPPORTED_CSS_PROPERTY" /* AnimationFailureReasons.UNSUPPORTED_CSS_PROPERTY */,
|
|
69
|
+
},
|
|
70
|
+
// The failure 1 << 14 is marked as obsolete in Blink
|
|
71
|
+
{
|
|
72
|
+
flag: 1 << 15,
|
|
73
|
+
failure: "MIXED_KEYFRAME_VALUE_TYPES" /* AnimationFailureReasons.MIXED_KEYFRAME_VALUE_TYPES */,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
flag: 1 << 16,
|
|
77
|
+
failure: "TIMELINE_SOURCE_HAS_INVALID_COMPOSITING_STATE" /* AnimationFailureReasons.TIMELINE_SOURCE_HAS_INVALID_COMPOSITING_STATE */,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
flag: 1 << 17,
|
|
81
|
+
failure: "ANIMATION_HAS_NO_VISIBLE_CHANGE" /* AnimationFailureReasons.ANIMATION_HAS_NO_VISIBLE_CHANGE */,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
flag: 1 << 18,
|
|
85
|
+
failure: "AFFECTS_IMPORTANT_PROPERTY" /* AnimationFailureReasons.AFFECTS_IMPORTANT_PROPERTY */,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
flag: 1 << 19,
|
|
89
|
+
failure: "SVG_TARGET_HAS_INDEPENDENT_TRANSFORM_PROPERTY" /* AnimationFailureReasons.SVG_TARGET_HAS_INDEPENDENT_TRANSFORM_PROPERTY */,
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
// 500ms window.
|
|
93
|
+
// Use this window to consider events and requests that may have caused a layout shift.
|
|
94
|
+
const ROOT_CAUSE_WINDOW = Helpers.Timing.secondsToMicroseconds(Types.Timing.Seconds(0.5));
|
|
95
|
+
/**
|
|
96
|
+
* Returns if an event happens within the root cause window, before the target event.
|
|
97
|
+
* ROOT_CAUSE_WINDOW v target event
|
|
98
|
+
* |------------------------|=======================
|
|
99
|
+
*/
|
|
100
|
+
function isInRootCauseWindow(event, targetEvent) {
|
|
101
|
+
const eventEnd = event.dur ? event.ts + event.dur : event.ts;
|
|
102
|
+
return eventEnd < targetEvent.ts && eventEnd >= targetEvent.ts - ROOT_CAUSE_WINDOW;
|
|
103
|
+
}
|
|
104
|
+
export function getNonCompositedFailure(animationEvent) {
|
|
105
|
+
const failures = [];
|
|
106
|
+
const beginEvent = animationEvent.args.data.beginEvent;
|
|
107
|
+
const instantEvents = animationEvent.args.data.instantEvents || [];
|
|
108
|
+
/**
|
|
109
|
+
* Animation events containing composite information are ASYNC_NESTABLE_INSTANT ('n').
|
|
110
|
+
* An animation may also contain multiple 'n' events, so we look through those with useful non-composited data.
|
|
111
|
+
*/
|
|
112
|
+
for (const event of instantEvents) {
|
|
113
|
+
const failureMask = event.args.data.compositeFailed;
|
|
114
|
+
const unsupportedProperties = event.args.data.unsupportedProperties;
|
|
115
|
+
if (!failureMask) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const failureReasons = ACTIONABLE_FAILURE_REASONS.filter(reason => failureMask & reason.flag).map(reason => reason.failure);
|
|
119
|
+
const failure = {
|
|
120
|
+
name: beginEvent.args.data.displayName,
|
|
121
|
+
failureReasons,
|
|
122
|
+
unsupportedProperties,
|
|
123
|
+
animation: animationEvent,
|
|
124
|
+
};
|
|
125
|
+
failures.push(failure);
|
|
126
|
+
}
|
|
127
|
+
return failures;
|
|
128
|
+
}
|
|
129
|
+
function getNonCompositedFailureRootCauses(animationEvents, prePaintEvents, shiftsByPrePaint, rootCausesByShift) {
|
|
130
|
+
const allAnimationFailures = [];
|
|
131
|
+
for (const animation of animationEvents) {
|
|
132
|
+
/**
|
|
133
|
+
* Animation events containing composite information are ASYNC_NESTABLE_INSTANT ('n').
|
|
134
|
+
* An animation may also contain multiple 'n' events, so we look through those with useful non-composited data.
|
|
135
|
+
*/
|
|
136
|
+
const failures = getNonCompositedFailure(animation);
|
|
137
|
+
if (!failures) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
allAnimationFailures.push(...failures);
|
|
141
|
+
const nextPrePaint = getNextEvent(prePaintEvents, animation);
|
|
142
|
+
// If no following prePaint, this is not a root cause.
|
|
143
|
+
if (!nextPrePaint) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
// If the animation event is outside the ROOT_CAUSE_WINDOW, it could not be a root cause.
|
|
147
|
+
if (!isInRootCauseWindow(animation, nextPrePaint)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const shifts = shiftsByPrePaint.get(nextPrePaint);
|
|
151
|
+
// if no layout shift(s), this is not a root cause.
|
|
152
|
+
if (!shifts) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
for (const shift of shifts) {
|
|
156
|
+
const rootCausesForShift = rootCausesByShift.get(shift);
|
|
157
|
+
if (!rootCausesForShift) {
|
|
158
|
+
throw new Error('Unaccounted shift');
|
|
159
|
+
}
|
|
160
|
+
rootCausesForShift.nonCompositedAnimations.push(...failures);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return allAnimationFailures;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Given an array of layout shift and PrePaint events, returns a mapping from
|
|
167
|
+
* PrePaint events to layout shifts dispatched within it.
|
|
168
|
+
*/
|
|
169
|
+
function getShiftsByPrePaintEvents(layoutShifts, prePaintEvents) {
|
|
170
|
+
// Maps from PrePaint events to LayoutShifts that occured in each one.
|
|
171
|
+
const shiftsByPrePaint = new Map();
|
|
172
|
+
// Associate all shifts to their corresponding PrePaint.
|
|
173
|
+
for (const prePaintEvent of prePaintEvents) {
|
|
174
|
+
const firstShiftIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(layoutShifts, shift => shift.ts >= prePaintEvent.ts);
|
|
175
|
+
if (firstShiftIndex === null) {
|
|
176
|
+
// No layout shifts registered after this PrePaint start. Continue.
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
for (let i = firstShiftIndex; i < layoutShifts.length; i++) {
|
|
180
|
+
const shift = layoutShifts[i];
|
|
181
|
+
if (shift.ts >= prePaintEvent.ts && shift.ts <= prePaintEvent.ts + prePaintEvent.dur) {
|
|
182
|
+
const shiftsInPrePaint = Platform.MapUtilities.getWithDefault(shiftsByPrePaint, prePaintEvent, () => []);
|
|
183
|
+
shiftsInPrePaint.push(shift);
|
|
184
|
+
}
|
|
185
|
+
if (shift.ts > prePaintEvent.ts + prePaintEvent.dur) {
|
|
186
|
+
// Reached all layoutShifts of this PrePaint. Break out to continue with the next prePaint event.
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return shiftsByPrePaint;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Given a source event list, this returns the first event of that list that directly follows the target event.
|
|
195
|
+
*/
|
|
196
|
+
function getNextEvent(sourceEvents, targetEvent) {
|
|
197
|
+
const index = Platform.ArrayUtilities.nearestIndexFromBeginning(sourceEvents, source => source.ts > targetEvent.ts + (targetEvent.dur || 0));
|
|
198
|
+
// No PrePaint event registered after this event
|
|
199
|
+
if (index === null) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
return sourceEvents[index];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* An Iframe is considered a root cause if the iframe event occurs before a prePaint event
|
|
206
|
+
* and within this prePaint event a layout shift(s) occurs.
|
|
207
|
+
*/
|
|
208
|
+
function getIframeRootCauses(iframeCreatedEvents, prePaintEvents, shiftsByPrePaint, rootCausesByShift, domLoadingEvents) {
|
|
209
|
+
for (const iframeEvent of iframeCreatedEvents) {
|
|
210
|
+
const nextPrePaint = getNextEvent(prePaintEvents, iframeEvent);
|
|
211
|
+
// If no following prePaint, this is not a root cause.
|
|
212
|
+
if (!nextPrePaint) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const shifts = shiftsByPrePaint.get(nextPrePaint);
|
|
216
|
+
// if no layout shift(s), this is not a root cause.
|
|
217
|
+
if (!shifts) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
for (const shift of shifts) {
|
|
221
|
+
const rootCausesForShift = rootCausesByShift.get(shift);
|
|
222
|
+
if (!rootCausesForShift) {
|
|
223
|
+
throw new Error('Unaccounted shift');
|
|
224
|
+
}
|
|
225
|
+
// Look for the first dom event that occurs within the bounds of the iframe event.
|
|
226
|
+
// This contains the frame id.
|
|
227
|
+
const domEvent = domLoadingEvents.find(e => {
|
|
228
|
+
const maxIframe = Types.Timing.MicroSeconds(iframeEvent.ts + (iframeEvent.dur ?? 0));
|
|
229
|
+
return e.ts >= iframeEvent.ts && e.ts <= maxIframe;
|
|
230
|
+
});
|
|
231
|
+
if (domEvent && domEvent.args.frame) {
|
|
232
|
+
rootCausesForShift.iframeIds.push(domEvent.args.frame);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return rootCausesByShift;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* An unsized image is considered a root cause if its PaintImage can be correlated to a
|
|
240
|
+
* layout shift. We can correlate PaintImages with unsized images by their matching nodeIds.
|
|
241
|
+
* X <- layout shift
|
|
242
|
+
* |----------------|
|
|
243
|
+
* ^ PrePaint event |-----|
|
|
244
|
+
* ^ PaintImage
|
|
245
|
+
*/
|
|
246
|
+
function getUnsizedImageRootCauses(unsizedImageEvents, paintImageEvents, shiftsByPrePaint, rootCausesByShift) {
|
|
247
|
+
shiftsByPrePaint.forEach((shifts, prePaint) => {
|
|
248
|
+
const paintImage = getNextEvent(paintImageEvents, prePaint);
|
|
249
|
+
// The unsized image corresponds to this PaintImage.
|
|
250
|
+
const matchingNode = unsizedImageEvents.find(unsizedImage => unsizedImage.args.data.nodeId === paintImage?.args.data.nodeId);
|
|
251
|
+
if (!matchingNode) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// The unsized image is a potential root cause of all the shifts of this prePaint.
|
|
255
|
+
for (const shift of shifts) {
|
|
256
|
+
const rootCausesForShift = rootCausesByShift.get(shift);
|
|
257
|
+
if (!rootCausesForShift) {
|
|
258
|
+
throw new Error('Unaccounted shift');
|
|
259
|
+
}
|
|
260
|
+
rootCausesForShift.unsizedImages.push(matchingNode.args.data.nodeId);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return rootCausesByShift;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* A font request is considered a root cause if the request occurs before a prePaint event
|
|
267
|
+
* and within this prePaint event a layout shift(s) occurs. Additionally, this font request should
|
|
268
|
+
* happen within the ROOT_CAUSE_WINDOW of the prePaint event.
|
|
269
|
+
*/
|
|
270
|
+
function getFontRootCauses(networkRequests, prePaintEvents, shiftsByPrePaint, rootCausesByShift) {
|
|
271
|
+
const fontRequests = networkRequests.filter(req => req.args.data.resourceType === 'Font' && req.args.data.mimeType.startsWith('font'));
|
|
272
|
+
for (const req of fontRequests) {
|
|
273
|
+
const nextPrePaint = getNextEvent(prePaintEvents, req);
|
|
274
|
+
if (!nextPrePaint) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
// If the req is outside the ROOT_CAUSE_WINDOW, it could not be a root cause.
|
|
278
|
+
if (!isInRootCauseWindow(req, nextPrePaint)) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
// Get the shifts that belong to this prepaint
|
|
282
|
+
const shifts = shiftsByPrePaint.get(nextPrePaint);
|
|
283
|
+
// if no layout shift(s) in this prePaint, the request is not a root cause.
|
|
284
|
+
if (!shifts) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
// Include the root cause to the shifts in this prePaint.
|
|
288
|
+
for (const shift of shifts) {
|
|
289
|
+
const rootCausesForShift = rootCausesByShift.get(shift);
|
|
290
|
+
if (!rootCausesForShift) {
|
|
291
|
+
throw new Error('Unaccounted shift');
|
|
292
|
+
}
|
|
293
|
+
rootCausesForShift.fontRequests.push(req);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return rootCausesByShift;
|
|
297
|
+
}
|
|
298
|
+
export function generateInsight(parsedTrace, context) {
|
|
299
|
+
const isWithinContext = (event) => Helpers.Timing.eventIsInBounds(event, context.bounds);
|
|
300
|
+
const compositeAnimationEvents = parsedTrace.Animations.animations.filter(isWithinContext);
|
|
301
|
+
const iframeEvents = parsedTrace.LayoutShifts.renderFrameImplCreateChildFrameEvents.filter(isWithinContext);
|
|
302
|
+
const networkRequests = parsedTrace.NetworkRequests.byTime.filter(isWithinContext);
|
|
303
|
+
const domLoadingEvents = parsedTrace.LayoutShifts.domLoadingEvents.filter(isWithinContext);
|
|
304
|
+
const unsizedImageEvents = parsedTrace.LayoutShifts.layoutImageUnsizedEvents.filter(isWithinContext);
|
|
305
|
+
const clusterKey = context.navigation ? context.navigationId : Types.Events.NO_NAVIGATION;
|
|
306
|
+
const clusters = parsedTrace.LayoutShifts.clustersByNavigationId.get(clusterKey) ?? [];
|
|
307
|
+
const clustersByScore = clusters.toSorted((a, b) => b.clusterCumulativeScore - a.clusterCumulativeScore);
|
|
308
|
+
const worstCluster = clustersByScore.at(0);
|
|
309
|
+
const layoutShifts = clusters.flatMap(cluster => cluster.events);
|
|
310
|
+
const prePaintEvents = parsedTrace.LayoutShifts.prePaintEvents.filter(isWithinContext);
|
|
311
|
+
const paintImageEvents = parsedTrace.LayoutShifts.paintImageEvents.filter(isWithinContext);
|
|
312
|
+
// Get root causes.
|
|
313
|
+
const rootCausesByShift = new Map();
|
|
314
|
+
const shiftsByPrePaint = getShiftsByPrePaintEvents(layoutShifts, prePaintEvents);
|
|
315
|
+
for (const shift of layoutShifts) {
|
|
316
|
+
rootCausesByShift.set(shift, { iframeIds: [], fontRequests: [], nonCompositedAnimations: [], unsizedImages: [] });
|
|
317
|
+
}
|
|
318
|
+
// Populate root causes for rootCausesByShift.
|
|
319
|
+
getIframeRootCauses(iframeEvents, prePaintEvents, shiftsByPrePaint, rootCausesByShift, domLoadingEvents);
|
|
320
|
+
getFontRootCauses(networkRequests, prePaintEvents, shiftsByPrePaint, rootCausesByShift);
|
|
321
|
+
getUnsizedImageRootCauses(unsizedImageEvents, paintImageEvents, shiftsByPrePaint, rootCausesByShift);
|
|
322
|
+
const animationFailures = getNonCompositedFailureRootCauses(compositeAnimationEvents, prePaintEvents, shiftsByPrePaint, rootCausesByShift);
|
|
323
|
+
const relatedEvents = [...layoutShifts];
|
|
324
|
+
if (worstCluster) {
|
|
325
|
+
relatedEvents.push(worstCluster);
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
relatedEvents,
|
|
329
|
+
animationFailures,
|
|
330
|
+
shifts: rootCausesByShift,
|
|
331
|
+
clusters,
|
|
332
|
+
worstCluster,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
//# sourceMappingURL=CLSCulprits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CLSCulprits.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/CLSCulprits.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAE/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAW3C,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC;AACnE,CAAC;AA4CD;;;;;GAKG;AACH,MAAM,0BAA0B,GAAG;IACjC;QACE,IAAI,EAAE,CAAC,IAAI,CAAC;QACZ,OAAO,iGAAyD;KACjE;IACD;QACE,IAAI,EAAE,CAAC,IAAI,CAAC;QACZ,OAAO,6FAAuD;KAC/D;IACD;QACE,IAAI,EAAE,CAAC,IAAI,CAAC;QACZ,OAAO,yFAAqD;KAC7D;IACD;QACE,IAAI,EAAE,CAAC,IAAI,CAAC;QACZ,OAAO,2GAA8D;KACtE;IACD;QACE,IAAI,EAAE,CAAC,IAAI,CAAC;QACZ,OAAO,6GAA+D;KACvE;IACD;QACE,IAAI,EAAE,CAAC,IAAI,CAAC;QACZ,OAAO,2GAA8D;KACtE;IACD;Q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C;IAED,8CAA8C;IAC9C,mBAAmB,CAAC,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;IACzG,iBAAiB,CAAC,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IACxF,yBAAyB,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IACrG,MAAM,iBAAiB,GACnB,iCAAiC,CAAC,wBAAwB,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IAErH,MAAM,aAAa,GAAyB,CAAC,GAAG,YAAY,CAAC,CAAC;IAC9D,IAAI,YAAY,EAAE,CAAC;QACjB,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;IAED,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,MAAM,EAAE,iBAAiB;QACzB,QAAQ;QACR,YAAY;KACb,CAAC;AACJ,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 Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {InsightModel, InsightSetContext, RequiredData} from './types.js';\n\nexport type CLSCulpritsInsightModel = InsightModel<{\n animationFailures: readonly NoncompositedAnimationFailure[],\n shifts: Map<Types.Events.SyntheticLayoutShift, LayoutShiftRootCausesData>,\n clusters: Types.Events.SyntheticLayoutShiftCluster[],\n worstCluster: Types.Events.SyntheticLayoutShiftCluster | undefined,\n}>;\n\nexport function deps(): ['Meta', 'Animations', 'LayoutShifts', 'NetworkRequests'] {\n return ['Meta', 'Animations', 'LayoutShifts', 'NetworkRequests'];\n}\n\nexport const enum AnimationFailureReasons {\n ACCELERATED_ANIMATIONS_DISABLED = 'ACCELERATED_ANIMATIONS_DISABLED',\n EFFECT_SUPPRESSED_BY_DEVTOOLS = 'EFFECT_SUPPRESSED_BY_DEVTOOLS',\n INVALID_ANIMATION_OR_EFFECT = 'INVALID_ANIMATION_OR_EFFECT',\n EFFECT_HAS_UNSUPPORTED_TIMING_PARAMS = 'EFFECT_HAS_UNSUPPORTED_TIMING_PARAMS',\n EFFECT_HAS_NON_REPLACE_COMPOSITE_MODE = 'EFFECT_HAS_NON_REPLACE_COMPOSITE_MODE',\n TARGET_HAS_INVALID_COMPOSITING_STATE = 'TARGET_HAS_INVALID_COMPOSITING_STATE',\n TARGET_HAS_INCOMPATIBLE_ANIMATIONS = 'TARGET_HAS_INCOMPATIBLE_ANIMATIONS',\n TARGET_HAS_CSS_OFFSET = 'TARGET_HAS_CSS_OFFSET',\n ANIMATION_AFFECTS_NON_CSS_PROPERTIES = 'ANIMATION_AFFECTS_NON_CSS_PROPERTIES',\n TRANSFORM_RELATED_PROPERTY_CANNOT_BE_ACCELERATED_ON_TARGET =\n 'TRANSFORM_RELATED_PROPERTY_CANNOT_BE_ACCELERATED_ON_TARGET',\n TRANSFROM_BOX_SIZE_DEPENDENT = 'TRANSFROM_BOX_SIZE_DEPENDENT',\n FILTER_RELATED_PROPERTY_MAY_MOVE_PIXELS = 'FILTER_RELATED_PROPERTY_MAY_MOVE_PIXELS',\n UNSUPPORTED_CSS_PROPERTY = 'UNSUPPORTED_CSS_PROPERTY',\n MIXED_KEYFRAME_VALUE_TYPES = 'MIXED_KEYFRAME_VALUE_TYPES',\n TIMELINE_SOURCE_HAS_INVALID_COMPOSITING_STATE = 'TIMELINE_SOURCE_HAS_INVALID_COMPOSITING_STATE',\n ANIMATION_HAS_NO_VISIBLE_CHANGE = 'ANIMATION_HAS_NO_VISIBLE_CHANGE',\n AFFECTS_IMPORTANT_PROPERTY = 'AFFECTS_IMPORTANT_PROPERTY',\n SVG_TARGET_HAS_INDEPENDENT_TRANSFORM_PROPERTY = 'SVG_TARGET_HAS_INDEPENDENT_TRANSFORM_PROPERTY',\n}\n\nexport interface NoncompositedAnimationFailure {\n /**\n * Animation name.\n */\n name?: string;\n /**\n * Failure reason based on mask number defined in\n * https://source.chromium.org/search?q=f:compositor_animations.h%20%22enum%20FailureReason%22.\n */\n failureReasons: AnimationFailureReasons[];\n /**\n * Unsupported properties.\n */\n unsupportedProperties?: Types.Events.Animation['args']['data']['unsupportedProperties'];\n /**\n * Animation event.\n */\n animation?: Types.Events.SyntheticAnimationPair;\n}\n\n/**\n * Each failure reason is represented by a bit flag. The bit shift operator '<<' is used to define\n * which bit corresponds to each failure reason.\n * https://source.chromium.org/search?q=f:compositor_animations.h%20%22enum%20FailureReason%22\n * @type {{flag: number, failure: AnimationFailureReasons}[]}\n */\nconst ACTIONABLE_FAILURE_REASONS = [\n {\n flag: 1 << 0,\n failure: AnimationFailureReasons.ACCELERATED_ANIMATIONS_DISABLED,\n },\n {\n flag: 1 << 1,\n failure: AnimationFailureReasons.EFFECT_SUPPRESSED_BY_DEVTOOLS,\n },\n {\n flag: 1 << 2,\n failure: AnimationFailureReasons.INVALID_ANIMATION_OR_EFFECT,\n },\n {\n flag: 1 << 3,\n failure: AnimationFailureReasons.EFFECT_HAS_UNSUPPORTED_TIMING_PARAMS,\n },\n {\n flag: 1 << 4,\n failure: AnimationFailureReasons.EFFECT_HAS_NON_REPLACE_COMPOSITE_MODE,\n },\n {\n flag: 1 << 5,\n failure: AnimationFailureReasons.TARGET_HAS_INVALID_COMPOSITING_STATE,\n },\n {\n flag: 1 << 6,\n failure: AnimationFailureReasons.TARGET_HAS_INCOMPATIBLE_ANIMATIONS,\n },\n {\n flag: 1 << 7,\n failure: AnimationFailureReasons.TARGET_HAS_CSS_OFFSET,\n },\n // The failure 1 << 8 is marked as obsolete in Blink\n {\n flag: 1 << 9,\n failure: AnimationFailureReasons.ANIMATION_AFFECTS_NON_CSS_PROPERTIES,\n },\n {\n flag: 1 << 10,\n failure: AnimationFailureReasons.TRANSFORM_RELATED_PROPERTY_CANNOT_BE_ACCELERATED_ON_TARGET,\n },\n {\n flag: 1 << 11,\n failure: AnimationFailureReasons.TRANSFROM_BOX_SIZE_DEPENDENT,\n },\n {\n flag: 1 << 12,\n failure: AnimationFailureReasons.FILTER_RELATED_PROPERTY_MAY_MOVE_PIXELS,\n },\n {\n flag: 1 << 13,\n failure: AnimationFailureReasons.UNSUPPORTED_CSS_PROPERTY,\n },\n // The failure 1 << 14 is marked as obsolete in Blink\n {\n flag: 1 << 15,\n failure: AnimationFailureReasons.MIXED_KEYFRAME_VALUE_TYPES,\n },\n {\n flag: 1 << 16,\n failure: AnimationFailureReasons.TIMELINE_SOURCE_HAS_INVALID_COMPOSITING_STATE,\n },\n {\n flag: 1 << 17,\n failure: AnimationFailureReasons.ANIMATION_HAS_NO_VISIBLE_CHANGE,\n },\n {\n flag: 1 << 18,\n failure: AnimationFailureReasons.AFFECTS_IMPORTANT_PROPERTY,\n },\n {\n flag: 1 << 19,\n failure: AnimationFailureReasons.SVG_TARGET_HAS_INDEPENDENT_TRANSFORM_PROPERTY,\n },\n];\n\n// 500ms window.\n// Use this window to consider events and requests that may have caused a layout shift.\nconst ROOT_CAUSE_WINDOW = Helpers.Timing.secondsToMicroseconds(Types.Timing.Seconds(0.5));\n\nexport interface LayoutShiftRootCausesData {\n iframeIds: string[];\n fontRequests: Types.Events.SyntheticNetworkRequest[];\n nonCompositedAnimations: NoncompositedAnimationFailure[];\n unsizedImages: Protocol.DOM.BackendNodeId[];\n}\n\n/**\n * Returns if an event happens within the root cause window, before the target event.\n * ROOT_CAUSE_WINDOW v target event\n * |------------------------|=======================\n */\nfunction isInRootCauseWindow(event: Types.Events.Event, targetEvent: Types.Events.Event): boolean {\n const eventEnd = event.dur ? event.ts + event.dur : event.ts;\n return eventEnd < targetEvent.ts && eventEnd >= targetEvent.ts - ROOT_CAUSE_WINDOW;\n}\n\nexport function getNonCompositedFailure(animationEvent: Types.Events.SyntheticAnimationPair):\n NoncompositedAnimationFailure[] {\n const failures: NoncompositedAnimationFailure[] = [];\n const beginEvent = animationEvent.args.data.beginEvent;\n const instantEvents = animationEvent.args.data.instantEvents || [];\n /**\n * Animation events containing composite information are ASYNC_NESTABLE_INSTANT ('n').\n * An animation may also contain multiple 'n' events, so we look through those with useful non-composited data.\n */\n for (const event of instantEvents) {\n const failureMask = event.args.data.compositeFailed;\n const unsupportedProperties = event.args.data.unsupportedProperties;\n if (!failureMask) {\n continue;\n }\n const failureReasons =\n ACTIONABLE_FAILURE_REASONS.filter(reason => failureMask & reason.flag).map(reason => reason.failure);\n const failure: NoncompositedAnimationFailure = {\n name: beginEvent.args.data.displayName,\n failureReasons,\n unsupportedProperties,\n animation: animationEvent,\n };\n failures.push(failure);\n }\n return failures;\n}\n\nfunction getNonCompositedFailureRootCauses(\n animationEvents: Types.Events.SyntheticAnimationPair[],\n prePaintEvents: Types.Events.PrePaint[],\n shiftsByPrePaint: Map<Types.Events.PrePaint, Types.Events.LayoutShift[]>,\n rootCausesByShift: Map<Types.Events.LayoutShift, LayoutShiftRootCausesData>,\n ): NoncompositedAnimationFailure[] {\n const allAnimationFailures: NoncompositedAnimationFailure[] = [];\n for (const animation of animationEvents) {\n /**\n * Animation events containing composite information are ASYNC_NESTABLE_INSTANT ('n').\n * An animation may also contain multiple 'n' events, so we look through those with useful non-composited data.\n */\n const failures = getNonCompositedFailure(animation);\n if (!failures) {\n continue;\n }\n allAnimationFailures.push(...failures);\n\n const nextPrePaint = getNextEvent(prePaintEvents, animation) as Types.Events.PrePaint | null;\n // If no following prePaint, this is not a root cause.\n if (!nextPrePaint) {\n continue;\n }\n\n // If the animation event is outside the ROOT_CAUSE_WINDOW, it could not be a root cause.\n if (!isInRootCauseWindow(animation, nextPrePaint)) {\n continue;\n }\n\n const shifts = shiftsByPrePaint.get(nextPrePaint);\n // if no layout shift(s), this is not a root cause.\n if (!shifts) {\n continue;\n }\n\n for (const shift of shifts) {\n const rootCausesForShift = rootCausesByShift.get(shift);\n if (!rootCausesForShift) {\n throw new Error('Unaccounted shift');\n }\n rootCausesForShift.nonCompositedAnimations.push(...failures);\n }\n }\n\n return allAnimationFailures;\n}\n\n/**\n * Given an array of layout shift and PrePaint events, returns a mapping from\n * PrePaint events to layout shifts dispatched within it.\n */\nfunction getShiftsByPrePaintEvents(\n layoutShifts: Types.Events.LayoutShift[],\n prePaintEvents: Types.Events.PrePaint[],\n ): Map<Types.Events.PrePaint, Types.Events.LayoutShift[]> {\n // Maps from PrePaint events to LayoutShifts that occured in each one.\n const shiftsByPrePaint = new Map<Types.Events.PrePaint, Types.Events.LayoutShift[]>();\n\n // Associate all shifts to their corresponding PrePaint.\n for (const prePaintEvent of prePaintEvents) {\n const firstShiftIndex =\n Platform.ArrayUtilities.nearestIndexFromBeginning(layoutShifts, shift => shift.ts >= prePaintEvent.ts);\n if (firstShiftIndex === null) {\n // No layout shifts registered after this PrePaint start. Continue.\n continue;\n }\n for (let i = firstShiftIndex; i < layoutShifts.length; i++) {\n const shift = layoutShifts[i];\n if (shift.ts >= prePaintEvent.ts && shift.ts <= prePaintEvent.ts + prePaintEvent.dur) {\n const shiftsInPrePaint = Platform.MapUtilities.getWithDefault(shiftsByPrePaint, prePaintEvent, () => []);\n shiftsInPrePaint.push(shift);\n }\n if (shift.ts > prePaintEvent.ts + prePaintEvent.dur) {\n // Reached all layoutShifts of this PrePaint. Break out to continue with the next prePaint event.\n break;\n }\n }\n }\n return shiftsByPrePaint;\n}\n\n/**\n * Given a source event list, this returns the first event of that list that directly follows the target event.\n */\nfunction getNextEvent(sourceEvents: Types.Events.Event[], targetEvent: Types.Events.Event): Types.Events.Event|\n undefined {\n const index = Platform.ArrayUtilities.nearestIndexFromBeginning(\n sourceEvents, source => source.ts > targetEvent.ts + (targetEvent.dur || 0));\n // No PrePaint event registered after this event\n if (index === null) {\n return undefined;\n }\n\n return sourceEvents[index];\n}\n\n/**\n * An Iframe is considered a root cause if the iframe event occurs before a prePaint event\n * and within this prePaint event a layout shift(s) occurs.\n */\nfunction getIframeRootCauses(\n iframeCreatedEvents: readonly Types.Events.RenderFrameImplCreateChildFrame[],\n prePaintEvents: Types.Events.PrePaint[], shiftsByPrePaint: Map<Types.Events.PrePaint, Types.Events.LayoutShift[]>,\n rootCausesByShift: Map<Types.Events.LayoutShift, LayoutShiftRootCausesData>,\n domLoadingEvents: readonly Types.Events.DomLoading[]): Map<Types.Events.LayoutShift, LayoutShiftRootCausesData> {\n for (const iframeEvent of iframeCreatedEvents) {\n const nextPrePaint = getNextEvent(prePaintEvents, iframeEvent) as Types.Events.PrePaint | null;\n // If no following prePaint, this is not a root cause.\n if (!nextPrePaint) {\n continue;\n }\n const shifts = shiftsByPrePaint.get(nextPrePaint);\n // if no layout shift(s), this is not a root cause.\n if (!shifts) {\n continue;\n }\n for (const shift of shifts) {\n const rootCausesForShift = rootCausesByShift.get(shift);\n if (!rootCausesForShift) {\n throw new Error('Unaccounted shift');\n }\n\n // Look for the first dom event that occurs within the bounds of the iframe event.\n // This contains the frame id.\n const domEvent = domLoadingEvents.find(e => {\n const maxIframe = Types.Timing.MicroSeconds(iframeEvent.ts + (iframeEvent.dur ?? 0));\n return e.ts >= iframeEvent.ts && e.ts <= maxIframe;\n });\n if (domEvent && domEvent.args.frame) {\n rootCausesForShift.iframeIds.push(domEvent.args.frame);\n }\n }\n }\n return rootCausesByShift;\n}\n\n/**\n * An unsized image is considered a root cause if its PaintImage can be correlated to a\n * layout shift. We can correlate PaintImages with unsized images by their matching nodeIds.\n * X <- layout shift\n * |----------------|\n * ^ PrePaint event |-----|\n * ^ PaintImage\n */\nfunction getUnsizedImageRootCauses(\n unsizedImageEvents: readonly Types.Events.LayoutImageUnsized[], paintImageEvents: Types.Events.PaintImage[],\n shiftsByPrePaint: Map<Types.Events.PrePaint, Types.Events.LayoutShift[]>,\n rootCausesByShift: Map<Types.Events.LayoutShift, LayoutShiftRootCausesData>):\n Map<Types.Events.LayoutShift, LayoutShiftRootCausesData> {\n shiftsByPrePaint.forEach((shifts, prePaint) => {\n const paintImage = getNextEvent(paintImageEvents, prePaint) as Types.Events.PaintImage | null;\n // The unsized image corresponds to this PaintImage.\n const matchingNode =\n unsizedImageEvents.find(unsizedImage => unsizedImage.args.data.nodeId === paintImage?.args.data.nodeId);\n if (!matchingNode) {\n return;\n }\n // The unsized image is a potential root cause of all the shifts of this prePaint.\n for (const shift of shifts) {\n const rootCausesForShift = rootCausesByShift.get(shift);\n if (!rootCausesForShift) {\n throw new Error('Unaccounted shift');\n }\n rootCausesForShift.unsizedImages.push(matchingNode.args.data.nodeId);\n }\n });\n return rootCausesByShift;\n}\n\n/**\n * A font request is considered a root cause if the request occurs before a prePaint event\n * and within this prePaint event a layout shift(s) occurs. Additionally, this font request should\n * happen within the ROOT_CAUSE_WINDOW of the prePaint event.\n */\nfunction getFontRootCauses(\n networkRequests: Types.Events.SyntheticNetworkRequest[], prePaintEvents: Types.Events.PrePaint[],\n shiftsByPrePaint: Map<Types.Events.PrePaint, Types.Events.LayoutShift[]>,\n rootCausesByShift: Map<Types.Events.LayoutShift, LayoutShiftRootCausesData>):\n Map<Types.Events.LayoutShift, LayoutShiftRootCausesData> {\n const fontRequests =\n networkRequests.filter(req => req.args.data.resourceType === 'Font' && req.args.data.mimeType.startsWith('font'));\n\n for (const req of fontRequests) {\n const nextPrePaint = getNextEvent(prePaintEvents, req) as Types.Events.PrePaint | null;\n if (!nextPrePaint) {\n continue;\n }\n\n // If the req is outside the ROOT_CAUSE_WINDOW, it could not be a root cause.\n if (!isInRootCauseWindow(req, nextPrePaint)) {\n continue;\n }\n\n // Get the shifts that belong to this prepaint\n const shifts = shiftsByPrePaint.get(nextPrePaint);\n\n // if no layout shift(s) in this prePaint, the request is not a root cause.\n if (!shifts) {\n continue;\n }\n // Include the root cause to the shifts in this prePaint.\n for (const shift of shifts) {\n const rootCausesForShift = rootCausesByShift.get(shift);\n if (!rootCausesForShift) {\n throw new Error('Unaccounted shift');\n }\n rootCausesForShift.fontRequests.push(req);\n }\n }\n return rootCausesByShift;\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): CLSCulpritsInsightModel {\n const isWithinContext = (event: Types.Events.Event): boolean => Helpers.Timing.eventIsInBounds(event, context.bounds);\n\n const compositeAnimationEvents = parsedTrace.Animations.animations.filter(isWithinContext);\n const iframeEvents = parsedTrace.LayoutShifts.renderFrameImplCreateChildFrameEvents.filter(isWithinContext);\n const networkRequests = parsedTrace.NetworkRequests.byTime.filter(isWithinContext);\n const domLoadingEvents = parsedTrace.LayoutShifts.domLoadingEvents.filter(isWithinContext);\n const unsizedImageEvents = parsedTrace.LayoutShifts.layoutImageUnsizedEvents.filter(isWithinContext);\n\n const clusterKey = context.navigation ? context.navigationId : Types.Events.NO_NAVIGATION;\n const clusters = parsedTrace.LayoutShifts.clustersByNavigationId.get(clusterKey) ?? [];\n const clustersByScore = clusters.toSorted((a, b) => b.clusterCumulativeScore - a.clusterCumulativeScore);\n const worstCluster = clustersByScore.at(0);\n const layoutShifts = clusters.flatMap(cluster => cluster.events);\n const prePaintEvents = parsedTrace.LayoutShifts.prePaintEvents.filter(isWithinContext);\n const paintImageEvents = parsedTrace.LayoutShifts.paintImageEvents.filter(isWithinContext);\n\n // Get root causes.\n const rootCausesByShift = new Map<Types.Events.SyntheticLayoutShift, LayoutShiftRootCausesData>();\n const shiftsByPrePaint = getShiftsByPrePaintEvents(layoutShifts, prePaintEvents);\n\n for (const shift of layoutShifts) {\n rootCausesByShift.set(shift, {iframeIds: [], fontRequests: [], nonCompositedAnimations: [], unsizedImages: []});\n }\n\n // Populate root causes for rootCausesByShift.\n getIframeRootCauses(iframeEvents, prePaintEvents, shiftsByPrePaint, rootCausesByShift, domLoadingEvents);\n getFontRootCauses(networkRequests, prePaintEvents, shiftsByPrePaint, rootCausesByShift);\n getUnsizedImageRootCauses(unsizedImageEvents, paintImageEvents, shiftsByPrePaint, rootCausesByShift);\n const animationFailures =\n getNonCompositedFailureRootCauses(compositeAnimationEvents, prePaintEvents, shiftsByPrePaint, rootCausesByShift);\n\n const relatedEvents: Types.Events.Event[] = [...layoutShifts];\n if (worstCluster) {\n relatedEvents.push(worstCluster);\n }\n\n return {\n relatedEvents,\n animationFailures,\n shifts: rootCausesByShift,\n clusters,\n worstCluster,\n };\n}\n"]}
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
3
|
-
import type { InsightResults, InsightSetContextWithNavigation, TraceInsightSets } from './types.js';
|
|
4
|
-
export declare function getInsight<InsightName extends keyof InsightResults>(insightName: InsightName, insights: TraceInsightSets | null, key: string | null): InsightResults[InsightName] | null;
|
|
5
|
-
/**
|
|
6
|
-
* Finds a network request given a navigation context and URL.
|
|
7
|
-
* Considers redirects.
|
|
8
|
-
*/
|
|
9
|
-
export declare function findRequest(parsedTrace: Pick<Handlers.Types.ParsedTrace, 'Meta' | 'NetworkRequests'>, context: InsightSetContextWithNavigation, url: string): Types.Events.SyntheticNetworkRequest | null;
|
|
10
|
-
export declare function findLCPRequest(parsedTrace: Pick<Handlers.Types.ParsedTrace, 'Meta' | 'NetworkRequests' | 'LargestImagePaint'>, context: InsightSetContextWithNavigation, lcpEvent: Types.Events.LargestContentfulPaintCandidate): Types.Events.SyntheticNetworkRequest | null;
|
|
1
|
+
import type { InsightModels, TraceInsightSets } from './types.js';
|
|
2
|
+
export declare function getInsight<InsightName extends keyof InsightModels>(insightName: InsightName, insights: TraceInsightSets | null, key: string | null): InsightModels[InsightName] | null;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
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
|
-
import * as Helpers from '../helpers/helpers.js';
|
|
5
4
|
export function getInsight(insightName, insights, key) {
|
|
6
5
|
if (!insights || !key) {
|
|
7
6
|
return null;
|
|
@@ -10,45 +9,11 @@ export function getInsight(insightName, insights, key) {
|
|
|
10
9
|
if (!insightSets) {
|
|
11
10
|
return null;
|
|
12
11
|
}
|
|
13
|
-
const insight = insightSets.
|
|
12
|
+
const insight = insightSets.model[insightName];
|
|
14
13
|
if (insight instanceof Error) {
|
|
15
14
|
return null;
|
|
16
15
|
}
|
|
17
16
|
// For some reason typescript won't narrow the type by removing Error, so do it manually.
|
|
18
17
|
return insight;
|
|
19
18
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Finds a network request given a navigation context and URL.
|
|
22
|
-
* Considers redirects.
|
|
23
|
-
*/
|
|
24
|
-
export function findRequest(parsedTrace, context, url) {
|
|
25
|
-
const request = parsedTrace.NetworkRequests.byTime.find(req => {
|
|
26
|
-
const urlMatch = req.args.data.url === url || req.args.data.redirects.some(r => r.url === url);
|
|
27
|
-
if (!urlMatch) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
const nav = Helpers.Trace.getNavigationForTraceEvent(req, context.frameId, parsedTrace.Meta.navigationsByFrameId);
|
|
31
|
-
return nav === context.navigation;
|
|
32
|
-
});
|
|
33
|
-
return request ?? null;
|
|
34
|
-
}
|
|
35
|
-
export function findLCPRequest(parsedTrace, context, lcpEvent) {
|
|
36
|
-
const lcpNodeId = lcpEvent.args.data?.nodeId;
|
|
37
|
-
if (!lcpNodeId) {
|
|
38
|
-
throw new Error('no lcp node id');
|
|
39
|
-
}
|
|
40
|
-
const imagePaint = parsedTrace.LargestImagePaint.get(lcpNodeId);
|
|
41
|
-
if (!imagePaint) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
const lcpUrl = imagePaint.args.data?.imageUrl;
|
|
45
|
-
if (!lcpUrl) {
|
|
46
|
-
throw new Error('no lcp url');
|
|
47
|
-
}
|
|
48
|
-
const lcpRequest = findRequest(parsedTrace, context, lcpUrl);
|
|
49
|
-
if (!lcpRequest) {
|
|
50
|
-
throw new Error('no lcp request found');
|
|
51
|
-
}
|
|
52
|
-
return lcpRequest;
|
|
53
|
-
}
|
|
54
19
|
//# sourceMappingURL=Common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Common.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Common.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAI7B,MAAM,UAAU,UAAU,CACtB,WAAwB,EAAE,QAA+B,EAAE,GAAgB;IAC7E,IAAI,CAAC,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,OAAO,YAAY,KAAK,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yFAAyF;IACzF,OAAO,OAAqC,CAAC;AAC/C,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 type {InsightModels, TraceInsightSets} from './types.js';\n\nexport function getInsight<InsightName extends keyof InsightModels>(\n insightName: InsightName, insights: TraceInsightSets|null, key: string|null): InsightModels[InsightName]|null {\n if (!insights || !key) {\n return null;\n }\n\n const insightSets = insights.get(key);\n if (!insightSets) {\n return null;\n }\n\n const insight = insightSets.model[insightName];\n if (insight instanceof Error) {\n return null;\n }\n\n // For some reason typescript won't narrow the type by removing Error, so do it manually.\n return insight as InsightModels[InsightName];\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Types from '../types/types.js';
|
|
2
|
-
import type {
|
|
3
|
-
export type
|
|
2
|
+
import type { InsightModel, InsightSetContext, RequiredData } from './types.js';
|
|
3
|
+
export type DocumentLatencyInsightModel = InsightModel<{
|
|
4
4
|
data?: {
|
|
5
5
|
serverResponseTime: Types.Timing.MilliSeconds;
|
|
6
6
|
serverResponseTooSlow: boolean;
|
|
@@ -10,4 +10,4 @@ export type DocumentLatencyInsightResult = InsightResult<{
|
|
|
10
10
|
};
|
|
11
11
|
}>;
|
|
12
12
|
export declare function deps(): ['Meta', 'NetworkRequests'];
|
|
13
|
-
export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext):
|
|
13
|
+
export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DocumentLatencyInsightModel;
|
|
@@ -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,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,wGAAwG;AACxG,4GAA4G;AAC5G,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,qCAAqC;AACrC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAYvC,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,qBAAqB,CAAC,OAA6C;IAC1E,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,0BAA0B,CAAC,OAAO,CAAC,IAAI,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AAM,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,gBAA6C;QAClD,GAAG,EAAE,gBAA6C;KACnD,CAAC;IAEF,OAAO;QACL,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;AACJ,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {
|
|
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,O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EF,OAAO;QACL,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;AACJ,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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {InsightModel, InsightSetContext, RequiredData} from './types.js';\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.microSecondsToMilliseconds(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\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DocumentLatencyInsightModel {\n if (!context.navigation) {\n return {};\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 {\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,11 +1,11 @@
|
|
|
1
1
|
import * as Types from '../types/types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { InsightModel, InsightSetContext, RequiredData } from './types.js';
|
|
3
3
|
export declare function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'];
|
|
4
|
-
export type
|
|
4
|
+
export type FontDisplayInsightModel = InsightModel<{
|
|
5
5
|
fonts: Array<{
|
|
6
6
|
request: Types.Events.SyntheticNetworkRequest;
|
|
7
7
|
display: string;
|
|
8
8
|
wastedTime: Types.Timing.MilliSeconds;
|
|
9
9
|
}>;
|
|
10
10
|
}>;
|
|
11
|
-
export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext):
|
|
11
|
+
export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel;
|
|
@@ -1 +1 @@
|
|
|
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,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC;AAUD,MAAM,UAAU,eAAe,
|
|
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,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC;AAUD,MAAM,UAAU,eAAe,CAC3B,WAAsC,EAAE,OAA0B;IACpE,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,YAAY,CAAC,yBAAyB,EAAE,CAAC;QACvE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3D,SAAS;QACX,CAAC;QAED,MAAM,SAAS,GAAG,GAAG,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,OAAO,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACh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ACJ,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 Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {InsightModel, InsightSetContext, RequiredData} from './types.js';\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\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.microSecondsToMilliseconds(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 {\n relatedEvents: fonts.map(f => f.request),\n fonts,\n metricSavings: {FCP: savings},\n };\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { SyntheticInteractionPair } from '../types/TraceEvents.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { InsightModel, InsightSetContext, RequiredData } from './types.js';
|
|
3
3
|
export declare function deps(): ['UserInteractions'];
|
|
4
|
-
export type
|
|
4
|
+
export type INPInsightModel = InsightModel<{
|
|
5
5
|
longestInteractionEvent?: SyntheticInteractionPair;
|
|
6
6
|
highPercentileInteractionEvent?: SyntheticInteractionPair;
|
|
7
7
|
}>;
|
|
8
|
-
export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext):
|
|
8
|
+
export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): INPInsightModel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InteractionToNextPaint.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/InteractionToNextPaint.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAKjD,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC9B,CAAC;AAOD,MAAM,UAAU,eAAe,CAAC,WAAsC,EAAE,OAA0B;IAChG,MAAM,iBAAiB,GAAG,WAAW,CAAC,gBAAgB,CAAC,8BAA8B,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QACnG,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC;QAC9B,qDAAqD;QACrD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC3E,KAAK,MAAM,KAAK,IAAI,iBAAiB,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC;QAChC,MAAM,OAAO,GAAG,sBAAsB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;YACxC,sBAAsB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IACD,MAAM,2BAA2B,GAAG,CAAC,GAAG,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC;IACzE,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAE1D,6EAA6E;IAC7E,+EAA+E;IAC/E,6EAA6E;IAC7E,iMAAiM;IACjM,MAAM,mBAAmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,2BAA2B,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;IAE7F,OAAO;QACL,aAAa,EAAE,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;QAC/C,uBAAuB,EAAE,2BAA2B,CAAC,CAAC,CAAC;QACvD,8BAA8B,EAAE,2BAA2B,CAAC,mBAAmB,CAAC;KACjF,CAAC;AACJ,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 Helpers from '../helpers/helpers.js';\nimport type {SyntheticInteractionPair} from '../types/TraceEvents.js';\n\nimport type {
|
|
1
|
+
{"version":3,"file":"InteractionToNextPaint.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/InteractionToNextPaint.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAA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G,EAAE,CAAC,CAAC,CAAC;IAE7F,OAAO;QACL,aAAa,EAAE,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;QAC/C,uBAAuB,EAAE,2BAA2B,CAAC,CAAC,CAAC;QACvD,8BAA8B,EAAE,2BAA2B,CAAC,mBAAmB,CAAC;KACjF,CAAC;AACJ,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 Helpers from '../helpers/helpers.js';\nimport type {SyntheticInteractionPair} from '../types/TraceEvents.js';\n\nimport type {InsightModel, InsightSetContext, RequiredData} from './types.js';\n\nexport function deps(): ['UserInteractions'] {\n return ['UserInteractions'];\n}\n\nexport type INPInsightModel = InsightModel<{\n longestInteractionEvent?: SyntheticInteractionPair,\n highPercentileInteractionEvent?: SyntheticInteractionPair,\n}>;\n\nexport function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): INPInsightModel {\n const interactionEvents = parsedTrace.UserInteractions.interactionEventsWithNoNesting.filter(event => {\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n if (!interactionEvents.length) {\n // A valid result, when there is no user interaction.\n return {};\n }\n\n const longestByInteractionId = new Map<number, SyntheticInteractionPair>();\n for (const event of interactionEvents) {\n const key = event.interactionId;\n const longest = longestByInteractionId.get(key);\n if (!longest || event.dur > longest.dur) {\n longestByInteractionId.set(key, event);\n }\n }\n const normalizedInteractionEvents = [...longestByInteractionId.values()];\n normalizedInteractionEvents.sort((a, b) => b.dur - a.dur);\n\n // INP is the \"nearest-rank\"/inverted_cdf 98th percentile, except Chrome only\n // keeps the 10 worst events around, so it can never be more than the 10th from\n // last array element. To keep things simpler, sort desc and pick from front.\n // See https://source.chromium.org/chromium/chromium/src/+/main:components/page_load_metrics/browser/responsiveness_metrics_normalization.cc;l=45-59;drc=cb0f9c8b559d9c7c3cb4ca94fc1118cc015d38ad\n const highPercentileIndex = Math.min(9, Math.floor(normalizedInteractionEvents.length / 50));\n\n return {\n relatedEvents: [normalizedInteractionEvents[0]],\n longestInteractionEvent: normalizedInteractionEvents[0],\n highPercentileInteractionEvent: normalizedInteractionEvents[highPercentileIndex],\n };\n}\n"]}
|