@paulirish/trace_engine 0.0.68 → 0.0.69
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/README.md +17 -1
- package/generated/protocol.d.ts +55 -13
- package/generated/protocol.js +1 -4
- package/locales/af.json +3 -6
- package/locales/am.json +3 -6
- package/locales/ar.json +3 -6
- package/locales/as.json +3 -6
- package/locales/az.json +3 -6
- package/locales/be.json +3 -6
- package/locales/bg.json +3 -6
- package/locales/bn.json +3 -6
- package/locales/bs.json +3 -6
- package/locales/ca.json +75 -78
- package/locales/cs.json +3 -6
- package/locales/cy.json +3 -6
- package/locales/da.json +3 -6
- package/locales/de.json +3 -6
- package/locales/el.json +3 -6
- package/locales/en-GB.json +3 -6
- package/locales/es-419.json +3 -6
- package/locales/es.json +3 -6
- package/locales/et.json +3 -6
- package/locales/eu.json +3 -6
- package/locales/fa.json +3 -6
- package/locales/fi.json +3 -6
- package/locales/fil.json +3 -6
- package/locales/fr-CA.json +37 -40
- package/locales/fr.json +3 -6
- package/locales/gl.json +18 -21
- package/locales/gu.json +3 -6
- package/locales/he.json +3 -6
- package/locales/hi.json +11 -14
- package/locales/hr.json +3 -6
- package/locales/hu.json +3 -6
- package/locales/hy.json +3 -6
- package/locales/id.json +3 -6
- package/locales/is.json +3 -6
- package/locales/it.json +3 -6
- package/locales/ja.json +3 -6
- package/locales/ka.json +3 -6
- package/locales/kk.json +3 -6
- package/locales/km.json +3 -6
- package/locales/kn.json +3 -6
- package/locales/ko.json +3 -6
- package/locales/ky.json +3 -6
- package/locales/lo.json +3 -6
- package/locales/lt.json +3 -6
- package/locales/lv.json +5 -8
- package/locales/mk.json +75 -78
- package/locales/ml.json +3 -6
- package/locales/mn.json +3 -6
- package/locales/mr.json +3 -6
- package/locales/ms.json +3 -6
- package/locales/my.json +3 -6
- package/locales/ne.json +29 -32
- package/locales/nl.json +3 -6
- package/locales/no.json +3 -6
- package/locales/or.json +3 -6
- package/locales/pa.json +3 -6
- package/locales/pl.json +3 -6
- package/locales/pt-PT.json +3 -6
- package/locales/pt.json +32 -35
- package/locales/ro.json +3 -6
- package/locales/ru.json +3 -6
- package/locales/si.json +3 -6
- package/locales/sk.json +3 -6
- package/locales/sl.json +3 -6
- package/locales/sq.json +3 -6
- package/locales/sr-Latn.json +3 -6
- package/locales/sr.json +3 -6
- package/locales/sv.json +3 -6
- package/locales/sw.json +4 -7
- package/locales/ta.json +3 -6
- package/locales/te.json +3 -6
- package/locales/th.json +3 -6
- package/locales/tr.json +3 -6
- package/locales/uk.json +3 -6
- package/locales/ur.json +3 -6
- package/locales/uz.json +3 -6
- package/locales/vi.json +3 -6
- package/locales/zh-HK.json +3 -6
- package/locales/zh-TW.json +3 -6
- package/locales/zh.json +3 -6
- package/locales/zu.json +3 -6
- package/models/trace/EventsSerializer.js +0 -7
- package/models/trace/EventsSerializer.js.map +1 -1
- package/models/trace/Processor.js +15 -7
- package/models/trace/Processor.js.map +1 -1
- package/models/trace/extras/ThirdParties.js +4 -6
- package/models/trace/extras/ThirdParties.js.map +1 -1
- package/models/trace/extras/TraceFilter.d.ts +1 -0
- package/models/trace/extras/TraceFilter.js +18 -8
- package/models/trace/extras/TraceFilter.js.map +1 -1
- package/models/trace/extras/TraceTree.d.ts +13 -16
- package/models/trace/extras/TraceTree.js +126 -101
- package/models/trace/extras/TraceTree.js.map +1 -1
- package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +0 -5
- package/models/trace/handlers/ExtensionTraceDataHandler.js +0 -5
- package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
- package/models/trace/handlers/FlowsHandler.js +9 -0
- package/models/trace/handlers/FlowsHandler.js.map +1 -1
- package/models/trace/handlers/MetaHandler.js +3 -0
- package/models/trace/handlers/MetaHandler.js.map +1 -1
- package/models/trace/handlers/RendererHandler.js +7 -6
- package/models/trace/handlers/RendererHandler.js.map +1 -1
- package/models/trace/handlers/SamplesHandler.d.ts +0 -1
- package/models/trace/handlers/SamplesHandler.js +4 -2
- package/models/trace/handlers/SamplesHandler.js.map +1 -1
- package/models/trace/handlers/ScriptsHandler.js +24 -22
- package/models/trace/handlers/ScriptsHandler.js.map +1 -1
- package/models/trace/handlers/types.d.ts +15 -0
- package/models/trace/handlers/types.js.map +1 -1
- package/models/trace/helpers/Extensions.js +1 -3
- package/models/trace/helpers/Extensions.js.map +1 -1
- package/models/trace/helpers/SamplesIntegrator.d.ts +17 -14
- package/models/trace/helpers/SamplesIntegrator.js +147 -84
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
- package/models/trace/helpers/Trace.js +19 -14
- package/models/trace/helpers/Trace.js.map +1 -1
- package/models/trace/helpers/TreeHelpers.d.ts +13 -1
- package/models/trace/helpers/TreeHelpers.js +35 -8
- package/models/trace/helpers/TreeHelpers.js.map +1 -1
- package/models/trace/insights/DuplicatedJavaScript.js +1 -2
- package/models/trace/insights/DuplicatedJavaScript.js.map +1 -1
- package/models/trace/insights/SlowCSSSelector.js +2 -2
- package/models/trace/insights/SlowCSSSelector.js.map +1 -1
- package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +1 -0
- package/models/trace/lantern/metrics/LargestContentfulPaint.js +17 -4
- package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -1
- package/models/trace/lantern/simulation/Simulator.d.ts +4 -0
- package/models/trace/lantern/simulation/Simulator.js +4 -1
- package/models/trace/lantern/simulation/Simulator.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +21 -19
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/package.json +1 -1
- package/test/test-trace-engine.mjs +20 -17
|
@@ -9,12 +9,38 @@ export const makeEmptyTraceEntryTree = () => ({
|
|
|
9
9
|
roots: new Set(),
|
|
10
10
|
maxDepth: 0,
|
|
11
11
|
});
|
|
12
|
+
// Most nodes in a trace tree are leaves, and most parent nodes have a single
|
|
13
|
+
// child. Sharing an empty array for leaves and creating a 1-element literal on
|
|
14
|
+
// the first append avoids allocating an empty JSArray per leaf and a 17-slot
|
|
15
|
+
// backing store for single-child parents. This array is kept unfrozen so V8
|
|
16
|
+
// uses the same PACKED_ELEMENTS map across leaf and parent children arrays.
|
|
17
|
+
const EMPTY_CHILDREN = [];
|
|
18
|
+
/**
|
|
19
|
+
* Appends a child to a `TraceEntryNode`.
|
|
20
|
+
*
|
|
21
|
+
* Call this helper instead of `parent.children.push(child)`. Nodes created by
|
|
22
|
+
* `makeEmptyTraceEntryNode` share a single empty array for their children to
|
|
23
|
+
* save memory; mutating `parent.children` directly on a leaf node corrupts all
|
|
24
|
+
* leaf nodes.
|
|
25
|
+
*/
|
|
26
|
+
export function appendChild(parent, child) {
|
|
27
|
+
if (parent.children === EMPTY_CHILDREN) {
|
|
28
|
+
parent.children = [child];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
parent.children.push(child);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
12
34
|
export const makeEmptyTraceEntryNode = (entry, id) => ({
|
|
13
35
|
entry,
|
|
14
36
|
id,
|
|
15
37
|
parent: null,
|
|
16
|
-
children:
|
|
38
|
+
children: EMPTY_CHILDREN,
|
|
17
39
|
depth: 0,
|
|
40
|
+
// selfTime is set on every node after creation. Declaring it here keeps it
|
|
41
|
+
// inside the object; adding it later makes V8 allocate a separate property
|
|
42
|
+
// store for every node.
|
|
43
|
+
selfTime: undefined,
|
|
18
44
|
});
|
|
19
45
|
/**
|
|
20
46
|
* Builds a hierarchy of the entries (trace events and profile calls) in
|
|
@@ -30,13 +56,16 @@ export const makeEmptyTraceEntryNode = (entry, id) => ({
|
|
|
30
56
|
* The nodes are also assumed to be created empty, with no known parent
|
|
31
57
|
* or children.
|
|
32
58
|
*
|
|
59
|
+
* If `targetEntryToNode` is provided, it is populated in-place with each
|
|
60
|
+
* event's `TraceEntryNode` and returned as `entryToNode`.
|
|
61
|
+
*
|
|
33
62
|
* Complexity: O(n), where n = number of events
|
|
34
63
|
*/
|
|
35
|
-
export function treify(entries, options) {
|
|
64
|
+
export function treify(entries, options, targetEntryToNode) {
|
|
36
65
|
// As we construct the tree, store a map of each entry to its node. This
|
|
37
66
|
// means if you are iterating over a list of RendererEntry events you can
|
|
38
67
|
// easily look up that node in the tree.
|
|
39
|
-
const entryToNode = new Map();
|
|
68
|
+
const entryToNode = targetEntryToNode ?? new Map();
|
|
40
69
|
const stack = [];
|
|
41
70
|
// Reset the node id counter for every new renderer.
|
|
42
71
|
nodeIdCount = -1;
|
|
@@ -49,11 +78,10 @@ export function treify(entries, options) {
|
|
|
49
78
|
continue;
|
|
50
79
|
}
|
|
51
80
|
const duration = event.dur || 0;
|
|
52
|
-
const nodeId = makeTraceEntryNodeId();
|
|
53
|
-
const node = makeEmptyTraceEntryNode(event, nodeId);
|
|
54
81
|
// If the parent stack is empty, then the current event is a root. Create a
|
|
55
82
|
// node for it, mark it as a root, then proceed with the next event.
|
|
56
83
|
if (stack.length === 0) {
|
|
84
|
+
const node = makeEmptyTraceEntryNode(event, makeTraceEntryNodeId());
|
|
57
85
|
tree.roots.add(node);
|
|
58
86
|
node.selfTime = Types.Timing.Micro(duration);
|
|
59
87
|
stack.push(node);
|
|
@@ -90,8 +118,6 @@ export function treify(entries, options) {
|
|
|
90
118
|
if (startsAfterParent) {
|
|
91
119
|
stack.pop();
|
|
92
120
|
i--;
|
|
93
|
-
// The last created node has been discarded, so discard this id.
|
|
94
|
-
nodeIdCount--;
|
|
95
121
|
continue;
|
|
96
122
|
}
|
|
97
123
|
// 3. If the current event starts during the parent event, but ends
|
|
@@ -106,9 +132,10 @@ export function treify(entries, options) {
|
|
|
106
132
|
// contained within the parent event. Create a node for the current
|
|
107
133
|
// event, establish the parent/child relationship, then proceed with the
|
|
108
134
|
// next event.
|
|
135
|
+
const node = makeEmptyTraceEntryNode(event, makeTraceEntryNodeId());
|
|
109
136
|
node.depth = stack.length;
|
|
110
137
|
node.parent = parentNode;
|
|
111
|
-
parentNode
|
|
138
|
+
appendChild(parentNode, node);
|
|
112
139
|
node.selfTime = Types.Timing.Micro(duration);
|
|
113
140
|
if (parentNode.selfTime !== undefined) {
|
|
114
141
|
parentNode.selfTime = Types.Timing.Micro(parentNode.selfTime - (event.dur || 0));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeHelpers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/TreeHelpers.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAE5C,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAqB,EAAE,CAAC,CAAC,EAAE,WAAW,CAAqB,CAAC;AAEhG,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAmB,EAAE,CAAC,CAAC;IAC5D,KAAK,EAAE,IAAI,GAAG,EAAE;IAChB,QAAQ,EAAE,CAAC;CACZ,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,EAAoB,EAAkB,EAAE,CAAC,CAAC;IAC3G,KAAK;IACL,EAAE;IACF,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,EAAE;IACZ,KAAK,EAAE,CAAC;CACT,CAAC,CAAC;AAmBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM,CAAC,OAAsC,EAAE,OAE9D;IACC,wEAAwE;IACxE,yEAAyE;IACzE,wCAAwC;IACxC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsC,CAAC;IAElE,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,oDAAoD;IACpD,WAAW,GAAG,CAAC,CAAC,CAAC;IACjB,MAAM,IAAI,GAAG,uBAAuB,EAAE,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAA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IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,aAAa,GAAG,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAClD,iEAAiE;QACjE,wDAAwD;QACxD,OAAO,KAAK,CAAC,MAAM,IAAI,SAAS,IAAI,aAAa,EAAE,CAAC;YAClD,KAAK,CAAC,GAAG,EAAE,CAAC;YACZ,MAAM,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAEtB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,MAAM;YACR,CAAC;YACD,aAAa,GAAG,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,GAAG,aAAa,EAAE,CAAC;YAC5C,0DAA0D;YAC1D,0DAA0D;YAC1D,UAAU;YACV,OAAO,KAAK,CAAC;QACf,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors\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 * as Platform from '../../../core/platform/platform.js';\nimport * as Types from '../types/types.js';\n\nimport {eventIsInBounds} from './Timing.js';\n\nlet nodeIdCount = 0;\nexport const makeTraceEntryNodeId = (): TraceEntryNodeId => (++nodeIdCount) as TraceEntryNodeId;\n\nexport const makeEmptyTraceEntryTree = (): TraceEntryTree => ({\n roots: new Set(),\n maxDepth: 0,\n});\n\nexport const makeEmptyTraceEntryNode = (entry: Types.Events.Event, id: TraceEntryNodeId): TraceEntryNode => ({\n entry,\n id,\n parent: null,\n children: [],\n depth: 0,\n});\n\nexport interface TraceEntryTree {\n roots: Set<TraceEntryNode>;\n maxDepth: number;\n}\n\n/** Node in the graph that defines all parent/child relationships. */\nexport interface TraceEntryNode {\n entry: Types.Events.Event;\n depth: number;\n selfTime?: Types.Timing.Micro;\n id: TraceEntryNodeId;\n parent: TraceEntryNode|null;\n children: TraceEntryNode[];\n}\n\nexport type TraceEntryNodeId = Platform.Brand.Brand<number, 'traceEntryNodeIdTag'>;\n\n/**\n * Builds a hierarchy of the entries (trace events and profile calls) in\n * a particular thread of a particular process, assuming that they're\n * sorted, by iterating through all of the events in order.\n *\n * The approach is analogous to how a parser would be implemented. A\n * stack maintains local context. A scanner peeks and pops from the data\n * stream. Various \"tokens\" (events) are treated as \"whitespace\"\n * (ignored).\n *\n * The tree starts out empty and is populated as the hierarchy is built.\n * The nodes are also assumed to be created empty, with no known parent\n * or children.\n *\n * Complexity: O(n), where n = number of events\n */\nexport function treify(entries: readonly Types.Events.Event[], options?: {\n filter: {has: (name: Types.Events.Name) => boolean},\n}): {tree: TraceEntryTree, entryToNode: Map<Types.Events.Event, TraceEntryNode>} {\n // As we construct the tree, store a map of each entry to its node. This\n // means if you are iterating over a list of RendererEntry events you can\n // easily look up that node in the tree.\n const entryToNode = new Map<Types.Events.Event, TraceEntryNode>();\n\n const stack = [];\n // Reset the node id counter for every new renderer.\n nodeIdCount = -1;\n const tree = makeEmptyTraceEntryTree();\n\n for (let i = 0; i < entries.length; i++) {\n const event = entries[i];\n // If the current event should not be part of the tree, then simply proceed\n // with the next event.\n if (options && !options.filter.has(event.name as Types.Events.Name)) {\n continue;\n }\n\n const duration = event.dur || 0;\n const nodeId = makeTraceEntryNodeId();\n const node = makeEmptyTraceEntryNode(event, nodeId);\n\n // If the parent stack is empty, then the current event is a root. Create a\n // node for it, mark it as a root, then proceed with the next event.\n if (stack.length === 0) {\n tree.roots.add(node);\n node.selfTime = Types.Timing.Micro(duration);\n stack.push(node);\n tree.maxDepth = Math.max(tree.maxDepth, stack.length);\n entryToNode.set(event, node);\n continue;\n }\n\n const parentNode = stack.at(-1);\n if (parentNode === undefined) {\n throw new Error('Impossible: no parent node found in the stack');\n }\n\n const parentEvent = parentNode.entry;\n\n const begin = event.ts;\n const parentBegin = parentEvent.ts;\n const parentDuration = parentEvent.dur || 0;\n const end = begin + duration;\n const parentEnd = parentBegin + parentDuration;\n // Check the relationship between the parent event at the top of the stack,\n // and the current event being processed. There are only 4 distinct\n // possibilities, only 2 of them actually valid, given the assumed sorting:\n // 1. Current event starts before the parent event, ends whenever. (invalid)\n // 2. Current event starts after the parent event, ends whenever. (valid)\n // 3. Current event starts during the parent event, ends after. (invalid)\n // 4. Current event starts and ends during the parent event. (valid)\n\n // 1. If the current event starts before the parent event, then the data is\n // not sorted properly, messed up some way, or this logic is incomplete.\n const startsBeforeParent = begin < parentBegin;\n if (startsBeforeParent) {\n throw new Error('Impossible: current event starts before the parent event');\n }\n\n // 2. If the current event starts after the parent event, then it's a new\n // parent. Pop, then handle current event again.\n const startsAfterParent = begin >= parentEnd;\n if (startsAfterParent) {\n stack.pop();\n i--;\n // The last created node has been discarded, so discard this id.\n nodeIdCount--;\n continue;\n }\n // 3. If the current event starts during the parent event, but ends\n // after it, then the data is messed up some way, for example a\n // profile call was sampled too late after its start, ignore the\n // problematic event.\n const endsAfterParent = end > parentEnd;\n if (endsAfterParent) {\n continue;\n }\n\n // 4. The only remaining case is the common case, where the current event is\n // contained within the parent event. Create a node for the current\n // event, establish the parent/child relationship, then proceed with the\n // next event.\n node.depth = stack.length;\n node.parent = parentNode;\n parentNode.children.push(node);\n node.selfTime = Types.Timing.Micro(duration);\n if (parentNode.selfTime !== undefined) {\n parentNode.selfTime = Types.Timing.Micro(parentNode.selfTime - (event.dur || 0));\n }\n stack.push(node);\n tree.maxDepth = Math.max(tree.maxDepth, stack.length);\n entryToNode.set(event, node);\n }\n return {tree, entryToNode};\n}\n\n/**\n * Iterates events in a tree hierarchically, from top to bottom,\n * calling back on every event's start and end in the order\n * as it traverses down and then up the tree.\n *\n * For example, given this tree, the following callbacks\n * are expected to be made in the following order\n * |---------------A---------------|\n * |------B------||-------D------|\n * |---C---|\n *\n * 1. Start A\n * 3. Start B\n * 4. Start C\n * 5. End C\n * 6. End B\n * 7. Start D\n * 8. End D\n * 9. End A\n *\n */\nexport function walkTreeFromEntry(\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n rootEntry: Types.Events.Event,\n onEntryStart: (entry: Types.Events.Event) => void,\n onEntryEnd: (entry: Types.Events.Event) => void,\n ): void {\n const startNode = entryToNode.get(rootEntry);\n if (!startNode) {\n return;\n }\n walkTreeByNode(entryToNode, startNode, onEntryStart, onEntryEnd);\n}\n\n/**\n * Given a Helpers.TreeHelpers.RendererTree, this will iterates events in hierarchically, visiting\n * each root node and working from top to bottom, calling back on every event's\n * start and end in the order as it traverses down and then up the tree.\n *\n * For example, given this tree, the following callbacks\n * are expected to be made in the following order\n * |------------- Task A -------------||-- Task E --|\n * |-- Task B --||-- Task D --|\n * |- Task C -|\n *\n * 1. Start A\n * 3. Start B\n * 4. Start C\n * 5. End C\n * 6. End B\n * 7. Start D\n * 8. End D\n * 9. End A\n * 10. Start E\n * 11. End E\n *\n */\n\nexport function walkEntireTree(\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n tree: TraceEntryTree,\n onEntryStart: (entry: Types.Events.Event) => void,\n onEntryEnd: (entry: Types.Events.Event) => void,\n traceWindowToInclude?: Types.Timing.TraceWindowMicro,\n minDuration?: Types.Timing.Micro,\n ): void {\n for (const rootNode of tree.roots) {\n walkTreeByNode(entryToNode, rootNode, onEntryStart, onEntryEnd, traceWindowToInclude, minDuration);\n }\n}\n\nfunction walkTreeByNode(\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n rootNode: TraceEntryNode,\n onEntryStart: (entry: Types.Events.Event) => void,\n onEntryEnd: (entry: Types.Events.Event) => void,\n traceWindowToInclude?: Types.Timing.TraceWindowMicro,\n minDuration?: Types.Timing.Micro,\n ): void {\n if (traceWindowToInclude && !treeNodeIsInWindow(rootNode, traceWindowToInclude)) {\n // If this node is not within the provided window, we can skip it. We also\n // can skip all its children too, as we know they won't be in the window if\n // their parent is not.\n return;\n }\n\n if (typeof minDuration !== 'undefined') {\n const duration = Types.Timing.Micro(\n rootNode.entry.ts + Types.Timing.Micro(rootNode.entry.dur ?? 0),\n );\n if (duration < minDuration) {\n return;\n }\n }\n\n onEntryStart(rootNode.entry);\n for (const child of rootNode.children) {\n walkTreeByNode(entryToNode, child, onEntryStart, onEntryEnd, traceWindowToInclude, minDuration);\n }\n onEntryEnd(rootNode.entry);\n}\n\n/**\n * Returns true if the provided node is partially or fully within the trace\n * window. The entire node does not have to fit inside the window, but it does\n * have to partially intersect it.\n */\nfunction treeNodeIsInWindow(node: TraceEntryNode, traceWindow: Types.Timing.TraceWindowMicro): boolean {\n return eventIsInBounds(node.entry, traceWindow);\n}\n\n/**\n * Determines if the given events, which are assumed to be ordered can\n * be organized into tree structures.\n * This condition is met if there is *not* a pair of async events\n * e1 and e2 where:\n *\n * e1.startTime < e2.startTime && e1.endTime > e2.startTime && e1.endTime < e2.endTime.\n * or, graphically:\n * |------- e1 ------|\n * |------- e2 --------|\n *\n * Because a parent-child relationship cannot be made from the example\n * above, a tree cannot be made from the set of events.\n *\n * Sync events from the same thread are tree-able by definition.\n *\n * Note that this will also return true if multiple trees can be\n * built, for example if none of the events overlap with each other.\n */\nexport function canBuildTreesFromEvents(events: readonly Types.Events.Event[]): boolean {\n const stack: Types.Events.Event[] = [];\n for (const event of events) {\n const startTime = event.ts;\n const endTime = event.ts + (event.dur ?? 0);\n let parent = stack.at(-1);\n if (parent === undefined) {\n stack.push(event);\n continue;\n }\n let parentEndTime = parent.ts + (parent.dur ?? 0);\n // Discard events that are not parents for this event. The parent\n // is one whose end time is after this event start time.\n while (stack.length && startTime >= parentEndTime) {\n stack.pop();\n parent = stack.at(-1);\n\n if (parent === undefined) {\n break;\n }\n parentEndTime = parent.ts + (parent.dur ?? 0);\n }\n if (stack.length && endTime > parentEndTime) {\n // If such an event exists but its end time is before this\n // event's end time, then a tree cannot be made using this\n // events.\n return false;\n }\n stack.push(event);\n }\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeHelpers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/TreeHelpers.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAE5C,IAAI,WAAW,GAAG,CAAC,CAAC;AACpB,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAqB,EAAE,CAAC,CAAC,EAAE,WAAW,CAAqB,CAAC;AAEhG,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAmB,EAAE,CAAC,CAAC;IAC5D,KAAK,EAAE,IAAI,GAAG,EAAE;IAChB,QAAQ,EAAE,CAAC;CACZ,CAAC,CAAC;AAEH,6EAA6E;AAC7E,+EAA+E;AAC/E,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,MAAM,cAAc,GAAqB,EAAE,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,MAAsB,EAAE,KAAqB;IACvE,IAAI,MAAM,CAAC,QAAQ,KAAK,cAAc,EAAE,CAAC;QACvC,MAAM,CAAC,QAAQ,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,EAAoB,EAAkB,EAAE,CAAC,CAAC;IAC3G,KAAK;IACL,EAAE;IACF,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,cAAc;IACxB,KAAK,EAAE,CAAC;IACR,2EAA2E;IAC3E,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,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors\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 * as Platform from '../../../core/platform/platform.js';\nimport * as Types from '../types/types.js';\n\nimport {eventIsInBounds} from './Timing.js';\n\nlet nodeIdCount = 0;\nexport const makeTraceEntryNodeId = (): TraceEntryNodeId => (++nodeIdCount) as TraceEntryNodeId;\n\nexport const makeEmptyTraceEntryTree = (): TraceEntryTree => ({\n roots: new Set(),\n maxDepth: 0,\n});\n\n// Most nodes in a trace tree are leaves, and most parent nodes have a single\n// child. Sharing an empty array for leaves and creating a 1-element literal on\n// the first append avoids allocating an empty JSArray per leaf and a 17-slot\n// backing store for single-child parents. This array is kept unfrozen so V8\n// uses the same PACKED_ELEMENTS map across leaf and parent children arrays.\nconst EMPTY_CHILDREN: TraceEntryNode[] = [];\n\n/**\n * Appends a child to a `TraceEntryNode`.\n *\n * Call this helper instead of `parent.children.push(child)`. Nodes created by\n * `makeEmptyTraceEntryNode` share a single empty array for their children to\n * save memory; mutating `parent.children` directly on a leaf node corrupts all\n * leaf nodes.\n */\nexport function appendChild(parent: TraceEntryNode, child: TraceEntryNode): void {\n if (parent.children === EMPTY_CHILDREN) {\n parent.children = [child];\n } else {\n parent.children.push(child);\n }\n}\n\nexport const makeEmptyTraceEntryNode = (entry: Types.Events.Event, id: TraceEntryNodeId): TraceEntryNode => ({\n entry,\n id,\n parent: null,\n children: EMPTY_CHILDREN,\n depth: 0,\n // selfTime is set on every node after creation. Declaring it here keeps it\n // inside the object; adding it later makes V8 allocate a separate property\n // store for every node.\n selfTime: undefined,\n});\n\nexport interface TraceEntryTree {\n roots: Set<TraceEntryNode>;\n maxDepth: number;\n}\n\n/** Node in the graph that defines all parent/child relationships. */\nexport interface TraceEntryNode {\n entry: Types.Events.Event;\n depth: number;\n selfTime?: Types.Timing.Micro;\n id: TraceEntryNodeId;\n parent: TraceEntryNode|null;\n children: TraceEntryNode[];\n}\n\nexport type TraceEntryNodeId = Platform.Brand.Brand<number, 'traceEntryNodeIdTag'>;\n\n/**\n * Builds a hierarchy of the entries (trace events and profile calls) in\n * a particular thread of a particular process, assuming that they're\n * sorted, by iterating through all of the events in order.\n *\n * The approach is analogous to how a parser would be implemented. A\n * stack maintains local context. A scanner peeks and pops from the data\n * stream. Various \"tokens\" (events) are treated as \"whitespace\"\n * (ignored).\n *\n * The tree starts out empty and is populated as the hierarchy is built.\n * The nodes are also assumed to be created empty, with no known parent\n * or children.\n *\n * If `targetEntryToNode` is provided, it is populated in-place with each\n * event's `TraceEntryNode` and returned as `entryToNode`.\n *\n * Complexity: O(n), where n = number of events\n */\nexport function treify(\n entries: readonly Types.Events.Event[],\n options?: {\n filter: {has: (name: Types.Events.Name) => boolean},\n },\n targetEntryToNode?: Map<Types.Events.Event, TraceEntryNode>,\n ): {tree: TraceEntryTree, entryToNode: Map<Types.Events.Event, TraceEntryNode>} {\n // As we construct the tree, store a map of each entry to its node. This\n // means if you are iterating over a list of RendererEntry events you can\n // easily look up that node in the tree.\n const entryToNode = targetEntryToNode ?? new Map<Types.Events.Event, TraceEntryNode>();\n\n const stack = [];\n // Reset the node id counter for every new renderer.\n nodeIdCount = -1;\n const tree = makeEmptyTraceEntryTree();\n\n for (let i = 0; i < entries.length; i++) {\n const event = entries[i];\n // If the current event should not be part of the tree, then simply proceed\n // with the next event.\n if (options && !options.filter.has(event.name as Types.Events.Name)) {\n continue;\n }\n\n const duration = event.dur || 0;\n\n // If the parent stack is empty, then the current event is a root. Create a\n // node for it, mark it as a root, then proceed with the next event.\n if (stack.length === 0) {\n const node = makeEmptyTraceEntryNode(event, makeTraceEntryNodeId());\n tree.roots.add(node);\n node.selfTime = Types.Timing.Micro(duration);\n stack.push(node);\n tree.maxDepth = Math.max(tree.maxDepth, stack.length);\n entryToNode.set(event, node);\n continue;\n }\n\n const parentNode = stack.at(-1);\n if (parentNode === undefined) {\n throw new Error('Impossible: no parent node found in the stack');\n }\n\n const parentEvent = parentNode.entry;\n\n const begin = event.ts;\n const parentBegin = parentEvent.ts;\n const parentDuration = parentEvent.dur || 0;\n const end = begin + duration;\n const parentEnd = parentBegin + parentDuration;\n // Check the relationship between the parent event at the top of the stack,\n // and the current event being processed. There are only 4 distinct\n // possibilities, only 2 of them actually valid, given the assumed sorting:\n // 1. Current event starts before the parent event, ends whenever. (invalid)\n // 2. Current event starts after the parent event, ends whenever. (valid)\n // 3. Current event starts during the parent event, ends after. (invalid)\n // 4. Current event starts and ends during the parent event. (valid)\n\n // 1. If the current event starts before the parent event, then the data is\n // not sorted properly, messed up some way, or this logic is incomplete.\n const startsBeforeParent = begin < parentBegin;\n if (startsBeforeParent) {\n throw new Error('Impossible: current event starts before the parent event');\n }\n\n // 2. If the current event starts after the parent event, then it's a new\n // parent. Pop, then handle current event again.\n const startsAfterParent = begin >= parentEnd;\n if (startsAfterParent) {\n stack.pop();\n i--;\n continue;\n }\n // 3. If the current event starts during the parent event, but ends\n // after it, then the data is messed up some way, for example a\n // profile call was sampled too late after its start, ignore the\n // problematic event.\n const endsAfterParent = end > parentEnd;\n if (endsAfterParent) {\n continue;\n }\n\n // 4. The only remaining case is the common case, where the current event is\n // contained within the parent event. Create a node for the current\n // event, establish the parent/child relationship, then proceed with the\n // next event.\n const node = makeEmptyTraceEntryNode(event, makeTraceEntryNodeId());\n node.depth = stack.length;\n node.parent = parentNode;\n appendChild(parentNode, node);\n node.selfTime = Types.Timing.Micro(duration);\n if (parentNode.selfTime !== undefined) {\n parentNode.selfTime = Types.Timing.Micro(parentNode.selfTime - (event.dur || 0));\n }\n stack.push(node);\n tree.maxDepth = Math.max(tree.maxDepth, stack.length);\n entryToNode.set(event, node);\n }\n return {tree, entryToNode};\n}\n\n/**\n * Iterates events in a tree hierarchically, from top to bottom,\n * calling back on every event's start and end in the order\n * as it traverses down and then up the tree.\n *\n * For example, given this tree, the following callbacks\n * are expected to be made in the following order\n * |---------------A---------------|\n * |------B------||-------D------|\n * |---C---|\n *\n * 1. Start A\n * 3. Start B\n * 4. Start C\n * 5. End C\n * 6. End B\n * 7. Start D\n * 8. End D\n * 9. End A\n *\n */\nexport function walkTreeFromEntry(\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n rootEntry: Types.Events.Event,\n onEntryStart: (entry: Types.Events.Event) => void,\n onEntryEnd: (entry: Types.Events.Event) => void,\n ): void {\n const startNode = entryToNode.get(rootEntry);\n if (!startNode) {\n return;\n }\n walkTreeByNode(entryToNode, startNode, onEntryStart, onEntryEnd);\n}\n\n/**\n * Given a Helpers.TreeHelpers.RendererTree, this will iterates events in hierarchically, visiting\n * each root node and working from top to bottom, calling back on every event's\n * start and end in the order as it traverses down and then up the tree.\n *\n * For example, given this tree, the following callbacks\n * are expected to be made in the following order\n * |------------- Task A -------------||-- Task E --|\n * |-- Task B --||-- Task D --|\n * |- Task C -|\n *\n * 1. Start A\n * 3. Start B\n * 4. Start C\n * 5. End C\n * 6. End B\n * 7. Start D\n * 8. End D\n * 9. End A\n * 10. Start E\n * 11. End E\n *\n */\n\nexport function walkEntireTree(\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n tree: TraceEntryTree,\n onEntryStart: (entry: Types.Events.Event) => void,\n onEntryEnd: (entry: Types.Events.Event) => void,\n traceWindowToInclude?: Types.Timing.TraceWindowMicro,\n minDuration?: Types.Timing.Micro,\n ): void {\n for (const rootNode of tree.roots) {\n walkTreeByNode(entryToNode, rootNode, onEntryStart, onEntryEnd, traceWindowToInclude, minDuration);\n }\n}\n\nfunction walkTreeByNode(\n entryToNode: Map<Types.Events.Event, TraceEntryNode>,\n rootNode: TraceEntryNode,\n onEntryStart: (entry: Types.Events.Event) => void,\n onEntryEnd: (entry: Types.Events.Event) => void,\n traceWindowToInclude?: Types.Timing.TraceWindowMicro,\n minDuration?: Types.Timing.Micro,\n ): void {\n if (traceWindowToInclude && !treeNodeIsInWindow(rootNode, traceWindowToInclude)) {\n // If this node is not within the provided window, we can skip it. We also\n // can skip all its children too, as we know they won't be in the window if\n // their parent is not.\n return;\n }\n\n if (typeof minDuration !== 'undefined') {\n const duration = Types.Timing.Micro(\n rootNode.entry.ts + Types.Timing.Micro(rootNode.entry.dur ?? 0),\n );\n if (duration < minDuration) {\n return;\n }\n }\n\n onEntryStart(rootNode.entry);\n for (const child of rootNode.children) {\n walkTreeByNode(entryToNode, child, onEntryStart, onEntryEnd, traceWindowToInclude, minDuration);\n }\n onEntryEnd(rootNode.entry);\n}\n\n/**\n * Returns true if the provided node is partially or fully within the trace\n * window. The entire node does not have to fit inside the window, but it does\n * have to partially intersect it.\n */\nfunction treeNodeIsInWindow(node: TraceEntryNode, traceWindow: Types.Timing.TraceWindowMicro): boolean {\n return eventIsInBounds(node.entry, traceWindow);\n}\n\n/**\n * Determines if the given events, which are assumed to be ordered can\n * be organized into tree structures.\n * This condition is met if there is *not* a pair of async events\n * e1 and e2 where:\n *\n * e1.startTime < e2.startTime && e1.endTime > e2.startTime && e1.endTime < e2.endTime.\n * or, graphically:\n * |------- e1 ------|\n * |------- e2 --------|\n *\n * Because a parent-child relationship cannot be made from the example\n * above, a tree cannot be made from the set of events.\n *\n * Sync events from the same thread are tree-able by definition.\n *\n * Note that this will also return true if multiple trees can be\n * built, for example if none of the events overlap with each other.\n */\nexport function canBuildTreesFromEvents(events: readonly Types.Events.Event[]): boolean {\n const stack: Types.Events.Event[] = [];\n for (const event of events) {\n const startTime = event.ts;\n const endTime = event.ts + (event.dur ?? 0);\n let parent = stack.at(-1);\n if (parent === undefined) {\n stack.push(event);\n continue;\n }\n let parentEndTime = parent.ts + (parent.dur ?? 0);\n // Discard events that are not parents for this event. The parent\n // is one whose end time is after this event start time.\n while (stack.length && startTime >= parentEndTime) {\n stack.pop();\n parent = stack.at(-1);\n\n if (parent === undefined) {\n break;\n }\n parentEndTime = parent.ts + (parent.dur ?? 0);\n }\n if (stack.length && endTime > parentEndTime) {\n // If such an event exists but its end time is before this\n // event's end time, then a tree cannot be made using this\n // events.\n return false;\n }\n stack.push(event);\n }\n return true;\n}\n"]}
|
|
@@ -84,8 +84,7 @@ export function generateInsight(data, context) {
|
|
|
84
84
|
mainDocumentUrl = context.navigation.args.context.URL;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
mainDocumentUrl =
|
|
88
|
-
context.navigation.args.data?.documentLoaderURL ?? context.navigation.args.data?.url ?? mainDocumentUrl;
|
|
87
|
+
mainDocumentUrl = context.navigation.args.data?.documentLoaderURL ?? mainDocumentUrl;
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
return finalize({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DuplicatedJavaScript.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DuplicatedJavaScript.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,iCAAiC,EAAE,2BAA2B,EAAC,MAAM,aAAa,CAAC;AAC3F,OAAO,EACL,eAAe,EACf,WAAW,GAIZ,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,uBAAuB;IAC9B;;OAEG;IACH,WAAW,EACP,kMAAkM;IACtM;;OAEG;IACH,YAAY,EAAE,QAAQ;IACtB;;OAEG;IACH,qBAAqB,EAAE,kBAAkB;IACzC;;OAEG;IACH,sBAAsB,EAAE,gCAAgC;CAChD,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,+CAA+C,EAAE,SAAS,CAAC,CAAC;AACrG,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAA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,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;YAChE,sBAAsB,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;QACrG,CAAC;IACH,CAAC;IAED,IAAI,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;IAC7C,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,IAAI,KAAK,CAAC,MAAM,CAAC,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3D,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,eAAe
|
|
1
|
+
{"version":3,"file":"DuplicatedJavaScript.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DuplicatedJavaScript.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,iCAAiC,EAAE,2BAA2B,EAAC,MAAM,aAAa,CAAC;AAC3F,OAAO,EACL,eAAe,EACf,WAAW,GAIZ,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,uBAAuB;IAC9B;;OAEG;IACH,WAAW,EACP,kMAAkM;IACtM;;OAEG;IACH,YAAY,EAAE,QAAQ;IACtB;;OAEG;IACH,qBAAqB,EAAE,kBAAkB;IACzC;;OAEG;IACH,sBAAsB,EAAE,gCAAgC;CAChD,CAAC;AAEX,MAAM,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CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAC/F,OAAO;YACL,IAAI,EAAE,eAAe;YACrB,KAAK,EAAE,OAAO;YACd,aAAa,EAAE,OAAO;SACvB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2025 The Chromium Authors\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 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 {estimateCompressionRatioForScript, metricSavingsForWastedBytes} from './Common.js';\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 identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.\n */\n title: 'Duplicated JavaScript',\n /**\n * @description Description of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.\n */\n description:\n 'Remove large, [duplicate JavaScript modules](https://developer.chrome.com/docs/performance/insights/duplicated-javascript) from bundles to reduce unnecessary bytes consumed by network activity',\n /**\n * @description Label for a column in a data table; entries will be the locations of JavaScript or CSS code, e.g. the name of a JavaScript package or module.\n */\n columnSource: 'Source',\n /**\n * @description Label for a column in a data table; entries will be the number of wasted bytes due to duplication of a web resource.\n */\n columnDuplicatedBytes: 'Duplicated bytes',\n /**\n * @description Message shown when no duplicated JavaScript is found.\n */\n noDuplicatedJavaScript: 'No duplicated JavaScript found',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/DuplicatedJavaScript.ts', UIStrings);\nexport const i18nString: i18n.LocalizeString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type DuplicatedJavaScriptInsightModel = InsightModel<typeof UIStrings, {\n duplication: Extras.ScriptDuplication.ScriptDuplication,\n duplicationGroupedByNodeModules: Extras.ScriptDuplication.ScriptDuplication,\n scriptsWithDuplication: Handlers.ModelHandlers.Scripts.Script[],\n scripts: Handlers.ModelHandlers.Scripts.Script[],\n mainDocumentUrl: string,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<DuplicatedJavaScriptInsightModel>):\n DuplicatedJavaScriptInsightModel {\n const requests = partialModel.scriptsWithDuplication.map(script => script.request).filter(e => !!e);\n\n return {\n insightKey: InsightKeys.DUPLICATE_JAVASCRIPT,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/duplicated-javascript',\n category: InsightCategory.LCP,\n state: Boolean(partialModel.duplication.values().next().value) ? 'fail' : 'pass',\n relatedEvents: [...new Set(requests)],\n ...partialModel,\n };\n}\n\nexport function isDuplicatedJavaScriptInsight(model: InsightModel): model is DuplicatedJavaScriptInsightModel {\n return model.insightKey === InsightKeys.DUPLICATE_JAVASCRIPT;\n}\n\nexport function generateInsight(\n data: Handlers.Types.HandlerData, context: InsightSetContext): DuplicatedJavaScriptInsightModel {\n const scripts = data.Scripts.scripts.filter(script => {\n if (script.frame !== context.frameId) {\n return false;\n }\n\n if (script.url?.startsWith('chrome-extension://')) {\n return false;\n }\n\n return Helpers.Timing.timestampIsInBounds(context.bounds, script.ts);\n });\n\n const compressionRatios = new Map<string, number>();\n for (const script of scripts) {\n if (script.request) {\n compressionRatios.set(script.request.args.data.requestId, estimateCompressionRatioForScript(script));\n }\n }\n\n const {duplication, duplicationGroupedByNodeModules} =\n Extras.ScriptDuplication.computeScriptDuplication({scripts}, compressionRatios);\n const scriptsWithDuplication = [...duplication.values().flatMap(data => data.duplicates.map(d => d.script))];\n\n const wastedBytesByRequestId = new Map<string, number>();\n for (const {duplicates} of duplication.values()) {\n for (let i = 1; i < duplicates.length; i++) {\n const sourceData = duplicates[i];\n if (!sourceData.script.request) {\n continue;\n }\n\n const transferSize = sourceData.attributedSize;\n const requestId = sourceData.script.request.args.data.requestId;\n wastedBytesByRequestId.set(requestId, (wastedBytesByRequestId.get(requestId) || 0) + transferSize);\n }\n }\n\n let mainDocumentUrl = data.Meta.mainFrameURL;\n if (context.navigation) {\n if (Types.Events.isSoftNavigationStart(context.navigation)) {\n mainDocumentUrl = context.navigation.args.context.URL;\n } else {\n mainDocumentUrl = context.navigation.args.data?.documentLoaderURL ?? mainDocumentUrl;\n }\n }\n\n return finalize({\n duplication,\n duplicationGroupedByNodeModules,\n scriptsWithDuplication: [...new Set(scriptsWithDuplication)],\n scripts,\n mainDocumentUrl,\n metricSavings: metricSavingsForWastedBytes(wastedBytesByRequestId, context),\n wastedBytes: wastedBytesByRequestId.values().reduce((acc, cur) => acc + cur, 0),\n });\n}\n\nexport function createOverlays(model: DuplicatedJavaScriptInsightModel): Types.Overlays.Overlay[] {\n return model.scriptsWithDuplication.map(script => script.request).filter(e => !!e).map(request => {\n return {\n type: 'ENTRY_OUTLINE',\n entry: request,\n outlineReason: 'ERROR',\n };\n });\n}\n"]}
|
|
@@ -101,11 +101,11 @@ export function generateInsight(data, context) {
|
|
|
101
101
|
let totalElapsedUs = 0;
|
|
102
102
|
let totalMatchAttempts = 0;
|
|
103
103
|
let totalMatchCount = 0;
|
|
104
|
-
|
|
104
|
+
for (const timing of selectorTimings) {
|
|
105
105
|
totalElapsedUs += timing[Types.Events.SelectorTimingsKey.Elapsed];
|
|
106
106
|
totalMatchAttempts += timing[Types.Events.SelectorTimingsKey.MatchAttempts];
|
|
107
107
|
totalMatchCount += timing[Types.Events.SelectorTimingsKey.MatchCount];
|
|
108
|
-
}
|
|
108
|
+
}
|
|
109
109
|
let topSelectorElapsedMs = null;
|
|
110
110
|
let topSelectorMatchAttempts = null;
|
|
111
111
|
if (selectorTimings.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SlowCSSSelector.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/SlowCSSSelector.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAEnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,EACf,WAAW,GAIZ,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,oBAAoB;IAE3B;;OAEG;IACH,WAAW,EACP,4UAA4U;IAChV;;OAEG;IACH,aAAa,EAAE,gBAAgB;IAC/B;;OAEG;IACH,UAAU,EAAE,aAAa;IACzB;;OAEG;IACH,OAAO,EAAE,cAAc;IACvB;;OAEG;IACH,YAAY,EAAE,eAAe;IAC7B;;OAEG;IACH,KAAK,EAAE,OAAO;IACd;;OAEG;IACH,kBAAkB,EACd,0GAA0G;IAC9G;;OAEG;IACH,sBAAsB,EAAE,2BAA2B;IACnD;;OAEG;IACH,uBAAuB,EAAE,4BAA4B;CAC7C,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,0CAA0C,EAAE,SAAS,CAAC,CAAC;AAChG,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAClG,MAAM,wBAAwB,GAAG,GAAG,CAAC,CAAE,qCAAqC;AAU5E,SAAS,sBAAsB,CAAC,IAA4D,EAC5D,OAA0B;IACxD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAuC,CAAC;IAEnE,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC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C,MAAM,CAAC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC;QAC3D,kBAAkB;QAClB,eAAe;QACf,oBAAoB;QACpB,wBAAwB;KACzB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAA8B;IAC3D,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\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 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 slow CSS selectors.\n */\n title: 'CSS selector costs',\n\n /**\n * @description Text to describe how to improve the performance of CSS selectors.\n */\n description:\n 'If recalculate style costs remain high, selector optimization can reduce them. [Optimize the selectors](https://developer.chrome.com/docs/performance/insights/slow-css-selector) with both high elapsed time and high slow-path %. Simpler selectors, fewer selectors, a smaller DOM, and a shallower DOM will all reduce matching costs.',\n /**\n * @description Column name for count of elements that the engine attempted to match against a style rule.\n */\n matchAttempts: 'Match attempts',\n /**\n * @description Column name for count of elements that matched a style rule.\n */\n matchCount: 'Match count',\n /**\n * @description Column name for elapsed time spent computing a style rule.\n */\n elapsed: 'Elapsed time',\n /**\n * @description Column name for the selectors that took the longest amount of time/effort.\n */\n topSelectors: 'Top selectors',\n /**\n * @description Column name for a total sum.\n */\n total: 'Total',\n /**\n * @description Text status indicating that no CSS selector data was found.\n */\n enableSelectorData:\n 'No CSS selector data was found. CSS selector stats need to be enabled in the Performance panel settings.',\n /**\n * @description Top CSS selector when ranked by elapsed time in ms.\n */\n topSelectorElapsedTime: 'Top selector elapsed time',\n /**\n * @description Top CSS selector when ranked by match attempt.\n */\n topSelectorMatchAttempt: 'Top selector match attempt',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/SlowCSSSelector.ts', UIStrings);\nexport const i18nString: i18n.LocalizeString = i18n.i18n.getLocalizedString.bind(undefined, str_);\nconst slowCSSSelectorThreshold = 500; // 500us threshold for slow selectors\n\nexport type SlowCSSSelectorInsightModel = InsightModel<typeof UIStrings, {\n totalElapsedMs: Types.Timing.Milli,\n totalMatchAttempts: number,\n totalMatchCount: number,\n topSelectorElapsedMs: Types.Events.SelectorTiming | null,\n topSelectorMatchAttempts: Types.Events.SelectorTiming | null,\n}>;\n\nfunction aggregateSelectorStats(data: Handlers.ModelHandlers.SelectorStats.SelectorStatsData,\n context: InsightSetContext): Types.Events.SelectorTiming[] {\n const selectorMap = new Map<String, Types.Events.SelectorTiming>();\n\n for (const [event, value] of data.dataForRecalcStyleEvent) {\n if (event.args.beginData?.frame !== context.frameId) {\n continue;\n }\n if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {\n continue;\n }\n for (const timing of value.timings) {\n const key =\n timing[Types.Events.SelectorTimingsKey.Selector] + '_' + timing[Types.Events.SelectorTimingsKey.StyleSheetId];\n const findTiming = selectorMap.get(key);\n if (findTiming !== undefined) {\n findTiming[Types.Events.SelectorTimingsKey.Elapsed] += timing[Types.Events.SelectorTimingsKey.Elapsed];\n findTiming[Types.Events.SelectorTimingsKey.FastRejectCount] +=\n timing[Types.Events.SelectorTimingsKey.FastRejectCount];\n findTiming[Types.Events.SelectorTimingsKey.MatchAttempts] +=\n timing[Types.Events.SelectorTimingsKey.MatchAttempts];\n findTiming[Types.Events.SelectorTimingsKey.MatchCount] += timing[Types.Events.SelectorTimingsKey.MatchCount];\n } else {\n selectorMap.set(key, {...timing});\n }\n }\n }\n\n return [...selectorMap.values()];\n}\n\nfunction finalize(partialModel: PartialInsightModel<SlowCSSSelectorInsightModel>): SlowCSSSelectorInsightModel {\n return {\n insightKey: InsightKeys.SLOW_CSS_SELECTOR,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/slow-css-selector',\n category: InsightCategory.ALL,\n state: partialModel.topSelectorElapsedMs && partialModel.topSelectorMatchAttempts ? 'informative' : 'pass',\n ...partialModel,\n };\n}\n\nexport function isSlowCSSSelectorInsight(model: InsightModel): model is SlowCSSSelectorInsightModel {\n return model.insightKey === InsightKeys.SLOW_CSS_SELECTOR;\n}\n\nexport function generateInsight(\n data: Handlers.Types.HandlerData, context: InsightSetContext): SlowCSSSelectorInsightModel {\n const selectorStatsData = data.SelectorStats;\n\n if (!selectorStatsData) {\n throw new Error('no selector stats data');\n }\n\n const selectorTimings = aggregateSelectorStats(selectorStatsData, context);\n\n let totalElapsedUs = 0;\n let totalMatchAttempts = 0;\n let totalMatchCount = 0;\n\n selectorTimings.map(timing => {\n totalElapsedUs += timing[Types.Events.SelectorTimingsKey.Elapsed];\n totalMatchAttempts += timing[Types.Events.SelectorTimingsKey.MatchAttempts];\n totalMatchCount += timing[Types.Events.SelectorTimingsKey.MatchCount];\n });\n\n let topSelectorElapsedMs: Types.Events.SelectorTiming|null = null;\n let topSelectorMatchAttempts: Types.Events.SelectorTiming|null = null;\n\n if (selectorTimings.length > 0) {\n // find the selector with most elapsed time\n topSelectorElapsedMs = selectorTimings.reduce((a, b) => {\n return a[Types.Events.SelectorTimingsKey.Elapsed] > b[Types.Events.SelectorTimingsKey.Elapsed] ? a : b;\n });\n\n // check if the slowest selector is slow enough to trigger insights info\n if (topSelectorElapsedMs &&\n topSelectorElapsedMs[Types.Events.SelectorTimingsKey.Elapsed] < slowCSSSelectorThreshold) {\n topSelectorElapsedMs = null;\n }\n\n // find the selector with most match attempts\n topSelectorMatchAttempts = selectorTimings.reduce((a, b) => {\n return a[Types.Events.SelectorTimingsKey.MatchAttempts] > b[Types.Events.SelectorTimingsKey.MatchAttempts] ? a :\n b;\n });\n }\n\n return finalize({\n // TODO: should we identify RecalcStyle events as linked to this insight?\n relatedEvents: [],\n totalElapsedMs: Types.Timing.Milli(totalElapsedUs / 1000.0),\n totalMatchAttempts,\n totalMatchCount,\n topSelectorElapsedMs,\n topSelectorMatchAttempts,\n });\n}\n\nexport function createOverlays(_: SlowCSSSelectorInsightModel): Types.Overlays.Overlay[] {\n return [];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SlowCSSSelector.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/SlowCSSSelector.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAEnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,EACf,WAAW,GAIZ,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,oBAAoB;IAE3B;;OAEG;IACH,WAAW,EACP,4UAA4U;IAChV;;OAEG;IACH,aAAa,EAAE,gBAAgB;IAC/B;;OAEG;IACH,UAAU,EAAE,aAAa;IACzB;;OAEG;IACH,OAAO,EAAE,cAAc;IACvB;;OAEG;IACH,YAAY,EAAE,eAAe;IAC7B;;OAEG;IACH,KAAK,EAAE,OAAO;IACd;;OAEG;IACH,kBAAkB,EACd,0GAA0G;IAC9G;;OAEG;IACH,sBAAsB,EAAE,2BAA2B;IACnD;;OAEG;IACH,uBAAuB,EAAE,4BAA4B;CAC7C,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,0CAA0C,EAAE,SAAS,CAAC,CAAC;AAChG,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAClG,MAAM,wBAAwB,GAAG,GAAG,CAAC,CAAE,qCAAqC;AAU5E,S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,CAAC,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC;QACjH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,yEAAyE;QACzE,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC;QAC3D,kBAAkB;QAClB,eAAe;QACf,oBAAoB;QACpB,wBAAwB;KACzB,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,CAA8B;IAC3D,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\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 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 slow CSS selectors.\n */\n title: 'CSS selector costs',\n\n /**\n * @description Text to describe how to improve the performance of CSS selectors.\n */\n description:\n 'If recalculate style costs remain high, selector optimization can reduce them. [Optimize the selectors](https://developer.chrome.com/docs/performance/insights/slow-css-selector) with both high elapsed time and high slow-path %. Simpler selectors, fewer selectors, a smaller DOM, and a shallower DOM will all reduce matching costs.',\n /**\n * @description Column name for count of elements that the engine attempted to match against a style rule.\n */\n matchAttempts: 'Match attempts',\n /**\n * @description Column name for count of elements that matched a style rule.\n */\n matchCount: 'Match count',\n /**\n * @description Column name for elapsed time spent computing a style rule.\n */\n elapsed: 'Elapsed time',\n /**\n * @description Column name for the selectors that took the longest amount of time/effort.\n */\n topSelectors: 'Top selectors',\n /**\n * @description Column name for a total sum.\n */\n total: 'Total',\n /**\n * @description Text status indicating that no CSS selector data was found.\n */\n enableSelectorData:\n 'No CSS selector data was found. CSS selector stats need to be enabled in the Performance panel settings.',\n /**\n * @description Top CSS selector when ranked by elapsed time in ms.\n */\n topSelectorElapsedTime: 'Top selector elapsed time',\n /**\n * @description Top CSS selector when ranked by match attempt.\n */\n topSelectorMatchAttempt: 'Top selector match attempt',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/SlowCSSSelector.ts', UIStrings);\nexport const i18nString: i18n.LocalizeString = i18n.i18n.getLocalizedString.bind(undefined, str_);\nconst slowCSSSelectorThreshold = 500; // 500us threshold for slow selectors\n\nexport type SlowCSSSelectorInsightModel = InsightModel<typeof UIStrings, {\n totalElapsedMs: Types.Timing.Milli,\n totalMatchAttempts: number,\n totalMatchCount: number,\n topSelectorElapsedMs: Types.Events.SelectorTiming | null,\n topSelectorMatchAttempts: Types.Events.SelectorTiming | null,\n}>;\n\nfunction aggregateSelectorStats(data: Handlers.ModelHandlers.SelectorStats.SelectorStatsData,\n context: InsightSetContext): Types.Events.SelectorTiming[] {\n const selectorMap = new Map<string, Types.Events.SelectorTiming>();\n\n for (const [event, value] of data.dataForRecalcStyleEvent) {\n if (event.args.beginData?.frame !== context.frameId) {\n continue;\n }\n if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {\n continue;\n }\n for (const timing of value.timings) {\n const key =\n timing[Types.Events.SelectorTimingsKey.Selector] + '_' + timing[Types.Events.SelectorTimingsKey.StyleSheetId];\n const findTiming = selectorMap.get(key);\n if (findTiming !== undefined) {\n findTiming[Types.Events.SelectorTimingsKey.Elapsed] += timing[Types.Events.SelectorTimingsKey.Elapsed];\n findTiming[Types.Events.SelectorTimingsKey.FastRejectCount] +=\n timing[Types.Events.SelectorTimingsKey.FastRejectCount];\n findTiming[Types.Events.SelectorTimingsKey.MatchAttempts] +=\n timing[Types.Events.SelectorTimingsKey.MatchAttempts];\n findTiming[Types.Events.SelectorTimingsKey.MatchCount] += timing[Types.Events.SelectorTimingsKey.MatchCount];\n } else {\n selectorMap.set(key, {...timing});\n }\n }\n }\n\n return [...selectorMap.values()];\n}\n\nfunction finalize(partialModel: PartialInsightModel<SlowCSSSelectorInsightModel>): SlowCSSSelectorInsightModel {\n return {\n insightKey: InsightKeys.SLOW_CSS_SELECTOR,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/slow-css-selector',\n category: InsightCategory.ALL,\n state: partialModel.topSelectorElapsedMs && partialModel.topSelectorMatchAttempts ? 'informative' : 'pass',\n ...partialModel,\n };\n}\n\nexport function isSlowCSSSelectorInsight(model: InsightModel): model is SlowCSSSelectorInsightModel {\n return model.insightKey === InsightKeys.SLOW_CSS_SELECTOR;\n}\n\nexport function generateInsight(\n data: Handlers.Types.HandlerData, context: InsightSetContext): SlowCSSSelectorInsightModel {\n const selectorStatsData = data.SelectorStats;\n\n if (!selectorStatsData) {\n throw new Error('no selector stats data');\n }\n\n const selectorTimings = aggregateSelectorStats(selectorStatsData, context);\n\n let totalElapsedUs = 0;\n let totalMatchAttempts = 0;\n let totalMatchCount = 0;\n\n for (const timing of selectorTimings) {\n totalElapsedUs += timing[Types.Events.SelectorTimingsKey.Elapsed];\n totalMatchAttempts += timing[Types.Events.SelectorTimingsKey.MatchAttempts];\n totalMatchCount += timing[Types.Events.SelectorTimingsKey.MatchCount];\n }\n\n let topSelectorElapsedMs: Types.Events.SelectorTiming|null = null;\n let topSelectorMatchAttempts: Types.Events.SelectorTiming|null = null;\n\n if (selectorTimings.length > 0) {\n // find the selector with most elapsed time\n topSelectorElapsedMs = selectorTimings.reduce((a, b) => {\n return a[Types.Events.SelectorTimingsKey.Elapsed] > b[Types.Events.SelectorTimingsKey.Elapsed] ? a : b;\n });\n\n // check if the slowest selector is slow enough to trigger insights info\n if (topSelectorElapsedMs &&\n topSelectorElapsedMs[Types.Events.SelectorTimingsKey.Elapsed] < slowCSSSelectorThreshold) {\n topSelectorElapsedMs = null;\n }\n\n // find the selector with most match attempts\n topSelectorMatchAttempts = selectorTimings.reduce((a, b) => {\n return a[Types.Events.SelectorTimingsKey.MatchAttempts] > b[Types.Events.SelectorTimingsKey.MatchAttempts] ? a :\n b;\n });\n }\n\n return finalize({\n // TODO: should we identify RecalcStyle events as linked to this insight?\n relatedEvents: [],\n totalElapsedMs: Types.Timing.Milli(totalElapsedUs / 1000.0),\n totalMatchAttempts,\n totalMatchCount,\n topSelectorElapsedMs,\n topSelectorMatchAttempts,\n });\n}\n\nexport function createOverlays(_: SlowCSSSelectorInsightModel): Types.Overlays.Overlay[] {\n return [];\n}\n"]}
|
|
@@ -13,6 +13,7 @@ declare class LargestContentfulPaint extends Metric {
|
|
|
13
13
|
* Finds the NetworkNode corresponding to the LCP image in the dependency graph, if LCP was an image.
|
|
14
14
|
*/
|
|
15
15
|
static findLcpNode(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.NetworkNode | null;
|
|
16
|
+
static isSameFrameTextLcp(processedNavigation: Types.Simulation.ProcessedNavigation): boolean;
|
|
16
17
|
static getOptimisticGraph(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node;
|
|
17
18
|
static getPessimisticGraph(dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node;
|
|
18
19
|
static getEstimateFromSimulation(simulationResult: Simulation.Result, extras?: Extras): Simulation.Result;
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
import * as Core from '../core/core.js';
|
|
5
5
|
import { FirstContentfulPaint } from './FirstContentfulPaint.js';
|
|
6
6
|
import { Metric, } from './Metric.js';
|
|
7
|
+
// Prior to https://crbug.com/583885865, Blink wrote largestContentfulPaint::Candidate
|
|
8
|
+
// with the exact base::TimeTicks presentation timestamp while firstContentfulPaint
|
|
9
|
+
// round-tripped through double seconds (InSecondsF -> base::Seconds), which could
|
|
10
|
+
// truncate the FCP trace timestamp by 1 µs for the exact same frame presentation.
|
|
11
|
+
const SAME_FRAME_TIMESTAMP_TOLERANCE_US = 10;
|
|
7
12
|
function stripUrlHash(urlStr) {
|
|
8
13
|
if (!urlStr.includes('#')) {
|
|
9
14
|
return urlStr;
|
|
@@ -103,12 +108,20 @@ class LargestContentfulPaint extends Metric {
|
|
|
103
108
|
urlMatches.sort((a, b) => a.endTime - b.endTime);
|
|
104
109
|
return urlMatches[0];
|
|
105
110
|
}
|
|
106
|
-
static
|
|
111
|
+
static isSameFrameTextLcp(processedNavigation) {
|
|
107
112
|
const { firstContentfulPaint: fcp, largestContentfulPaint: lcp } = processedNavigation.timestamps;
|
|
113
|
+
if (!lcp) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return Math.abs(lcp - fcp) <= SAME_FRAME_TIMESTAMP_TOLERANCE_US &&
|
|
117
|
+
processedNavigation.largestContentfulPaintEvt?.args?.data?.type === 'text';
|
|
118
|
+
}
|
|
119
|
+
static getOptimisticGraph(dependencyGraph, processedNavigation) {
|
|
120
|
+
const lcp = processedNavigation.timestamps.largestContentfulPaint;
|
|
108
121
|
if (!lcp) {
|
|
109
122
|
throw new Core.LanternError('NO_LCP');
|
|
110
123
|
}
|
|
111
|
-
if (
|
|
124
|
+
if (LargestContentfulPaint.isSameFrameTextLcp(processedNavigation)) {
|
|
112
125
|
return FirstContentfulPaint.getOptimisticGraph(dependencyGraph, processedNavigation);
|
|
113
126
|
}
|
|
114
127
|
const lcpNode = LargestContentfulPaint.findLcpNode(dependencyGraph, processedNavigation);
|
|
@@ -147,11 +160,11 @@ class LargestContentfulPaint extends Metric {
|
|
|
147
160
|
});
|
|
148
161
|
}
|
|
149
162
|
static getPessimisticGraph(dependencyGraph, processedNavigation) {
|
|
150
|
-
const
|
|
163
|
+
const lcp = processedNavigation.timestamps.largestContentfulPaint;
|
|
151
164
|
if (!lcp) {
|
|
152
165
|
throw new Core.LanternError('NO_LCP');
|
|
153
166
|
}
|
|
154
|
-
if (
|
|
167
|
+
if (LargestContentfulPaint.isSameFrameTextLcp(processedNavigation)) {
|
|
155
168
|
return FirstContentfulPaint.getPessimisticGraph(dependencyGraph, processedNavigation);
|
|
156
169
|
}
|
|
157
170
|
return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LargestContentfulPaint.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAKxC,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAEL,MAAM,GAIP,MAAM,aAAa,CAAC;AAErB,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,MAAM,sBAAuB,SAAQ,MAAM;IACzC,MAAM,KAAc,YAAY;QAC9B,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG;SACjB,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,yBAAyB,CAAC,IAAgB;QAC/C,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK,OAAO,CAAC;QACtD,MAAM,aAAa,GAAG,IAAI,CAAC,OA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C,WAAW,CAAC,OAAO,EAAE,CAAC;aAC7C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aAC3E,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAExE,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,2BAA2B,CAAC;YAClD,WAAW,EAAE,gBAAgB,CAAC,WAAW;SAC1C,CAAC;IACJ,CAAC;IAED,MAAM,CAAU,OAAO,CAAC,IAAgC,EAAE,MAAmC;QAC3F,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,CAAC;QACpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,6CAA6C,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjD,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACtE,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED,OAAO,EAAC,sBAAsB,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\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 Core from '../core/core.js';\nimport type * as Graph from '../graph/graph.js';\nimport type * as Simulation from '../simulation/simulation.js';\nimport type * as Types from '../types/types.js';\n\nimport {FirstContentfulPaint} from './FirstContentfulPaint.js';\nimport {\n type Extras,\n Metric,\n type MetricCoefficients,\n type MetricComputationDataInput,\n type MetricResult,\n} from './Metric.js';\n\nfunction stripUrlHash(urlStr: string): string {\n if (!urlStr.includes('#')) {\n return urlStr;\n }\n try {\n const url = new URL(urlStr);\n url.hash = '';\n return url.href;\n } catch {\n return urlStr;\n }\n}\n\nclass LargestContentfulPaint extends Metric {\n static override get coefficients(): MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n /**\n * Low priority image nodes are usually offscreen and very unlikely to be the\n * resource that is required for LCP. Our LCP graphs include everything except for these images.\n */\n static isNotLowPriorityImageNode(node: Graph.Node): boolean {\n if (node.type !== 'network') {\n return true;\n }\n const isImage = node.request.resourceType === 'Image';\n const isLowPriority = node.request.priority === 'Low' || node.request.priority === 'VeryLow';\n return !isImage || !isLowPriority;\n }\n\n /**\n * Finds the NetworkNode corresponding to the LCP image in the dependency graph, if LCP was an image.\n */\n static findLcpNode(dependencyGraph: Graph.Node,\n processedNavigation: Types.Simulation.ProcessedNavigation): Graph.NetworkNode|null {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n return null;\n }\n\n const lcpEvent = processedNavigation.largestContentfulPaintEvt;\n if (lcpEvent?.args?.data?.type && lcpEvent.args.data.type !== 'image') {\n return null;\n }\n\n const {lcpRequestId, lcpImageUrl} = processedNavigation;\n if (!lcpRequestId && !lcpImageUrl) {\n return null;\n }\n\n if (lcpRequestId) {\n const idMatches: Graph.NetworkNode[] = [];\n dependencyGraph.traverse(node => {\n if (node.type !== 'network' || node.request.redirectDestination) {\n return;\n }\n if (node.request.finished === false || node.endTime < 0 || node.startTime > lcp) {\n return;\n }\n const baseRequestId = node.request.requestId.replace(/(:redirect|:duplicate)+$/, '');\n if (baseRequestId === lcpRequestId) {\n idMatches.push(node);\n }\n });\n if (idMatches.length) {\n idMatches.sort((a, b) => a.endTime - b.endTime);\n return idMatches[0];\n }\n }\n\n if (!lcpImageUrl) {\n return null;\n }\n\n const normalizedLcpUrl = stripUrlHash(lcpImageUrl);\n const lcpFrameId = lcpEvent?.args?.frame;\n const urlMatches: Graph.NetworkNode[] = [];\n dependencyGraph.traverse(node => {\n if (node.type !== 'network' || node.request.redirectDestination) {\n return;\n }\n if (node.request.finished === false || node.endTime < 0 || node.startTime > lcp) {\n return;\n }\n if (lcpFrameId && node.request.frameId && node.request.frameId !== lcpFrameId) {\n return;\n }\n if (node.request.resourceType && node.request.resourceType !== 'Image' && node.request.resourceType !== 'Media') {\n return;\n }\n const matchesUrl = node.request.url === lcpImageUrl || stripUrlHash(node.request.url) === normalizedLcpUrl ||\n Boolean(node.request.redirects?.some(r => r.url === lcpImageUrl || stripUrlHash(r.url) === normalizedLcpUrl));\n if (matchesUrl) {\n urlMatches.push(node);\n }\n });\n\n if (!urlMatches.length) {\n return null;\n }\n urlMatches.sort((a, b) => a.endTime - b.endTime);\n return urlMatches[0];\n }\n\n static override getOptimisticGraph(\n dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node {\n const {firstContentfulPaint: fcp, largestContentfulPaint: lcp} = processedNavigation.timestamps;\n if (!lcp) {\n throw new Core.LanternError('NO_LCP');\n }\n if (fcp === lcp && processedNavigation.largestContentfulPaintEvt?.args?.data?.type === 'text') {\n return FirstContentfulPaint.getOptimisticGraph(dependencyGraph, processedNavigation);\n }\n\n const lcpNode = LargestContentfulPaint.findLcpNode(dependencyGraph, processedNavigation);\n if (lcpNode) {\n const fcpOptimisticGraph = FirstContentfulPaint.getOptimisticGraph(dependencyGraph, processedNavigation);\n const criticalNodeIds = new Set<string>();\n fcpOptimisticGraph.traverse(node => criticalNodeIds.add(node.id));\n criticalNodeIds.add(lcpNode.id);\n\n // PageDependencyGraph.linkCPUNodes does not add CPUNode -> Image edges, so if the LCP image\n // has any Script dependencies (e.g. JS-injected hero image or JS-injected stylesheet),\n // include the CPU tasks that evaluated those scripts prior to the LCP request.\n const initiatorScriptUrls = new Set<string>();\n lcpNode.traverse(node => {\n if (node.type === 'network' && node.request.resourceType === 'Script') {\n initiatorScriptUrls.add(node.request.url);\n }\n }, node => node.getDependencies());\n\n if (initiatorScriptUrls.size) {\n dependencyGraph.traverse(node => {\n if (node.type !== 'cpu' || node.startTime > lcpNode.startTime) {\n return;\n }\n for (const url of node.getEvaluateScriptURLs()) {\n if (initiatorScriptUrls.has(url)) {\n criticalNodeIds.add(node.id);\n break;\n }\n }\n });\n }\n\n return dependencyGraph.cloneWithRelationships(node => criticalNodeIds.has(node.id));\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,\n });\n }\n\n static override getPessimisticGraph(\n dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node {\n const {firstContentfulPaint: fcp, largestContentfulPaint: lcp} = processedNavigation.timestamps;\n if (!lcp) {\n throw new Core.LanternError('NO_LCP');\n }\n if (fcp === lcp && processedNavigation.largestContentfulPaintEvt?.args?.data?.type === 'text') {\n return FirstContentfulPaint.getPessimisticGraph(dependencyGraph, processedNavigation);\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: _ => true,\n // For pessimistic LCP we'll include *all* layout nodes\n additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),\n });\n }\n\n static override getEstimateFromSimulation(simulationResult: Simulation.Result, extras?: Extras): Simulation.Result {\n if (extras?.optimistic) {\n return simulationResult;\n }\n\n const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())\n .filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))\n .map(entry => entry[1].endTime);\n\n return {\n timeInMs: Math.max(...nodeTimesNotOffscreenImages),\n nodeTimings: simulationResult.nodeTimings,\n };\n }\n\n static override compute(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): MetricResult {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Core.LanternError('FCP is required to calculate the LCP metric');\n }\n\n const metricResult = super.compute(data, extras);\n metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);\n return metricResult;\n }\n}\n\nexport {LargestContentfulPaint};\n"]}
|
|
1
|
+
{"version":3,"file":"LargestContentfulPaint.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAKxC,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAEL,MAAM,GAIP,MAAM,aAAa,CAAC;AAErB,sFAAsF;AACtF,mFAAmF;AACnF,kFAAkF;AAClF,kFAAkF;AAClF,MAAM,iCAAiC,GAAG,EAAE,CAAC;AAE7C,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;QACd,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,MAAM,sBAAuB,SAAQ,MAAM;IACzC,MAAM,KAAc,YAAY;QAC9B,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG;SACjB,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,yBAAyB,CAAC,IAAgB;QAC/C,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,KAAK,OAAO,CAAC;QACtD,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO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;IAED,MAAM,CAAU,yBAAyB,CAAC,gBAAmC,EAAE,MAAe;QAC5F,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC;YACvB,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,2BAA2B,GAAG,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aAC7C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aAC3E,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAExE,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,2BAA2B,CAAC;YAClD,WAAW,EAAE,gBAAgB,CAAC,WAAW;SAC1C,CAAC;IACJ,CAAC;IAED,MAAM,CAAU,OAAO,CAAC,IAAgC,EAAE,MAAmC;QAC3F,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,CAAC;QACpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,6CAA6C,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACjD,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACtE,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED,OAAO,EAAC,sBAAsB,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\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 Core from '../core/core.js';\nimport type * as Graph from '../graph/graph.js';\nimport type * as Simulation from '../simulation/simulation.js';\nimport type * as Types from '../types/types.js';\n\nimport {FirstContentfulPaint} from './FirstContentfulPaint.js';\nimport {\n type Extras,\n Metric,\n type MetricCoefficients,\n type MetricComputationDataInput,\n type MetricResult,\n} from './Metric.js';\n\n// Prior to https://crbug.com/583885865, Blink wrote largestContentfulPaint::Candidate\n// with the exact base::TimeTicks presentation timestamp while firstContentfulPaint\n// round-tripped through double seconds (InSecondsF -> base::Seconds), which could\n// truncate the FCP trace timestamp by 1 µs for the exact same frame presentation.\nconst SAME_FRAME_TIMESTAMP_TOLERANCE_US = 10;\n\nfunction stripUrlHash(urlStr: string): string {\n if (!urlStr.includes('#')) {\n return urlStr;\n }\n try {\n const url = new URL(urlStr);\n url.hash = '';\n return url.href;\n } catch {\n return urlStr;\n }\n}\n\nclass LargestContentfulPaint extends Metric {\n static override get coefficients(): MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n /**\n * Low priority image nodes are usually offscreen and very unlikely to be the\n * resource that is required for LCP. Our LCP graphs include everything except for these images.\n */\n static isNotLowPriorityImageNode(node: Graph.Node): boolean {\n if (node.type !== 'network') {\n return true;\n }\n const isImage = node.request.resourceType === 'Image';\n const isLowPriority = node.request.priority === 'Low' || node.request.priority === 'VeryLow';\n return !isImage || !isLowPriority;\n }\n\n /**\n * Finds the NetworkNode corresponding to the LCP image in the dependency graph, if LCP was an image.\n */\n static findLcpNode(dependencyGraph: Graph.Node,\n processedNavigation: Types.Simulation.ProcessedNavigation): Graph.NetworkNode|null {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n return null;\n }\n\n const lcpEvent = processedNavigation.largestContentfulPaintEvt;\n if (lcpEvent?.args?.data?.type && lcpEvent.args.data.type !== 'image') {\n return null;\n }\n\n const {lcpRequestId, lcpImageUrl} = processedNavigation;\n if (!lcpRequestId && !lcpImageUrl) {\n return null;\n }\n\n if (lcpRequestId) {\n const idMatches: Graph.NetworkNode[] = [];\n dependencyGraph.traverse(node => {\n if (node.type !== 'network' || node.request.redirectDestination) {\n return;\n }\n if (node.request.finished === false || node.endTime < 0 || node.startTime > lcp) {\n return;\n }\n const baseRequestId = node.request.requestId.replace(/(:redirect|:duplicate)+$/, '');\n if (baseRequestId === lcpRequestId) {\n idMatches.push(node);\n }\n });\n if (idMatches.length) {\n idMatches.sort((a, b) => a.endTime - b.endTime);\n return idMatches[0];\n }\n }\n\n if (!lcpImageUrl) {\n return null;\n }\n\n const normalizedLcpUrl = stripUrlHash(lcpImageUrl);\n const lcpFrameId = lcpEvent?.args?.frame;\n const urlMatches: Graph.NetworkNode[] = [];\n dependencyGraph.traverse(node => {\n if (node.type !== 'network' || node.request.redirectDestination) {\n return;\n }\n if (node.request.finished === false || node.endTime < 0 || node.startTime > lcp) {\n return;\n }\n if (lcpFrameId && node.request.frameId && node.request.frameId !== lcpFrameId) {\n return;\n }\n if (node.request.resourceType && node.request.resourceType !== 'Image' && node.request.resourceType !== 'Media') {\n return;\n }\n const matchesUrl = node.request.url === lcpImageUrl || stripUrlHash(node.request.url) === normalizedLcpUrl ||\n Boolean(node.request.redirects?.some(r => r.url === lcpImageUrl || stripUrlHash(r.url) === normalizedLcpUrl));\n if (matchesUrl) {\n urlMatches.push(node);\n }\n });\n\n if (!urlMatches.length) {\n return null;\n }\n urlMatches.sort((a, b) => a.endTime - b.endTime);\n return urlMatches[0];\n }\n\n static isSameFrameTextLcp(processedNavigation: Types.Simulation.ProcessedNavigation): boolean {\n const {firstContentfulPaint: fcp, largestContentfulPaint: lcp} = processedNavigation.timestamps;\n if (!lcp) {\n return false;\n }\n return Math.abs(lcp - fcp) <= SAME_FRAME_TIMESTAMP_TOLERANCE_US &&\n processedNavigation.largestContentfulPaintEvt?.args?.data?.type === 'text';\n }\n\n static override getOptimisticGraph(\n dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n throw new Core.LanternError('NO_LCP');\n }\n if (LargestContentfulPaint.isSameFrameTextLcp(processedNavigation)) {\n return FirstContentfulPaint.getOptimisticGraph(dependencyGraph, processedNavigation);\n }\n\n const lcpNode = LargestContentfulPaint.findLcpNode(dependencyGraph, processedNavigation);\n if (lcpNode) {\n const fcpOptimisticGraph = FirstContentfulPaint.getOptimisticGraph(dependencyGraph, processedNavigation);\n const criticalNodeIds = new Set<string>();\n fcpOptimisticGraph.traverse(node => criticalNodeIds.add(node.id));\n criticalNodeIds.add(lcpNode.id);\n\n // PageDependencyGraph.linkCPUNodes does not add CPUNode -> Image edges, so if the LCP image\n // has any Script dependencies (e.g. JS-injected hero image or JS-injected stylesheet),\n // include the CPU tasks that evaluated those scripts prior to the LCP request.\n const initiatorScriptUrls = new Set<string>();\n lcpNode.traverse(node => {\n if (node.type === 'network' && node.request.resourceType === 'Script') {\n initiatorScriptUrls.add(node.request.url);\n }\n }, node => node.getDependencies());\n\n if (initiatorScriptUrls.size) {\n dependencyGraph.traverse(node => {\n if (node.type !== 'cpu' || node.startTime > lcpNode.startTime) {\n return;\n }\n for (const url of node.getEvaluateScriptURLs()) {\n if (initiatorScriptUrls.has(url)) {\n criticalNodeIds.add(node.id);\n break;\n }\n }\n });\n }\n\n return dependencyGraph.cloneWithRelationships(node => criticalNodeIds.has(node.id));\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,\n });\n }\n\n static override getPessimisticGraph(\n dependencyGraph: Graph.Node, processedNavigation: Types.Simulation.ProcessedNavigation): Graph.Node {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n throw new Core.LanternError('NO_LCP');\n }\n if (LargestContentfulPaint.isSameFrameTextLcp(processedNavigation)) {\n return FirstContentfulPaint.getPessimisticGraph(dependencyGraph, processedNavigation);\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: _ => true,\n // For pessimistic LCP we'll include *all* layout nodes\n additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),\n });\n }\n\n static override getEstimateFromSimulation(simulationResult: Simulation.Result, extras?: Extras): Simulation.Result {\n if (extras?.optimistic) {\n return simulationResult;\n }\n\n const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())\n .filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))\n .map(entry => entry[1].endTime);\n\n return {\n timeInMs: Math.max(...nodeTimesNotOffscreenImages),\n nodeTimings: simulationResult.nodeTimings,\n };\n }\n\n static override compute(data: MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): MetricResult {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Core.LanternError('FCP is required to calculate the LCP metric');\n }\n\n const metricResult = super.compute(data, extras);\n metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);\n return metricResult;\n }\n}\n\nexport {LargestContentfulPaint};\n"]}
|
|
@@ -73,6 +73,10 @@ declare class Simulator<T = Lantern.AnyNetworkObject> {
|
|
|
73
73
|
label?: string;
|
|
74
74
|
}): Result<T>;
|
|
75
75
|
computeWastedMsFromWastedBytes(wastedBytes: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* Lighthouse's asset-saver reads this map. TraceProcessor clears it after
|
|
78
|
+
* every parse and on reset() so it does not retain the Lantern dependency graph.
|
|
79
|
+
*/
|
|
76
80
|
static get allNodeTimings(): Map<string, Map<Graph.Node, CompleteNodeTiming>>;
|
|
77
81
|
/**
|
|
78
82
|
* We attempt to start nodes by their observed start time using the request priority as a tie breaker.
|
|
@@ -441,7 +441,10 @@ class Simulator {
|
|
|
441
441
|
// This is an estimate of wasted time, so we won't be more precise than 10ms.
|
|
442
442
|
return Math.round(wastedMs / 10) * 10;
|
|
443
443
|
}
|
|
444
|
-
|
|
444
|
+
/**
|
|
445
|
+
* Lighthouse's asset-saver reads this map. TraceProcessor clears it after
|
|
446
|
+
* every parse and on reset() so it does not retain the Lantern dependency graph.
|
|
447
|
+
*/
|
|
445
448
|
static get allNodeTimings() {
|
|
446
449
|
return ALL_SIMULATION_NODE_TIMINGS;
|
|
447
450
|
}
|