lighthouse 12.0.0-dev.20240609 → 12.0.0-dev.20240611
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/core/audits/long-tasks.d.ts +7 -6
- package/core/audits/long-tasks.js +5 -4
- package/core/computed/metrics/lantern-metric.js +2 -2
- package/core/computed/metrics/lantern-speed-index.js +1 -1
- package/core/computed/metrics/total-blocking-time.js +1 -1
- package/core/computed/navigation-insights.d.ts +2 -22
- package/core/computed/page-dependency-graph.js +5 -2
- package/core/computed/processed-navigation.d.ts +1 -1
- package/core/computed/tbt-impact-tasks.js +3 -2
- package/core/computed/trace-engine-result.d.ts +0 -12
- package/core/computed/trace-engine-result.js +5 -20
- package/core/config/constants.d.ts +28 -53
- package/core/config/constants.js +2 -43
- package/core/gather/driver/target-manager.d.ts +1 -1
- package/core/gather/gatherers/root-causes.js +0 -1
- package/core/gather/session.d.ts +3 -3
- package/core/lib/lantern/cpu-node.d.ts +10 -10
- package/core/lib/lantern/cpu-node.js +5 -5
- package/core/lib/lantern/lantern.d.ts +48 -11
- package/core/lib/lantern/lantern.js +40 -43
- package/core/lib/lantern/metric.d.ts +10 -12
- package/core/lib/lantern/metric.js +7 -7
- package/core/lib/lantern/metrics/interactive.d.ts +3 -8
- package/core/lib/lantern/metrics/interactive.js +5 -5
- package/core/lib/lantern/metrics/largest-contentful-paint.d.ts +4 -3
- package/core/lib/lantern/metrics/largest-contentful-paint.js +4 -4
- package/core/lib/lantern/metrics/max-potential-fid.d.ts +3 -8
- package/core/lib/lantern/metrics/max-potential-fid.js +5 -5
- package/core/lib/lantern/metrics/speed-index.d.ts +3 -8
- package/core/lib/lantern/metrics/speed-index.js +8 -8
- package/core/lib/lantern/metrics/total-blocking-time.d.ts +3 -8
- package/core/lib/lantern/metrics/total-blocking-time.js +6 -6
- package/core/lib/lantern/page-dependency-graph.d.ts +17 -49
- package/core/lib/lantern/page-dependency-graph.js +45 -354
- package/core/lib/lantern/simulator/network-analyzer.d.ts +6 -6
- package/core/lib/lantern/simulator/network-analyzer.js +2 -2
- package/core/lib/lantern/simulator/simulator.js +6 -6
- package/core/lib/lantern/trace-engine-computation-data.d.ts +25 -0
- package/core/lib/lantern/trace-engine-computation-data.js +468 -0
- package/core/lib/lantern/types/lantern.d.ts +77 -5
- package/core/lib/lantern-trace-saver.js +1 -1
- package/package.json +8 -8
- package/types/artifacts.d.ts +4 -11
- /package/core/{computed/metrics → lib/lantern}/tbt-utils.d.ts +0 -0
- /package/core/{computed/metrics → lib/lantern}/tbt-utils.js +0 -0
|
@@ -8,12 +8,18 @@ import * as Lantern from './types/lantern.js';
|
|
|
8
8
|
import {NetworkRequestTypes} from './lantern.js';
|
|
9
9
|
import {NetworkNode} from './network-node.js';
|
|
10
10
|
import {CPUNode} from './cpu-node.js';
|
|
11
|
-
import {TraceProcessor} from '../tracehouse/trace-processor.js';
|
|
12
11
|
import {NetworkAnalyzer} from './simulator/network-analyzer.js';
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
// COMPAT: m71+ We added RunTask to `disabled-by-default-lighthouse`
|
|
14
|
+
const SCHEDULABLE_TASK_TITLE_LH = 'RunTask';
|
|
15
|
+
// m69-70 DoWork is different and we now need RunTask, see https://bugs.chromium.org/p/chromium/issues/detail?id=871204#c11
|
|
16
|
+
const SCHEDULABLE_TASK_TITLE_ALT1 = 'ThreadControllerImpl::RunTask';
|
|
17
|
+
// In m66-68 refactored to this task title, https://crrev.com/c/883346
|
|
18
|
+
const SCHEDULABLE_TASK_TITLE_ALT2 = 'ThreadControllerImpl::DoWork';
|
|
19
|
+
// m65 and earlier
|
|
20
|
+
const SCHEDULABLE_TASK_TITLE_ALT3 = 'TaskQueueManager::ProcessTaskFromWorkQueue';
|
|
14
21
|
|
|
15
22
|
/** @typedef {import('./base-node.js').Node} Node */
|
|
16
|
-
/** @typedef {Omit<LH.Artifacts['URL'], 'finalDisplayedUrl'>} URLArtifact */
|
|
17
23
|
|
|
18
24
|
/**
|
|
19
25
|
* @typedef {Object} NetworkNodeOutput
|
|
@@ -110,7 +116,31 @@ class PageDependencyGraph {
|
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
/**
|
|
113
|
-
* @param {
|
|
119
|
+
* @param {Lantern.TraceEvent} evt
|
|
120
|
+
* @return {boolean}
|
|
121
|
+
*/
|
|
122
|
+
static isScheduleableTask(evt) {
|
|
123
|
+
return evt.name === SCHEDULABLE_TASK_TITLE_LH ||
|
|
124
|
+
evt.name === SCHEDULABLE_TASK_TITLE_ALT1 ||
|
|
125
|
+
evt.name === SCHEDULABLE_TASK_TITLE_ALT2 ||
|
|
126
|
+
evt.name === SCHEDULABLE_TASK_TITLE_ALT3;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* There should *always* be at least one top level event, having 0 typically means something is
|
|
131
|
+
* drastically wrong with the trace and we should just give up early and loudly.
|
|
132
|
+
*
|
|
133
|
+
* @param {Lantern.TraceEvent[]} events
|
|
134
|
+
*/
|
|
135
|
+
static assertHasToplevelEvents(events) {
|
|
136
|
+
const hasToplevelTask = events.some(this.isScheduleableTask);
|
|
137
|
+
if (!hasToplevelTask) {
|
|
138
|
+
throw new Error('Could not find any top level events');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {Lantern.TraceEvent[]} mainThreadEvents
|
|
114
144
|
* @return {Array<CPUNode>}
|
|
115
145
|
*/
|
|
116
146
|
static getCPUNodes(mainThreadEvents) {
|
|
@@ -118,14 +148,14 @@ class PageDependencyGraph {
|
|
|
118
148
|
const nodes = [];
|
|
119
149
|
let i = 0;
|
|
120
150
|
|
|
121
|
-
|
|
151
|
+
PageDependencyGraph.assertHasToplevelEvents(mainThreadEvents);
|
|
122
152
|
|
|
123
153
|
while (i < mainThreadEvents.length) {
|
|
124
154
|
const evt = mainThreadEvents[i];
|
|
125
155
|
i++;
|
|
126
156
|
|
|
127
157
|
// Skip all trace events that aren't schedulable tasks with sizable duration
|
|
128
|
-
if (!
|
|
158
|
+
if (!PageDependencyGraph.isScheduleableTask(evt) || !evt.dur) {
|
|
129
159
|
continue;
|
|
130
160
|
}
|
|
131
161
|
|
|
@@ -133,23 +163,25 @@ class PageDependencyGraph {
|
|
|
133
163
|
let correctedEndTs = undefined;
|
|
134
164
|
|
|
135
165
|
// Capture all events that occurred within the task
|
|
136
|
-
/** @type {Array<
|
|
166
|
+
/** @type {Array<Lantern.TraceEvent>} */
|
|
137
167
|
const children = [];
|
|
138
168
|
for (
|
|
139
169
|
const endTime = evt.ts + evt.dur;
|
|
140
170
|
i < mainThreadEvents.length && mainThreadEvents[i].ts < endTime;
|
|
141
171
|
i++
|
|
142
172
|
) {
|
|
173
|
+
const event = mainThreadEvents[i];
|
|
174
|
+
|
|
143
175
|
// Temporary fix for a Chrome bug where some RunTask events can be overlapping.
|
|
144
176
|
// We correct that here be ensuring each RunTask ends at least 1 microsecond before the next
|
|
145
177
|
// https://github.com/GoogleChrome/lighthouse/issues/15896
|
|
146
178
|
// https://issues.chromium.org/issues/329678173
|
|
147
|
-
if (
|
|
148
|
-
correctedEndTs =
|
|
179
|
+
if (PageDependencyGraph.isScheduleableTask(event) && event.dur) {
|
|
180
|
+
correctedEndTs = event.ts - 1;
|
|
149
181
|
break;
|
|
150
182
|
}
|
|
151
183
|
|
|
152
|
-
children.push(
|
|
184
|
+
children.push(event);
|
|
153
185
|
}
|
|
154
186
|
|
|
155
187
|
nodes.push(new CPUNode(evt, children, correctedEndTs));
|
|
@@ -211,7 +243,7 @@ class PageDependencyGraph {
|
|
|
211
243
|
* @param {Array<CPUNode>} cpuNodes
|
|
212
244
|
*/
|
|
213
245
|
static linkCPUNodes(rootNode, networkNodeOutput, cpuNodes) {
|
|
214
|
-
/** @type {Set<
|
|
246
|
+
/** @type {Set<Lantern.ResourceType|undefined>} */
|
|
215
247
|
const linkableResourceTypes = new Set([
|
|
216
248
|
NetworkRequestTypes.XHR, NetworkRequestTypes.Fetch, NetworkRequestTypes.Script,
|
|
217
249
|
]);
|
|
@@ -507,9 +539,9 @@ class PageDependencyGraph {
|
|
|
507
539
|
}
|
|
508
540
|
|
|
509
541
|
/**
|
|
510
|
-
* @param {
|
|
542
|
+
* @param {Lantern.TraceEvent[]} mainThreadEvents
|
|
511
543
|
* @param {Lantern.NetworkRequest[]} networkRequests
|
|
512
|
-
* @param {
|
|
544
|
+
* @param {Lantern.Simulation.URL} URL
|
|
513
545
|
* @return {Node}
|
|
514
546
|
*/
|
|
515
547
|
static createGraph(mainThreadEvents, networkRequests, URL) {
|
|
@@ -543,347 +575,6 @@ class PageDependencyGraph {
|
|
|
543
575
|
}
|
|
544
576
|
|
|
545
577
|
/**
|
|
546
|
-
* @param {Lantern.NetworkRequest} request The request to find the initiator of
|
|
547
|
-
* @param {Map<string, Lantern.NetworkRequest[]>} requestsByURL
|
|
548
|
-
* @return {Lantern.NetworkRequest|null}
|
|
549
|
-
*/
|
|
550
|
-
static chooseInitiatorRequest(request, requestsByURL) {
|
|
551
|
-
if (request.redirectSource) {
|
|
552
|
-
return request.redirectSource;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const initiatorURL = PageDependencyGraph.getNetworkInitiators(request)[0];
|
|
556
|
-
let candidates = requestsByURL.get(initiatorURL) || [];
|
|
557
|
-
// The (valid) initiator must come before the initiated request.
|
|
558
|
-
candidates = candidates.filter(c => {
|
|
559
|
-
return c.responseHeadersEndTime <= request.rendererStartTime &&
|
|
560
|
-
c.finished && !c.failed;
|
|
561
|
-
});
|
|
562
|
-
if (candidates.length > 1) {
|
|
563
|
-
// Disambiguate based on prefetch. Prefetch requests have type 'Other' and cannot
|
|
564
|
-
// initiate requests, so we drop them here.
|
|
565
|
-
const nonPrefetchCandidates = candidates.filter(
|
|
566
|
-
cand => cand.resourceType !== RESOURCE_TYPES.Other);
|
|
567
|
-
if (nonPrefetchCandidates.length) {
|
|
568
|
-
candidates = nonPrefetchCandidates;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
if (candidates.length > 1) {
|
|
572
|
-
// Disambiguate based on frame. It's likely that the initiator comes from the same frame.
|
|
573
|
-
const sameFrameCandidates = candidates.filter(cand => cand.frameId === request.frameId);
|
|
574
|
-
if (sameFrameCandidates.length) {
|
|
575
|
-
candidates = sameFrameCandidates;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
if (candidates.length > 1 && request.initiator.type === 'parser') {
|
|
579
|
-
// Filter to just Documents when initiator type is parser.
|
|
580
|
-
const documentCandidates = candidates.filter(cand =>
|
|
581
|
-
cand.resourceType === RESOURCE_TYPES.Document);
|
|
582
|
-
if (documentCandidates.length) {
|
|
583
|
-
candidates = documentCandidates;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
if (candidates.length > 1) {
|
|
587
|
-
// If all real loads came from successful preloads (url preloaded and
|
|
588
|
-
// loads came from the cache), filter to link rel=preload request(s).
|
|
589
|
-
const linkPreloadCandidates = candidates.filter(c => c.isLinkPreload);
|
|
590
|
-
if (linkPreloadCandidates.length) {
|
|
591
|
-
const nonPreloadCandidates = candidates.filter(c => !c.isLinkPreload);
|
|
592
|
-
const allPreloaded = nonPreloadCandidates.every(c => c.fromDiskCache || c.fromMemoryCache);
|
|
593
|
-
if (nonPreloadCandidates.length && allPreloaded) {
|
|
594
|
-
candidates = linkPreloadCandidates;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Only return an initiator if the result is unambiguous.
|
|
600
|
-
return candidates.length === 1 ? candidates[0] : null;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
* Returns a map of `pid` -> `tid[]`.
|
|
605
|
-
* @param {LH.Trace} trace
|
|
606
|
-
* @return {Map<number, number[]>}
|
|
607
|
-
*/
|
|
608
|
-
static _findWorkerThreads(trace) {
|
|
609
|
-
// TODO: WorkersHandler in TraceEngine needs to be updated to also include `pid` (only had `tid`).
|
|
610
|
-
const workerThreads = new Map();
|
|
611
|
-
const workerCreationEvents = ['ServiceWorker thread', 'DedicatedWorker thread'];
|
|
612
|
-
|
|
613
|
-
for (const event of trace.traceEvents) {
|
|
614
|
-
if (event.name !== 'thread_name' || !event.args.name) {
|
|
615
|
-
continue;
|
|
616
|
-
}
|
|
617
|
-
if (!workerCreationEvents.includes(event.args.name)) {
|
|
618
|
-
continue;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
const tids = workerThreads.get(event.pid);
|
|
622
|
-
if (tids) {
|
|
623
|
-
tids.push(event.tid);
|
|
624
|
-
} else {
|
|
625
|
-
workerThreads.set(event.pid, [event.tid]);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
return workerThreads;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* @param {URL|string} url
|
|
634
|
-
*/
|
|
635
|
-
static _createParsedUrl(url) {
|
|
636
|
-
if (typeof url === 'string') {
|
|
637
|
-
url = new URL(url);
|
|
638
|
-
}
|
|
639
|
-
return {
|
|
640
|
-
scheme: url.protocol.split(':')[0],
|
|
641
|
-
// Intentional, DevTools uses different terminology
|
|
642
|
-
host: url.hostname,
|
|
643
|
-
securityOrigin: url.origin,
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* @param {LH.Artifacts.TraceEngineResult} traceEngineResult
|
|
649
|
-
* @param {Map<number, number[]>} workerThreads
|
|
650
|
-
* @param {import('@paulirish/trace_engine/models/trace/types/TraceEvents.js').SyntheticNetworkRequest} request
|
|
651
|
-
* @return {Lantern.NetworkRequest=}
|
|
652
|
-
*/
|
|
653
|
-
static _createLanternRequest(traceEngineResult, workerThreads, request) {
|
|
654
|
-
if (request.args.data.connectionId === undefined ||
|
|
655
|
-
request.args.data.connectionReused === undefined) {
|
|
656
|
-
throw new Error('Trace is too old');
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
let url;
|
|
660
|
-
try {
|
|
661
|
-
url = new URL(request.args.data.url);
|
|
662
|
-
} catch (e) {
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
const timing = request.args.data.timing ? {
|
|
667
|
-
// These two timings are not included in the trace.
|
|
668
|
-
workerFetchStart: -1,
|
|
669
|
-
workerRespondWithSettled: -1,
|
|
670
|
-
...request.args.data.timing,
|
|
671
|
-
} : undefined;
|
|
672
|
-
|
|
673
|
-
const networkRequestTime = timing ?
|
|
674
|
-
timing.requestTime * 1000 :
|
|
675
|
-
request.args.data.syntheticData.downloadStart / 1000;
|
|
676
|
-
|
|
677
|
-
let fromWorker = false;
|
|
678
|
-
const tids = workerThreads.get(request.pid);
|
|
679
|
-
if (tids?.includes(request.tid)) {
|
|
680
|
-
fromWorker = true;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
// TraceEngine collects worker thread ids in a different manner than `workerThreads` does.
|
|
684
|
-
// AFAIK these should be equivalent, but in case they are not let's also check this for now.
|
|
685
|
-
if (traceEngineResult.data.Workers.workerIdByThread.has(request.tid)) {
|
|
686
|
-
fromWorker = true;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
// `initiator` in the trace does not contain the stack trace for JS-initiated
|
|
690
|
-
// requests. Instead, that is stored in the `stackTrace` property of the SyntheticNetworkRequest.
|
|
691
|
-
// There are some minor differences in the fields, accounted for here.
|
|
692
|
-
// Most importantly, there seems to be fewer frames in the trace than the equivalent
|
|
693
|
-
// events over the CDP. This results in less accuracy in determining the initiator request,
|
|
694
|
-
// which means less edges in the graph, which mean worse results.
|
|
695
|
-
// TODO: Should fix in Chromium.
|
|
696
|
-
/** @type {Lantern.NetworkRequest['initiator']} */
|
|
697
|
-
const initiator = request.args.data.initiator ?? {type: 'other'};
|
|
698
|
-
if (request.args.data.stackTrace) {
|
|
699
|
-
const callFrames = request.args.data.stackTrace.map(f => {
|
|
700
|
-
return {
|
|
701
|
-
scriptId: String(f.scriptId),
|
|
702
|
-
url: f.url,
|
|
703
|
-
lineNumber: f.lineNumber - 1,
|
|
704
|
-
columnNumber: f.columnNumber - 1,
|
|
705
|
-
functionName: f.functionName,
|
|
706
|
-
};
|
|
707
|
-
});
|
|
708
|
-
initiator.stack = {callFrames};
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
let resourceType = request.args.data.resourceType;
|
|
712
|
-
if (request.args.data.initiator?.fetchType === 'xmlhttprequest') {
|
|
713
|
-
// @ts-expect-error yes XHR is a valid ResourceType. TypeScript const enums are so unhelpful.
|
|
714
|
-
resourceType = 'XHR';
|
|
715
|
-
} else if (request.args.data.initiator?.fetchType === 'fetch') {
|
|
716
|
-
// @ts-expect-error yes Fetch is a valid ResourceType. TypeScript const enums are so unhelpful.
|
|
717
|
-
resourceType = 'Fetch';
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
// TODO: set decodedBodyLength for data urls in Trace Engine.
|
|
721
|
-
let resourceSize = request.args.data.decodedBodyLength ?? 0;
|
|
722
|
-
if (url.protocol === 'data:' && resourceSize === 0) {
|
|
723
|
-
const needle = 'base64,';
|
|
724
|
-
const index = url.pathname.indexOf(needle);
|
|
725
|
-
if (index !== -1) {
|
|
726
|
-
resourceSize = atob(url.pathname.substring(index + needle.length)).length;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
return {
|
|
731
|
-
rawRequest: request,
|
|
732
|
-
requestId: request.args.data.requestId,
|
|
733
|
-
connectionId: request.args.data.connectionId,
|
|
734
|
-
connectionReused: request.args.data.connectionReused,
|
|
735
|
-
url: request.args.data.url,
|
|
736
|
-
protocol: request.args.data.protocol,
|
|
737
|
-
parsedURL: this._createParsedUrl(url),
|
|
738
|
-
documentURL: request.args.data.requestingFrameUrl,
|
|
739
|
-
rendererStartTime: request.ts / 1000,
|
|
740
|
-
networkRequestTime,
|
|
741
|
-
responseHeadersEndTime: request.args.data.syntheticData.downloadStart / 1000,
|
|
742
|
-
networkEndTime: request.args.data.syntheticData.finishTime / 1000,
|
|
743
|
-
transferSize: request.args.data.encodedDataLength,
|
|
744
|
-
resourceSize,
|
|
745
|
-
fromDiskCache: request.args.data.syntheticData.isDiskCached,
|
|
746
|
-
fromMemoryCache: request.args.data.syntheticData.isMemoryCached,
|
|
747
|
-
isLinkPreload: request.args.data.isLinkPreload,
|
|
748
|
-
finished: request.args.data.finished,
|
|
749
|
-
failed: request.args.data.failed,
|
|
750
|
-
statusCode: request.args.data.statusCode,
|
|
751
|
-
initiator,
|
|
752
|
-
timing,
|
|
753
|
-
resourceType,
|
|
754
|
-
mimeType: request.args.data.mimeType,
|
|
755
|
-
priority: request.args.data.priority,
|
|
756
|
-
frameId: request.args.data.frame,
|
|
757
|
-
fromWorker,
|
|
758
|
-
// Set later.
|
|
759
|
-
redirects: undefined,
|
|
760
|
-
redirectSource: undefined,
|
|
761
|
-
redirectDestination: undefined,
|
|
762
|
-
initiatorRequest: undefined,
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
*
|
|
768
|
-
* @param {Lantern.NetworkRequest[]} lanternRequests
|
|
769
|
-
*/
|
|
770
|
-
static _linkInitiators(lanternRequests) {
|
|
771
|
-
/** @type {Map<string, Lantern.NetworkRequest[]>} */
|
|
772
|
-
const requestsByURL = new Map();
|
|
773
|
-
for (const request of lanternRequests) {
|
|
774
|
-
const requests = requestsByURL.get(request.url) || [];
|
|
775
|
-
requests.push(request);
|
|
776
|
-
requestsByURL.set(request.url, requests);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
for (const request of lanternRequests) {
|
|
780
|
-
const initiatorRequest = PageDependencyGraph.chooseInitiatorRequest(request, requestsByURL);
|
|
781
|
-
if (initiatorRequest) {
|
|
782
|
-
request.initiatorRequest = initiatorRequest;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* @param {LH.TraceEvent[]} mainThreadEvents
|
|
789
|
-
* @param {LH.Trace} trace
|
|
790
|
-
* @param {LH.Artifacts.TraceEngineResult} traceEngineResult
|
|
791
|
-
* @param {LH.Artifacts.URL} URL
|
|
792
|
-
*/
|
|
793
|
-
static async createGraphFromTrace(mainThreadEvents, trace, traceEngineResult, URL) {
|
|
794
|
-
const workerThreads = this._findWorkerThreads(trace);
|
|
795
|
-
|
|
796
|
-
/** @type {Lantern.NetworkRequest[]} */
|
|
797
|
-
const lanternRequests = [];
|
|
798
|
-
for (const request of traceEngineResult.data.NetworkRequests.byTime) {
|
|
799
|
-
const lanternRequest = this._createLanternRequest(traceEngineResult, workerThreads, request);
|
|
800
|
-
if (lanternRequest) {
|
|
801
|
-
lanternRequests.push(lanternRequest);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
// TraceEngine consolidates all redirects into a single request object, but lantern needs
|
|
806
|
-
// an entry for each redirected request.
|
|
807
|
-
for (const request of [...lanternRequests]) {
|
|
808
|
-
if (!request.rawRequest) continue;
|
|
809
|
-
|
|
810
|
-
const redirects = request.rawRequest.args.data.redirects;
|
|
811
|
-
if (!redirects.length) continue;
|
|
812
|
-
|
|
813
|
-
const requestChain = [];
|
|
814
|
-
for (const redirect of redirects) {
|
|
815
|
-
const redirectedRequest = structuredClone(request);
|
|
816
|
-
|
|
817
|
-
redirectedRequest.networkRequestTime = redirect.ts / 1000;
|
|
818
|
-
redirectedRequest.rendererStartTime = redirectedRequest.networkRequestTime;
|
|
819
|
-
|
|
820
|
-
redirectedRequest.networkEndTime = (redirect.ts + redirect.dur) / 1000;
|
|
821
|
-
redirectedRequest.responseHeadersEndTime = redirectedRequest.networkEndTime;
|
|
822
|
-
|
|
823
|
-
redirectedRequest.timing = {
|
|
824
|
-
requestTime: redirectedRequest.networkRequestTime / 1000,
|
|
825
|
-
receiveHeadersStart: redirectedRequest.responseHeadersEndTime,
|
|
826
|
-
receiveHeadersEnd: redirectedRequest.responseHeadersEndTime,
|
|
827
|
-
proxyStart: -1,
|
|
828
|
-
proxyEnd: -1,
|
|
829
|
-
dnsStart: -1,
|
|
830
|
-
dnsEnd: -1,
|
|
831
|
-
connectStart: -1,
|
|
832
|
-
connectEnd: -1,
|
|
833
|
-
sslStart: -1,
|
|
834
|
-
sslEnd: -1,
|
|
835
|
-
sendStart: -1,
|
|
836
|
-
sendEnd: -1,
|
|
837
|
-
workerStart: -1,
|
|
838
|
-
workerReady: -1,
|
|
839
|
-
workerFetchStart: -1,
|
|
840
|
-
workerRespondWithSettled: -1,
|
|
841
|
-
pushStart: -1,
|
|
842
|
-
pushEnd: -1,
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
redirectedRequest.url = redirect.url;
|
|
846
|
-
redirectedRequest.parsedURL = this._createParsedUrl(redirect.url);
|
|
847
|
-
// TODO: TraceEngine is not retaining the actual status code.
|
|
848
|
-
redirectedRequest.statusCode = 302;
|
|
849
|
-
redirectedRequest.resourceType = undefined;
|
|
850
|
-
// TODO: TraceEngine is not retaining transfer size of redirected request.
|
|
851
|
-
redirectedRequest.transferSize = 400;
|
|
852
|
-
requestChain.push(redirectedRequest);
|
|
853
|
-
lanternRequests.push(redirectedRequest);
|
|
854
|
-
}
|
|
855
|
-
requestChain.push(request);
|
|
856
|
-
|
|
857
|
-
for (let i = 0; i < requestChain.length; i++) {
|
|
858
|
-
const request = requestChain[i];
|
|
859
|
-
if (i > 0) {
|
|
860
|
-
request.redirectSource = requestChain[i - 1];
|
|
861
|
-
request.redirects = requestChain.slice(0, i);
|
|
862
|
-
}
|
|
863
|
-
if (i !== requestChain.length - 1) {
|
|
864
|
-
request.redirectDestination = requestChain[i + 1];
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// Apply the `:redirect` requestId convention: only redirects[0].requestId is the actual
|
|
869
|
-
// requestId, all the rest have n occurences of `:redirect` as a suffix.
|
|
870
|
-
for (let i = 1; i < requestChain.length; i++) {
|
|
871
|
-
requestChain[i].requestId = `${requestChain[i - 1].requestId}:redirect`;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
this._linkInitiators(lanternRequests);
|
|
876
|
-
|
|
877
|
-
// This would already be sorted by rendererStartTime, if not for the redirect unwrapping done
|
|
878
|
-
// above.
|
|
879
|
-
lanternRequests.sort((a, b) => a.rendererStartTime - b.rendererStartTime);
|
|
880
|
-
|
|
881
|
-
const graph = PageDependencyGraph.createGraph(mainThreadEvents, lanternRequests, URL);
|
|
882
|
-
return {graph, records: lanternRequests};
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
/**
|
|
886
|
-
*
|
|
887
578
|
* @param {Node} rootNode
|
|
888
579
|
*/
|
|
889
580
|
static printGraph(rootNode, widthInCharacters = 100) {
|
|
@@ -46,7 +46,7 @@ export class NetworkAnalyzer {
|
|
|
46
46
|
* @return {Map<string, Summary>}
|
|
47
47
|
*/
|
|
48
48
|
static summarize(values: Map<string, number[]>): Map<string, Summary>;
|
|
49
|
-
/** @typedef {{request: Lantern.NetworkRequest, timing:
|
|
49
|
+
/** @typedef {{request: Lantern.NetworkRequest, timing: Lantern.ResourceTiming, connectionReused?: boolean}} RequestInfo */
|
|
50
50
|
/**
|
|
51
51
|
* @param {Lantern.NetworkRequest[]} requests
|
|
52
52
|
* @param {(e: RequestInfo) => number | number[] | undefined} iteratee
|
|
@@ -54,7 +54,7 @@ export class NetworkAnalyzer {
|
|
|
54
54
|
*/
|
|
55
55
|
static _estimateValueByOrigin(requests: Lantern.NetworkRequest[], iteratee: (e: {
|
|
56
56
|
request: Lantern.NetworkRequest;
|
|
57
|
-
timing:
|
|
57
|
+
timing: Lantern.ResourceTiming;
|
|
58
58
|
connectionReused?: boolean | undefined;
|
|
59
59
|
}) => number | number[] | undefined): Map<string, number[]>;
|
|
60
60
|
/**
|
|
@@ -70,7 +70,7 @@ export class NetworkAnalyzer {
|
|
|
70
70
|
*/
|
|
71
71
|
static _estimateRTTViaConnectionTiming(info: {
|
|
72
72
|
request: Lantern.NetworkRequest;
|
|
73
|
-
timing:
|
|
73
|
+
timing: Lantern.ResourceTiming;
|
|
74
74
|
connectionReused?: boolean | undefined;
|
|
75
75
|
}): number[] | number | undefined;
|
|
76
76
|
/**
|
|
@@ -83,7 +83,7 @@ export class NetworkAnalyzer {
|
|
|
83
83
|
*/
|
|
84
84
|
static _estimateRTTViaDownloadTiming(info: {
|
|
85
85
|
request: Lantern.NetworkRequest;
|
|
86
|
-
timing:
|
|
86
|
+
timing: Lantern.ResourceTiming;
|
|
87
87
|
connectionReused?: boolean | undefined;
|
|
88
88
|
}): number | undefined;
|
|
89
89
|
/**
|
|
@@ -97,7 +97,7 @@ export class NetworkAnalyzer {
|
|
|
97
97
|
*/
|
|
98
98
|
static _estimateRTTViaSendStartTiming(info: {
|
|
99
99
|
request: Lantern.NetworkRequest;
|
|
100
|
-
timing:
|
|
100
|
+
timing: Lantern.ResourceTiming;
|
|
101
101
|
connectionReused?: boolean | undefined;
|
|
102
102
|
}): number | undefined;
|
|
103
103
|
/**
|
|
@@ -111,7 +111,7 @@ export class NetworkAnalyzer {
|
|
|
111
111
|
*/
|
|
112
112
|
static _estimateRTTViaHeadersEndTiming(info: {
|
|
113
113
|
request: Lantern.NetworkRequest;
|
|
114
|
-
timing:
|
|
114
|
+
timing: Lantern.ResourceTiming;
|
|
115
115
|
connectionReused?: boolean | undefined;
|
|
116
116
|
}): number | undefined;
|
|
117
117
|
/**
|
|
@@ -15,7 +15,7 @@ const DEFAULT_SERVER_RESPONSE_PERCENTAGE = 0.4;
|
|
|
15
15
|
/**
|
|
16
16
|
* For certain resource types, server response time takes up a greater percentage of TTFB (dynamic
|
|
17
17
|
* assets like HTML documents, XHR/API calls, etc)
|
|
18
|
-
* @type {Partial<Record<
|
|
18
|
+
* @type {Partial<Record<Lantern.ResourceType, number>>}
|
|
19
19
|
*/
|
|
20
20
|
const SERVER_RESPONSE_PERCENTAGE_OF_TTFB = {
|
|
21
21
|
Document: 0.9,
|
|
@@ -88,7 +88,7 @@ class NetworkAnalyzer {
|
|
|
88
88
|
return summaryByKey;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
/** @typedef {{request: Lantern.NetworkRequest, timing:
|
|
91
|
+
/** @typedef {{request: Lantern.NetworkRequest, timing: Lantern.ResourceTiming, connectionReused?: boolean}} RequestInfo */
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
94
|
* @param {Lantern.NetworkRequest[]} requests
|
|
@@ -10,9 +10,9 @@ import {TcpConnection} from './tcp-connection.js';
|
|
|
10
10
|
import {ConnectionPool} from './connection-pool.js';
|
|
11
11
|
import {DNSCache} from './dns-cache.js';
|
|
12
12
|
import {SimulatorTimingMap} from './simulator-timing-map.js';
|
|
13
|
-
import
|
|
13
|
+
import {constants} from '../lantern.js';
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const defaultThrottling = constants.throttling.mobileSlow4G;
|
|
16
16
|
|
|
17
17
|
/** @typedef {import('../base-node.js').Node} Node */
|
|
18
18
|
/** @typedef {import('../network-node.js').NetworkNode} NetworkNode */
|
|
@@ -113,10 +113,10 @@ class Simulator {
|
|
|
113
113
|
/** @type {Required<Lantern.Simulation.Options>} */
|
|
114
114
|
this._options = Object.assign(
|
|
115
115
|
{
|
|
116
|
-
rtt:
|
|
117
|
-
throughput:
|
|
116
|
+
rtt: defaultThrottling.rttMs,
|
|
117
|
+
throughput: defaultThrottling.throughputKbps * 1024,
|
|
118
118
|
maximumConcurrentRequests: DEFAULT_MAXIMUM_CONCURRENT_REQUESTS,
|
|
119
|
-
cpuSlowdownMultiplier:
|
|
119
|
+
cpuSlowdownMultiplier: defaultThrottling.cpuSlowdownMultiplier,
|
|
120
120
|
layoutTaskMultiplier: DEFAULT_LAYOUT_TASK_MULTIPLIER,
|
|
121
121
|
additionalRttByOrigin: new Map(),
|
|
122
122
|
serverResponseTimeByOrigin: new Map(),
|
|
@@ -533,7 +533,7 @@ class Simulator {
|
|
|
533
533
|
const minimumTime = this._findNextNodeCompletionTime();
|
|
534
534
|
totalElapsedTime += minimumTime;
|
|
535
535
|
|
|
536
|
-
// While this is no longer strictly necessary, it's always better than
|
|
536
|
+
// While this is no longer strictly necessary, it's always better than hanging
|
|
537
537
|
if (!Number.isFinite(minimumTime) || iteration > 100000) {
|
|
538
538
|
throw new Error('Simulation failed, depth exceeded');
|
|
539
539
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type MetricName = import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricName;
|
|
2
|
+
export type MetricScore = import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricScore;
|
|
3
|
+
/** @typedef {import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricName} MetricName */
|
|
4
|
+
/** @typedef {import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricScore} MetricScore */
|
|
5
|
+
/**
|
|
6
|
+
* @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
|
|
7
|
+
* @return {Lantern.Simulation.ProcessedNavigation}
|
|
8
|
+
*/
|
|
9
|
+
export function createProcessedNavigation(traceEngineData: TraceEngine.Handlers.Types.TraceParseData): Lantern.Simulation.ProcessedNavigation;
|
|
10
|
+
/**
|
|
11
|
+
* @param {Lantern.Trace} trace
|
|
12
|
+
* @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
|
|
13
|
+
* @return {Lantern.NetworkRequest[]}
|
|
14
|
+
*/
|
|
15
|
+
export function createNetworkRequests(trace: Lantern.Trace, traceEngineData: TraceEngine.Handlers.Types.TraceParseData): Lantern.NetworkRequest[];
|
|
16
|
+
/**
|
|
17
|
+
* @param {Lantern.NetworkRequest[]} requests
|
|
18
|
+
* @param {Lantern.Trace} trace
|
|
19
|
+
* @param {TraceEngine.Handlers.Types.TraceParseData} traceEngineData
|
|
20
|
+
* @param {Lantern.Simulation.URL=} URL
|
|
21
|
+
*/
|
|
22
|
+
export function createGraph(requests: Lantern.NetworkRequest[], trace: Lantern.Trace, traceEngineData: TraceEngine.Handlers.Types.TraceParseData, URL?: Lantern.Simulation.URL | undefined): import("./page-dependency-graph.js").Node;
|
|
23
|
+
import * as TraceEngine from '@paulirish/trace_engine';
|
|
24
|
+
import * as Lantern from './types/lantern.js';
|
|
25
|
+
//# sourceMappingURL=trace-engine-computation-data.d.ts.map
|