@paulirish/trace_engine 0.0.37 → 0.0.39
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/core/platform/NumberUtilities.d.ts +0 -1
- package/core/platform/NumberUtilities.js +0 -17
- package/core/platform/NumberUtilities.js.map +1 -1
- package/core/platform/PromiseUtilities.d.ts +10 -0
- package/core/platform/PromiseUtilities.js +18 -0
- package/core/platform/PromiseUtilities.js.map +1 -0
- package/core/platform/SetUtilities.d.ts +2 -0
- package/core/platform/SetUtilities.js +23 -0
- package/core/platform/SetUtilities.js.map +1 -0
- package/generated/protocol.d.ts +36 -8
- package/locales/af.json +62 -0
- package/locales/am.json +62 -0
- package/locales/ar.json +62 -0
- package/locales/as.json +62 -0
- package/locales/az.json +62 -0
- package/locales/be.json +62 -0
- package/locales/bg.json +62 -0
- package/locales/bn.json +62 -0
- package/locales/bs.json +62 -0
- package/locales/ca.json +62 -0
- package/locales/cs.json +62 -0
- package/locales/cy.json +62 -0
- package/locales/da.json +62 -0
- package/locales/de.json +62 -0
- package/locales/el.json +62 -0
- package/locales/en-GB.json +62 -0
- package/locales/en-US.json +68 -0
- package/locales/en-XL.json +68 -0
- package/locales/es-419.json +62 -0
- package/locales/es.json +62 -0
- package/locales/et.json +62 -0
- package/locales/eu.json +62 -0
- package/locales/fa.json +62 -0
- package/locales/fi.json +62 -0
- package/locales/fil.json +62 -0
- package/locales/fr-CA.json +62 -0
- package/locales/fr.json +62 -0
- package/locales/gl.json +62 -0
- package/locales/gu.json +62 -0
- package/locales/he.json +62 -0
- package/locales/hi.json +62 -0
- package/locales/hr.json +62 -0
- package/locales/hu.json +62 -0
- package/locales/hy.json +62 -0
- package/locales/id.json +62 -0
- package/locales/is.json +62 -0
- package/locales/it.json +62 -0
- package/locales/ja.json +62 -0
- package/locales/ka.json +62 -0
- package/locales/kk.json +62 -0
- package/locales/km.json +62 -0
- package/locales/kn.json +62 -0
- package/locales/ko.json +62 -0
- package/locales/ky.json +62 -0
- package/locales/lo.json +62 -0
- package/locales/lt.json +62 -0
- package/locales/lv.json +62 -0
- package/locales/mk.json +62 -0
- package/locales/ml.json +62 -0
- package/locales/mn.json +62 -0
- package/locales/mr.json +62 -0
- package/locales/ms.json +62 -0
- package/locales/my.json +62 -0
- package/locales/ne.json +62 -0
- package/locales/nl.json +62 -0
- package/locales/no.json +62 -0
- package/locales/or.json +62 -0
- package/locales/pa.json +62 -0
- package/locales/pl.json +62 -0
- package/locales/pt-PT.json +62 -0
- package/locales/pt.json +62 -0
- package/locales/ro.json +62 -0
- package/locales/ru.json +62 -0
- package/locales/si.json +62 -0
- package/locales/sk.json +62 -0
- package/locales/sl.json +62 -0
- package/locales/sq.json +62 -0
- package/locales/sr-Latn.json +62 -0
- package/locales/sr.json +62 -0
- package/locales/sv.json +62 -0
- package/locales/sw.json +62 -0
- package/locales/ta.json +62 -0
- package/locales/te.json +62 -0
- package/locales/th.json +62 -0
- package/locales/tr.json +62 -0
- package/locales/uk.json +62 -0
- package/locales/ur.json +62 -0
- package/locales/uz.json +62 -0
- package/locales/vi.json +62 -0
- package/locales/zh-HK.json +62 -0
- package/locales/zh-TW.json +62 -0
- package/locales/zh.json +62 -0
- package/locales/zu.json +62 -0
- package/models/trace/EntriesFilter.d.ts +72 -0
- package/models/trace/EntriesFilter.js +296 -0
- package/models/trace/EntriesFilter.js.map +1 -0
- package/models/trace/LegacyTracingModel.js.map +1 -0
- package/models/trace/extras/Metadata.d.ts +2 -1
- package/models/trace/extras/Metadata.js +23 -4
- package/models/trace/extras/Metadata.js.map +1 -1
- package/models/trace/extras/TraceTree.d.ts +10 -7
- package/models/trace/extras/TraceTree.js +30 -15
- package/models/trace/extras/TraceTree.js.map +1 -1
- package/models/trace/extras/URLForEntry.d.ts +6 -5
- package/models/trace/extras/URLForEntry.js +6 -5
- package/models/trace/extras/URLForEntry.js.map +1 -1
- package/models/trace/handlers/EnhancedTracesHandler.d.ts +48 -0
- package/models/trace/handlers/EnhancedTracesHandler.js +165 -0
- package/models/trace/handlers/EnhancedTracesHandler.js.map +1 -0
- package/models/trace/handlers/FlowsHandler.d.ts +7 -0
- package/models/trace/handlers/FlowsHandler.js +157 -0
- package/models/trace/handlers/FlowsHandler.js.map +1 -0
- package/models/trace/handlers/ImagePaintingHandler.d.ts +1 -0
- package/models/trace/handlers/ImagePaintingHandler.js +8 -0
- package/models/trace/handlers/ImagePaintingHandler.js.map +1 -1
- package/models/trace/handlers/ModelHandlers.d.ts +1 -0
- package/models/trace/handlers/ModelHandlers.js +1 -0
- package/models/trace/handlers/ModelHandlers.js.map +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +2 -1
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
- package/models/trace/handlers/handlers-tsconfig.json +1 -0
- package/models/trace/helpers/Timing.d.ts +1 -0
- package/models/trace/helpers/Timing.js +7 -0
- package/models/trace/helpers/Timing.js.map +1 -1
- package/models/trace/insights/CLSCulprits.d.ts +1 -1
- package/models/trace/insights/CLSCulprits.js +32 -3
- package/models/trace/insights/CLSCulprits.js.map +1 -1
- package/models/trace/insights/CumulativeLayoutShift.d.ts +13 -36
- package/models/trace/insights/CumulativeLayoutShift.js +73 -199
- package/models/trace/insights/CumulativeLayoutShift.js.map +1 -1
- package/models/trace/insights/DocumentLatency.d.ts +1 -1
- package/models/trace/insights/DocumentLatency.js +31 -3
- package/models/trace/insights/DocumentLatency.js.map +1 -1
- package/models/trace/insights/FontDisplay.d.ts +1 -1
- package/models/trace/insights/FontDisplay.js +23 -2
- package/models/trace/insights/FontDisplay.js.map +1 -1
- package/models/trace/insights/ImageDelivery.d.ts +23 -0
- package/models/trace/insights/ImageDelivery.js +130 -0
- package/models/trace/insights/ImageDelivery.js.map +1 -0
- package/models/trace/insights/InsightRunners.d.ts +0 -3
- package/models/trace/insights/InsightRunners.js +0 -3
- package/models/trace/insights/InsightRunners.js.map +1 -1
- package/models/trace/insights/InteractionToNextPaint.d.ts +1 -1
- package/models/trace/insights/InteractionToNextPaint.js +26 -3
- package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
- package/models/trace/insights/LCPDiscovery.js +36 -9
- package/models/trace/insights/LCPDiscovery.js.map +1 -1
- package/models/trace/insights/LCPPhases.js +40 -8
- package/models/trace/insights/LCPPhases.js.map +1 -1
- package/models/trace/insights/LargestContentfulPaint.d.ts +7 -20
- package/models/trace/insights/LargestContentfulPaint.js +37 -57
- package/models/trace/insights/LargestContentfulPaint.js.map +1 -1
- package/models/trace/insights/Models.d.ts +1 -0
- package/models/trace/insights/Models.js +1 -0
- package/models/trace/insights/Models.js.map +1 -1
- package/models/trace/insights/RenderBlocking.js +31 -7
- package/models/trace/insights/RenderBlocking.js.map +1 -1
- package/models/trace/insights/SlowCSSSelector.d.ts +1 -1
- package/models/trace/insights/SlowCSSSelector.js +27 -4
- package/models/trace/insights/SlowCSSSelector.js.map +1 -1
- package/models/trace/insights/ThirdParties.d.ts +1 -1
- package/models/trace/insights/ThirdParties.js +25 -2
- package/models/trace/insights/ThirdParties.js.map +1 -1
- package/models/trace/insights/Viewport.js +27 -7
- package/models/trace/insights/Viewport.js.map +1 -1
- package/models/trace/insights/insights-tsconfig.json +1 -0
- package/models/trace/insights/types.d.ts +12 -0
- package/models/trace/insights/types.js +7 -0
- package/models/trace/insights/types.js.map +1 -1
- package/models/trace/lantern/BaseNode.d.ts +91 -0
- package/models/trace/lantern/BaseNode.js +268 -0
- package/models/trace/lantern/BaseNode.js.map +1 -0
- package/models/trace/lantern/CPUNode.d.ts +24 -0
- package/models/trace/lantern/CPUNode.js +64 -0
- package/models/trace/lantern/CPUNode.js.map +1 -0
- package/models/trace/lantern/LanternError.d.ts +3 -0
- package/models/trace/lantern/LanternError.js +7 -0
- package/models/trace/lantern/LanternError.js.map +1 -0
- package/models/trace/lantern/MetricsModule.d.ts +11 -0
- package/models/trace/lantern/MetricsModule.js +14 -0
- package/models/trace/lantern/MetricsModule.js.map +1 -0
- package/models/trace/lantern/NetworkNode.d.ts +22 -0
- package/models/trace/lantern/NetworkNode.js +83 -0
- package/models/trace/lantern/NetworkNode.js.map +1 -0
- package/models/trace/lantern/PageDependencyGraph.d.ts +43 -0
- package/models/trace/lantern/PageDependencyGraph.js +509 -0
- package/models/trace/lantern/PageDependencyGraph.js.map +1 -0
- package/models/trace/lantern/SimulationModule.d.ts +17 -0
- package/models/trace/lantern/SimulationModule.js +13 -0
- package/models/trace/lantern/SimulationModule.js.map +1 -0
- package/models/trace/lantern/simulation/NetworkAnalyzer.d.ts +112 -0
- package/models/trace/lantern/simulation/NetworkAnalyzer.js +486 -0
- package/models/trace/lantern/simulation/NetworkAnalyzer.js.map +1 -0
- package/models/trace/types/File.d.ts +5 -0
- package/models/trace/types/File.js +3 -0
- package/models/trace/types/File.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +5 -0
- package/models/trace/types/TraceEvents.js +12 -2
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/models/trace/types/types-tsconfig.json +6 -0
- package/package.json +1 -1
- package/test/test-trace-engine.mjs +10 -4
- package/.tmp/tsbuildinfo/models/trace/LanternComputationData.d.ts +0 -46
- package/.tmp/tsbuildinfo/models/trace/LanternComputationData.d.ts.map +0 -1
- package/.tmp/tsbuildinfo/models/trace/LegacyTracingModel.d.ts +0 -2
- package/.tmp/tsbuildinfo/models/trace/LegacyTracingModel.d.ts.map +0 -1
- package/.tmp/tsbuildinfo/models/trace/ModelImpl.d.ts +0 -72
- package/.tmp/tsbuildinfo/models/trace/ModelImpl.d.ts.map +0 -1
- package/.tmp/tsbuildinfo/models/trace/Processor.d.ts +0 -25
- package/.tmp/tsbuildinfo/models/trace/Processor.d.ts.map +0 -1
- package/.tmp/tsbuildinfo/models/trace/TracingManager.d.ts +0 -2
- package/.tmp/tsbuildinfo/models/trace/TracingManager.d.ts.map +0 -1
- package/.tmp/tsbuildinfo/models/trace/trace.d.ts +0 -13
- package/.tmp/tsbuildinfo/models/trace/trace.d.ts.map +0 -1
- package/models/trace/insights/ThirdPartyWeb.d.ts +0 -13
- package/models/trace/insights/ThirdPartyWeb.js +0 -42
- package/models/trace/insights/ThirdPartyWeb.js.map +0 -1
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
2
|
// Use of this source code is governed by a BSD-style license that can be
|
|
3
3
|
// found in the LICENSE file.
|
|
4
|
+
// import * as i18n from '../../../core/i18n/i18n.js';
|
|
4
5
|
import * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';
|
|
5
6
|
import * as Extras from '../extras/extras.js';
|
|
6
7
|
import * as Helpers from '../helpers/helpers.js';
|
|
8
|
+
import { InsightCategory } from './types.js';
|
|
9
|
+
const UIStrings = {
|
|
10
|
+
/** Title of an insight that provides details about the code on a web page that the user doesn't control (referred to as "third-party code"). */
|
|
11
|
+
title: 'Third parties',
|
|
12
|
+
/**
|
|
13
|
+
* @description Description of a DevTools insight that identifies the code on the page that the user doesn't control.
|
|
14
|
+
* This is displayed after a user expands the section to see more. No character length limits.
|
|
15
|
+
*/
|
|
16
|
+
description: 'Third party code can significantly impact load performance. ' +
|
|
17
|
+
'[Reduce and defer loading of third party code](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/loading-third-party-javascript/) to prioritize your page\'s content.',
|
|
18
|
+
};
|
|
19
|
+
// const str_ = i18n.i18n.registerUIStrings('models/trace/insights/ThirdParties.ts', UIStrings);
|
|
20
|
+
const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
|
|
7
21
|
export function deps() {
|
|
8
22
|
return ['Meta', 'NetworkRequests', 'Renderer', 'ImagePainting'];
|
|
9
23
|
}
|
|
@@ -16,6 +30,15 @@ function getRelatedEvents(summaries, firstPartyEntity) {
|
|
|
16
30
|
}
|
|
17
31
|
return events;
|
|
18
32
|
}
|
|
33
|
+
function finalize(partialModel) {
|
|
34
|
+
return {
|
|
35
|
+
title: i18nString(UIStrings.title),
|
|
36
|
+
description: i18nString(UIStrings.description),
|
|
37
|
+
category: InsightCategory.ALL,
|
|
38
|
+
shouldShow: Boolean([...partialModel.summaryByEntity.entries()].find(kv => kv[0] !== partialModel.firstPartyEntity)),
|
|
39
|
+
...partialModel,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
19
42
|
export function generateInsight(parsedTrace, context) {
|
|
20
43
|
const networkRequests = parsedTrace.NetworkRequests.byTime.filter(event => {
|
|
21
44
|
if (!context.navigation) {
|
|
@@ -30,13 +53,13 @@ export function generateInsight(parsedTrace, context) {
|
|
|
30
53
|
const firstPartyUrl = context.navigation?.args.data?.documentLoaderURL ?? parsedTrace.Meta.mainFrameURL;
|
|
31
54
|
const firstPartyEntity = ThirdPartyWeb.ThirdPartyWeb.getEntity(firstPartyUrl) ||
|
|
32
55
|
Extras.ThirdParties.makeUpEntity(madeUpEntityCache, firstPartyUrl);
|
|
33
|
-
return {
|
|
56
|
+
return finalize({
|
|
34
57
|
relatedEvents: getRelatedEvents(summaries, firstPartyEntity),
|
|
35
58
|
entityByRequest,
|
|
36
59
|
requestsByEntity: summaries.requestsByEntity,
|
|
37
60
|
summaryByRequest: summaries.byRequest,
|
|
38
61
|
summaryByEntity: summaries.byEntity,
|
|
39
62
|
firstPartyEntity,
|
|
40
|
-
};
|
|
63
|
+
});
|
|
41
64
|
}
|
|
42
65
|
//# sourceMappingURL=ThirdParties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThirdParties.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/ThirdParties.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,aAAa,MAAM,yDAAyD,CAAC;AACzF,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"Thir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E,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC;QAC5D,eAAe;QACf,gBAAgB,EAAE,SAAS,CAAC,gBAAgB;QAC5C,gBAAgB,EAAE,SAAS,CAAC,SAAS;QACrC,eAAe,EAAE,SAAS,CAAC,QAAQ;QACnC,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';\nimport * as Extras from '../extras/extras.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Types from '../types/types.js';\n\nimport {InsightCategory, type InsightModel, type InsightSetContext, type RequiredData} from './types.js';\n\nconst UIStrings = {\n /** Title of an insight that provides details about the code on a web page that the user doesn't control (referred to as \"third-party code\"). */\n title: 'Third parties',\n /**\n * @description Description of a DevTools insight that identifies the code on the page that the user doesn't control.\n * This is displayed after a user expands the section to see more. No character length limits.\n */\n description: 'Third party code can significantly impact load performance. ' +\n '[Reduce and defer loading of third party code](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/loading-third-party-javascript/) to prioritize your page\\'s content.',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/ThirdParties.ts', UIStrings);\nconst i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport function deps(): ['Meta', 'NetworkRequests', 'Renderer', 'ImagePainting'] {\n return ['Meta', 'NetworkRequests', 'Renderer', 'ImagePainting'];\n}\n\nexport type ThirdPartiesInsightModel = InsightModel<{\n entityByRequest: Map<Types.Events.SyntheticNetworkRequest, Extras.ThirdParties.Entity>,\n requestsByEntity: Map<Extras.ThirdParties.Entity, Types.Events.SyntheticNetworkRequest[]>,\n summaryByRequest: Map<Types.Events.SyntheticNetworkRequest, Extras.ThirdParties.Summary>,\n summaryByEntity: Map<Extras.ThirdParties.Entity, Extras.ThirdParties.Summary>,\n /** The entity for this navigation's URL. Any other entity is from a third party. */\n firstPartyEntity?: Extras.ThirdParties.Entity,\n}>;\n\nfunction getRelatedEvents(\n summaries: Extras.ThirdParties.SummaryMaps,\n firstPartyEntity: Extras.ThirdParties.Entity|undefined): Types.Events.Event[] {\n const events = [];\n\n for (const [entity, requests] of summaries.requestsByEntity.entries()) {\n if (entity !== firstPartyEntity) {\n events.push(...requests);\n }\n }\n\n return events;\n}\n\nfunction finalize(partialModel: Omit<ThirdPartiesInsightModel, 'title'|'description'|'category'|'shouldShow'>):\n ThirdPartiesInsightModel {\n return {\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n shouldShow:\n Boolean([...partialModel.summaryByEntity.entries()].find(kv => kv[0] !== partialModel.firstPartyEntity)),\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): ThirdPartiesInsightModel {\n const networkRequests = parsedTrace.NetworkRequests.byTime.filter(event => {\n if (!context.navigation) {\n return false;\n }\n\n if (event.args.data.frame !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n const {entityByRequest, madeUpEntityCache, summaries} = Extras.ThirdParties.getSummariesAndEntitiesForTraceBounds(\n parsedTrace as Handlers.Types.ParsedTrace, context.bounds, networkRequests);\n\n const firstPartyUrl = context.navigation?.args.data?.documentLoaderURL ?? parsedTrace.Meta.mainFrameURL;\n const firstPartyEntity = ThirdPartyWeb.ThirdPartyWeb.getEntity(firstPartyUrl) ||\n Extras.ThirdParties.makeUpEntity(madeUpEntityCache, firstPartyUrl);\n\n return finalize({\n relatedEvents: getRelatedEvents(summaries, firstPartyEntity),\n entityByRequest,\n requestsByEntity: summaries.requestsByEntity,\n summaryByRequest: summaries.byRequest,\n summaryByEntity: summaries.byEntity,\n firstPartyEntity,\n });\n}\n"]}
|
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
2
|
// Use of this source code is governed by a BSD-style license that can be
|
|
3
3
|
// found in the LICENSE file.
|
|
4
|
+
// import * as i18n from '../../../core/i18n/i18n.js';
|
|
4
5
|
import * as Helpers from '../helpers/helpers.js';
|
|
5
|
-
import { InsightWarning } from './types.js';
|
|
6
|
+
import { InsightCategory, InsightWarning, } from './types.js';
|
|
7
|
+
const UIStrings = {
|
|
8
|
+
/** Title of an insight that provides details about if the page's viewport is optimized for mobile viewing. */
|
|
9
|
+
title: 'Viewport not optimized for mobile',
|
|
10
|
+
/**
|
|
11
|
+
* @description Text to tell the user how a viewport meta element can improve performance. \xa0 is a non-breaking space
|
|
12
|
+
*/
|
|
13
|
+
description: 'The page\'s viewport is not mobile-optimized, so tap interactions may be [delayed by up to 300\xA0ms](https://developer.chrome.com/blog/300ms-tap-delay-gone-away/).',
|
|
14
|
+
};
|
|
15
|
+
// const str_ = i18n.i18n.registerUIStrings('models/trace/insights/Viewport.ts', UIStrings);
|
|
16
|
+
const i18nString = string => string; // i18n.i18n.getLocalizedString.bind(undefined, str_);
|
|
6
17
|
export function deps() {
|
|
7
18
|
return ['Meta', 'UserInteractions'];
|
|
8
19
|
}
|
|
20
|
+
function finalize(partialModel) {
|
|
21
|
+
return {
|
|
22
|
+
title: i18nString(UIStrings.title),
|
|
23
|
+
description: i18nString(UIStrings.description),
|
|
24
|
+
category: InsightCategory.INP,
|
|
25
|
+
shouldShow: partialModel.mobileOptimized === false,
|
|
26
|
+
...partialModel,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
9
29
|
export function generateInsight(parsedTrace, context) {
|
|
10
30
|
const compositorEvents = parsedTrace.UserInteractions.beginCommitCompositorFrameEvents.filter(event => {
|
|
11
31
|
if (event.args.frame !== context.frameId) {
|
|
@@ -15,10 +35,10 @@ export function generateInsight(parsedTrace, context) {
|
|
|
15
35
|
});
|
|
16
36
|
if (!compositorEvents.length) {
|
|
17
37
|
// Trace doesn't have the data we need.
|
|
18
|
-
return {
|
|
38
|
+
return finalize({
|
|
19
39
|
mobileOptimized: null,
|
|
20
40
|
warnings: [InsightWarning.NO_LAYOUT],
|
|
21
|
-
};
|
|
41
|
+
});
|
|
22
42
|
}
|
|
23
43
|
const viewportEvent = parsedTrace.UserInteractions.parseMetaViewportEvents.find(event => {
|
|
24
44
|
if (event.args.data.frame !== context.frameId) {
|
|
@@ -29,16 +49,16 @@ export function generateInsight(parsedTrace, context) {
|
|
|
29
49
|
// Returns true only if all events are mobile optimized.
|
|
30
50
|
for (const event of compositorEvents) {
|
|
31
51
|
if (!event.args.is_mobile_optimized) {
|
|
32
|
-
return {
|
|
52
|
+
return finalize({
|
|
33
53
|
mobileOptimized: false,
|
|
34
54
|
viewportEvent,
|
|
35
55
|
metricSavings: { INP: 300 },
|
|
36
|
-
};
|
|
56
|
+
});
|
|
37
57
|
}
|
|
38
58
|
}
|
|
39
|
-
return {
|
|
59
|
+
return finalize({
|
|
40
60
|
mobileOptimized: true,
|
|
41
61
|
viewportEvent,
|
|
42
|
-
};
|
|
62
|
+
});
|
|
43
63
|
}
|
|
44
64
|
//# sourceMappingURL=Viewport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Viewport.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Viewport.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAGjD,OAAO,
|
|
1
|
+
{"version":3,"file":"Viewport.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Viewport.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,uBAAu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Ae,EAAE,IAAI;YACrB,QAAQ,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC;SACrC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,aAAa,GAAG,WAAW,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;QACtF,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC;YAC9C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,wDAAwD;IACxD,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,OAAO,QAAQ,CAAC;gBACd,eAAe,EAAE,KAAK;gBACtB,aAAa;gBACb,aAAa,EAAE,EAAC,GAAG,EAAE,GAAgC,EAAC;aACvD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,eAAe,EAAE,IAAI;QACrB,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n type InsightModel,\n type InsightSetContext,\n InsightWarning,\n type RequiredData,\n} from './types.js';\n\nconst UIStrings = {\n /** Title of an insight that provides details about if the page's viewport is optimized for mobile viewing. */\n title: 'Viewport not optimized for mobile',\n /**\n * @description Text to tell the user how a viewport meta element can improve performance. \\xa0 is a non-breaking space\n */\n description:\n 'The page\\'s viewport is not mobile-optimized, so tap interactions may be [delayed by up to 300\\xA0ms](https://developer.chrome.com/blog/300ms-tap-delay-gone-away/).',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/Viewport.ts', UIStrings);\nconst i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport function deps(): ['Meta', 'UserInteractions'] {\n return ['Meta', 'UserInteractions'];\n}\n\nexport type ViewportInsightModel = InsightModel<{\n mobileOptimized: boolean | null,\n viewportEvent?: Types.Events.ParseMetaViewport,\n}>;\n\nfunction finalize(partialModel: Omit<ViewportInsightModel, 'title'|'description'|'category'|'shouldShow'>):\n ViewportInsightModel {\n return {\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n shouldShow: partialModel.mobileOptimized === false,\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): ViewportInsightModel {\n const compositorEvents = parsedTrace.UserInteractions.beginCommitCompositorFrameEvents.filter(event => {\n if (event.args.frame !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n if (!compositorEvents.length) {\n // Trace doesn't have the data we need.\n return finalize({\n mobileOptimized: null,\n warnings: [InsightWarning.NO_LAYOUT],\n });\n }\n\n const viewportEvent = parsedTrace.UserInteractions.parseMetaViewportEvents.find(event => {\n if (event.args.data.frame !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n // Returns true only if all events are mobile optimized.\n for (const event of compositorEvents) {\n if (!event.args.is_mobile_optimized) {\n return finalize({\n mobileOptimized: false,\n viewportEvent,\n metricSavings: {INP: 300 as Types.Timing.MilliSeconds},\n });\n }\n }\n\n return finalize({\n mobileOptimized: true,\n viewportEvent,\n });\n}\n"]}
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"../../../../../../../front_end/models/trace/insights/Common.ts",
|
|
34
34
|
"../../../../../../../front_end/models/trace/insights/DocumentLatency.ts",
|
|
35
35
|
"../../../../../../../front_end/models/trace/insights/FontDisplay.ts",
|
|
36
|
+
"../../../../../../../front_end/models/trace/insights/ImageDelivery.ts",
|
|
36
37
|
"../../../../../../../front_end/models/trace/insights/InteractionToNextPaint.ts",
|
|
37
38
|
"../../../../../../../front_end/models/trace/insights/LCPDiscovery.ts",
|
|
38
39
|
"../../../../../../../front_end/models/trace/insights/LCPPhases.ts",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// import type * as Common from '../../../core/common/common.js';
|
|
1
2
|
import type * as Handlers from '../handlers/handlers.js';
|
|
2
3
|
import type * as Lantern from '../lantern/lantern.js';
|
|
3
4
|
import type * as Types from '../types/types.js';
|
|
@@ -37,7 +38,18 @@ export interface MetricSavings {
|
|
|
37
38
|
CLS?: number;
|
|
38
39
|
INP?: Types.Timing.MilliSeconds;
|
|
39
40
|
}
|
|
41
|
+
export declare enum InsightCategory {
|
|
42
|
+
ALL = "All",
|
|
43
|
+
INP = "INP",
|
|
44
|
+
LCP = "LCP",
|
|
45
|
+
CLS = "CLS"
|
|
46
|
+
}
|
|
40
47
|
export type InsightModel<R extends Record<string, unknown>> = R & {
|
|
48
|
+
title: string;
|
|
49
|
+
description: string;
|
|
50
|
+
category: InsightCategory;
|
|
51
|
+
/** True if there is anything of interest to display to the user. */
|
|
52
|
+
shouldShow: boolean;
|
|
41
53
|
relatedEvents?: Types.Events.Event[];
|
|
42
54
|
warnings?: InsightWarning[];
|
|
43
55
|
metricSavings?: MetricSavings;
|
|
@@ -9,4 +9,11 @@ export var InsightWarning;
|
|
|
9
9
|
InsightWarning["NO_DOCUMENT_REQUEST"] = "NO_DOCUMENT_REQUEST";
|
|
10
10
|
InsightWarning["NO_LAYOUT"] = "NO_LAYOUT";
|
|
11
11
|
})(InsightWarning || (InsightWarning = {}));
|
|
12
|
+
export var InsightCategory;
|
|
13
|
+
(function (InsightCategory) {
|
|
14
|
+
InsightCategory["ALL"] = "All";
|
|
15
|
+
InsightCategory["INP"] = "INP";
|
|
16
|
+
InsightCategory["LCP"] = "LCP";
|
|
17
|
+
InsightCategory["CLS"] = "CLS";
|
|
18
|
+
})(InsightCategory || (InsightCategory = {}));
|
|
12
19
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAoC7B,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,uEAAuE;IACvE,6DAA2C,CAAA;IAC3C,yCAAuB,CAAA;AACzB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB;AAYD,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;AACb,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Common from '../../../core/common/common.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport type * as Types from '../types/types.js';\n\nimport type * as Models from './Models.js';\n\n/**\n * Context for the portion of the trace an insight should look at.\n */\nexport type InsightSetContext = InsightSetContextWithoutNavigation|InsightSetContextWithNavigation;\n\nexport interface InsightSetContextWithoutNavigation {\n bounds: Types.Timing.TraceWindowMicroSeconds;\n frameId: string;\n navigation?: never;\n}\n\nexport interface InsightSetContextWithNavigation {\n bounds: Types.Timing.TraceWindowMicroSeconds;\n frameId: string;\n navigation: Types.Events.NavigationStart;\n navigationId: string;\n lantern?: LanternContext;\n}\n\nexport interface LanternContext {\n graph: Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>;\n simulator: Lantern.Simulation.Simulator<Types.Events.SyntheticNetworkRequest>;\n metrics: Record<string, Lantern.Metrics.MetricResult>;\n}\n\nexport type InsightModelsType = typeof Models;\n\nexport enum InsightWarning {\n NO_FP = 'NO_FP',\n NO_LCP = 'NO_LCP',\n // No network request could be identified as the primary HTML document.\n NO_DOCUMENT_REQUEST = 'NO_DOCUMENT_REQUEST',\n NO_LAYOUT = 'NO_LAYOUT',\n}\n\nexport interface MetricSavings {\n /* eslint-disable @typescript-eslint/naming-convention */\n FCP?: Types.Timing.MilliSeconds;\n LCP?: Types.Timing.MilliSeconds;\n TBT?: Types.Timing.MilliSeconds;\n CLS?: number;\n INP?: Types.Timing.MilliSeconds;\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n\nexport enum InsightCategory {\n ALL = 'All',\n INP = 'INP',\n LCP = 'LCP',\n CLS = 'CLS',\n}\n\nexport type InsightModel<R extends Record<string, unknown>> = R&{\n title: Common.UIString.LocalizedString,\n description: Common.UIString.LocalizedString,\n category: InsightCategory,\n /** True if there is anything of interest to display to the user. */\n shouldShow: boolean,\n relatedEvents?: Types.Events.Event[],\n warnings?: InsightWarning[],\n metricSavings?: MetricSavings,\n};\n\n/**\n * Contains insights for a specific navigation. If a trace began after a navigation already started,\n * this could instead represent the duration from the beginning of the trace up to the first recorded\n * navigation (or the end of the trace).\n */\nexport type InsightSet = {\n /** If for a navigation, this is the navigationId. Else it is Trace.Types.Events.NO_NAVIGATION. */\n id: Types.Events.NavigationId,\n /** The URL to show in the accordion list. */\n url: URL,\n frameId: string,\n bounds: Types.Timing.TraceWindowMicroSeconds,\n model: InsightModels,\n navigation?: Types.Events.NavigationStart,\n};\n\n/**\n * Contains insights for a specific insight set.\n */\nexport type InsightModels = {\n [I in keyof InsightModelsType]: ReturnType<InsightModelsType[I]['generateInsight']>;\n};\n\n/**\n * Contains insights for the entire trace. Insights are mostly grouped by `navigationId`, with one exception:\n *\n * If the analyzed trace started after the navigation, and has meaningful work with that span, there is no\n * navigation to map it to. In this case `Types.Events.NO_NAVIGATION` is used for the key.\n */\nexport type TraceInsightSets = Map<Types.Events.NavigationId, InsightSet>;\n\n/**\n * Represents the narrow set of dependencies defined by an insight's `deps()` function. `Meta` is always included regardless of `deps()`.\n */\nexport type RequiredData<D extends() => Array<keyof typeof Handlers.ModelHandlers>> =\n Handlers.Types.EnabledHandlerDataWithMeta<Pick<typeof Handlers.ModelHandlers, ReturnType<D>[number]>>;\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type CPUNode } from './CPUNode.js';
|
|
2
|
+
import { type NetworkNode } from './NetworkNode.js';
|
|
3
|
+
import type * as Lantern from './types/lantern.js';
|
|
4
|
+
/**
|
|
5
|
+
* A union of all types derived from BaseNode, allowing type check discrimination
|
|
6
|
+
* based on `node.type`. If a new node type is created, it should be added here.
|
|
7
|
+
*/
|
|
8
|
+
export type Node<T = Lantern.AnyNetworkObject> = CPUNode<T> | NetworkNode<T>;
|
|
9
|
+
/**
|
|
10
|
+
* @fileoverview This class encapsulates logic for handling resources and tasks used to model the
|
|
11
|
+
* execution dependency graph of the page. A node has a unique identifier and can depend on other
|
|
12
|
+
* nodes/be depended on. The construction of the graph maintains some important invariants that are
|
|
13
|
+
* inherent to the model:
|
|
14
|
+
*
|
|
15
|
+
* 1. The graph is a DAG, there are no cycles.
|
|
16
|
+
* 2. There is always a root node upon which all other nodes eventually depend.
|
|
17
|
+
*
|
|
18
|
+
* This allows particular optimizations in this class so that we do no need to check for cycles as
|
|
19
|
+
* these methods are called and we can always start traversal at the root node.
|
|
20
|
+
*/
|
|
21
|
+
declare class BaseNode<T = Lantern.AnyNetworkObject> {
|
|
22
|
+
static types: {
|
|
23
|
+
readonly NETWORK: "network";
|
|
24
|
+
readonly CPU: "cpu";
|
|
25
|
+
};
|
|
26
|
+
_id: string;
|
|
27
|
+
_isMainDocument: boolean;
|
|
28
|
+
_dependents: Node[];
|
|
29
|
+
_dependencies: Node[];
|
|
30
|
+
constructor(id: string);
|
|
31
|
+
get id(): string;
|
|
32
|
+
get type(): 'network' | 'cpu';
|
|
33
|
+
/**
|
|
34
|
+
* In microseconds
|
|
35
|
+
*/
|
|
36
|
+
get startTime(): number;
|
|
37
|
+
/**
|
|
38
|
+
* In microseconds
|
|
39
|
+
*/
|
|
40
|
+
get endTime(): number;
|
|
41
|
+
setIsMainDocument(value: boolean): void;
|
|
42
|
+
isMainDocument(): boolean;
|
|
43
|
+
getDependents(): Node[];
|
|
44
|
+
getNumberOfDependents(): number;
|
|
45
|
+
getDependencies(): Node[];
|
|
46
|
+
getNumberOfDependencies(): number;
|
|
47
|
+
getRootNode(): Node<T>;
|
|
48
|
+
addDependent(node: Node): void;
|
|
49
|
+
addDependency(node: Node): void;
|
|
50
|
+
removeDependent(node: Node): void;
|
|
51
|
+
removeDependency(node: Node): void;
|
|
52
|
+
removeAllDependencies(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Computes whether the given node is anywhere in the dependency graph of this node.
|
|
55
|
+
* While this method can prevent cycles, it walks the graph and should be used sparingly.
|
|
56
|
+
* Nodes are always considered dependent on themselves for the purposes of cycle detection.
|
|
57
|
+
*/
|
|
58
|
+
isDependentOn(node: BaseNode<T>): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Clones the node's information without adding any dependencies/dependents.
|
|
61
|
+
*/
|
|
62
|
+
cloneWithoutRelationships(): Node<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Clones the entire graph connected to this node filtered by the optional predicate. If a node is
|
|
65
|
+
* included by the predicate, all nodes along the paths between the node and the root will be included. If the
|
|
66
|
+
* node this was called on is not included in the resulting filtered graph, the method will throw.
|
|
67
|
+
*/
|
|
68
|
+
cloneWithRelationships(predicate?: (arg0: Node) => boolean): Node;
|
|
69
|
+
/**
|
|
70
|
+
* Traverses all connected nodes in BFS order, calling `callback` exactly once
|
|
71
|
+
* on each. `traversalPath` is the shortest (though not necessarily unique)
|
|
72
|
+
* path from `node` to the root of the iteration.
|
|
73
|
+
*
|
|
74
|
+
* The `getNextNodes` function takes a visited node and returns which nodes to
|
|
75
|
+
* visit next. It defaults to returning the node's dependents.
|
|
76
|
+
*/
|
|
77
|
+
traverse(callback: (node: Node<T>, traversalPath: Node<T>[]) => void, getNextNodes?: (arg0: Node<T>) => Node<T>[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* @see BaseNode.traverse
|
|
80
|
+
*/
|
|
81
|
+
traverseGenerator(getNextNodes?: (arg0: Node) => Node[]): Generator<{
|
|
82
|
+
node: Node;
|
|
83
|
+
traversalPath: Node[];
|
|
84
|
+
}, void, unknown>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns whether the given node has a cycle in its dependent graph by performing a DFS.
|
|
87
|
+
*/
|
|
88
|
+
static hasCycle(node: Node, direction?: 'dependents' | 'dependencies' | 'both'): boolean;
|
|
89
|
+
canDependOn(node: Node): boolean;
|
|
90
|
+
}
|
|
91
|
+
export { BaseNode };
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview This class encapsulates logic for handling resources and tasks used to model the
|
|
6
|
+
* execution dependency graph of the page. A node has a unique identifier and can depend on other
|
|
7
|
+
* nodes/be depended on. The construction of the graph maintains some important invariants that are
|
|
8
|
+
* inherent to the model:
|
|
9
|
+
*
|
|
10
|
+
* 1. The graph is a DAG, there are no cycles.
|
|
11
|
+
* 2. There is always a root node upon which all other nodes eventually depend.
|
|
12
|
+
*
|
|
13
|
+
* This allows particular optimizations in this class so that we do no need to check for cycles as
|
|
14
|
+
* these methods are called and we can always start traversal at the root node.
|
|
15
|
+
*/
|
|
16
|
+
class BaseNode {
|
|
17
|
+
static types = {
|
|
18
|
+
NETWORK: 'network',
|
|
19
|
+
CPU: 'cpu',
|
|
20
|
+
};
|
|
21
|
+
_id;
|
|
22
|
+
_isMainDocument;
|
|
23
|
+
_dependents;
|
|
24
|
+
_dependencies;
|
|
25
|
+
constructor(id) {
|
|
26
|
+
this._id = id;
|
|
27
|
+
this._isMainDocument = false;
|
|
28
|
+
this._dependents = [];
|
|
29
|
+
this._dependencies = [];
|
|
30
|
+
}
|
|
31
|
+
get id() {
|
|
32
|
+
return this._id;
|
|
33
|
+
}
|
|
34
|
+
get type() {
|
|
35
|
+
throw new Error('Unimplemented');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* In microseconds
|
|
39
|
+
*/
|
|
40
|
+
get startTime() {
|
|
41
|
+
throw new Error('Unimplemented');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* In microseconds
|
|
45
|
+
*/
|
|
46
|
+
get endTime() {
|
|
47
|
+
throw new Error('Unimplemented');
|
|
48
|
+
}
|
|
49
|
+
setIsMainDocument(value) {
|
|
50
|
+
this._isMainDocument = value;
|
|
51
|
+
}
|
|
52
|
+
isMainDocument() {
|
|
53
|
+
return this._isMainDocument;
|
|
54
|
+
}
|
|
55
|
+
getDependents() {
|
|
56
|
+
return this._dependents.slice();
|
|
57
|
+
}
|
|
58
|
+
getNumberOfDependents() {
|
|
59
|
+
return this._dependents.length;
|
|
60
|
+
}
|
|
61
|
+
getDependencies() {
|
|
62
|
+
return this._dependencies.slice();
|
|
63
|
+
}
|
|
64
|
+
getNumberOfDependencies() {
|
|
65
|
+
return this._dependencies.length;
|
|
66
|
+
}
|
|
67
|
+
getRootNode() {
|
|
68
|
+
let rootNode = this;
|
|
69
|
+
while (rootNode._dependencies.length) {
|
|
70
|
+
rootNode = rootNode._dependencies[0];
|
|
71
|
+
}
|
|
72
|
+
return rootNode;
|
|
73
|
+
}
|
|
74
|
+
addDependent(node) {
|
|
75
|
+
node.addDependency(this);
|
|
76
|
+
}
|
|
77
|
+
addDependency(node) {
|
|
78
|
+
// @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.
|
|
79
|
+
if (node === this) {
|
|
80
|
+
throw new Error('Cannot add dependency on itself');
|
|
81
|
+
}
|
|
82
|
+
if (this._dependencies.includes(node)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
node._dependents.push(this);
|
|
86
|
+
this._dependencies.push(node);
|
|
87
|
+
}
|
|
88
|
+
removeDependent(node) {
|
|
89
|
+
node.removeDependency(this);
|
|
90
|
+
}
|
|
91
|
+
removeDependency(node) {
|
|
92
|
+
if (!this._dependencies.includes(node)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const thisIndex = node._dependents.indexOf(this);
|
|
96
|
+
node._dependents.splice(thisIndex, 1);
|
|
97
|
+
this._dependencies.splice(this._dependencies.indexOf(node), 1);
|
|
98
|
+
}
|
|
99
|
+
removeAllDependencies() {
|
|
100
|
+
for (const node of this._dependencies.slice()) {
|
|
101
|
+
this.removeDependency(node);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Computes whether the given node is anywhere in the dependency graph of this node.
|
|
106
|
+
* While this method can prevent cycles, it walks the graph and should be used sparingly.
|
|
107
|
+
* Nodes are always considered dependent on themselves for the purposes of cycle detection.
|
|
108
|
+
*/
|
|
109
|
+
isDependentOn(node) {
|
|
110
|
+
let isDependentOnNode = false;
|
|
111
|
+
this.traverse(currentNode => {
|
|
112
|
+
if (isDependentOnNode) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
isDependentOnNode = currentNode === node;
|
|
116
|
+
}, currentNode => {
|
|
117
|
+
// If we've already found the dependency, don't traverse further.
|
|
118
|
+
if (isDependentOnNode) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
// Otherwise, traverse the dependencies.
|
|
122
|
+
return currentNode.getDependencies();
|
|
123
|
+
});
|
|
124
|
+
return isDependentOnNode;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Clones the node's information without adding any dependencies/dependents.
|
|
128
|
+
*/
|
|
129
|
+
cloneWithoutRelationships() {
|
|
130
|
+
const node = new BaseNode(this.id);
|
|
131
|
+
node.setIsMainDocument(this._isMainDocument);
|
|
132
|
+
return node;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Clones the entire graph connected to this node filtered by the optional predicate. If a node is
|
|
136
|
+
* included by the predicate, all nodes along the paths between the node and the root will be included. If the
|
|
137
|
+
* node this was called on is not included in the resulting filtered graph, the method will throw.
|
|
138
|
+
*/
|
|
139
|
+
cloneWithRelationships(predicate) {
|
|
140
|
+
const rootNode = this.getRootNode();
|
|
141
|
+
const idsToIncludedClones = new Map();
|
|
142
|
+
// Walk down dependents.
|
|
143
|
+
rootNode.traverse(node => {
|
|
144
|
+
if (idsToIncludedClones.has(node.id)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (predicate === undefined) {
|
|
148
|
+
// No condition for entry, so clone every node.
|
|
149
|
+
idsToIncludedClones.set(node.id, node.cloneWithoutRelationships());
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (predicate(node)) {
|
|
153
|
+
// Node included, so walk back up dependencies, cloning nodes from here back to the root.
|
|
154
|
+
node.traverse(node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),
|
|
155
|
+
// Dependencies already cloned have already cloned ancestors, so no need to visit again.
|
|
156
|
+
node => node._dependencies.filter(parent => !idsToIncludedClones.has(parent.id)));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
// Copy dependencies between nodes.
|
|
160
|
+
rootNode.traverse(originalNode => {
|
|
161
|
+
const clonedNode = idsToIncludedClones.get(originalNode.id);
|
|
162
|
+
if (!clonedNode) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
for (const dependency of originalNode._dependencies) {
|
|
166
|
+
const clonedDependency = idsToIncludedClones.get(dependency.id);
|
|
167
|
+
if (!clonedDependency) {
|
|
168
|
+
throw new Error('Dependency somehow not cloned');
|
|
169
|
+
}
|
|
170
|
+
clonedNode.addDependency(clonedDependency);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
const clonedThisNode = idsToIncludedClones.get(this.id);
|
|
174
|
+
if (!clonedThisNode) {
|
|
175
|
+
throw new Error('Cloned graph missing node');
|
|
176
|
+
}
|
|
177
|
+
return clonedThisNode;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Traverses all connected nodes in BFS order, calling `callback` exactly once
|
|
181
|
+
* on each. `traversalPath` is the shortest (though not necessarily unique)
|
|
182
|
+
* path from `node` to the root of the iteration.
|
|
183
|
+
*
|
|
184
|
+
* The `getNextNodes` function takes a visited node and returns which nodes to
|
|
185
|
+
* visit next. It defaults to returning the node's dependents.
|
|
186
|
+
*/
|
|
187
|
+
traverse(callback, getNextNodes) {
|
|
188
|
+
for (const { node, traversalPath } of this.traverseGenerator(getNextNodes)) {
|
|
189
|
+
callback(node, traversalPath);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @see BaseNode.traverse
|
|
194
|
+
*/
|
|
195
|
+
// clang-format off
|
|
196
|
+
*traverseGenerator(getNextNodes) {
|
|
197
|
+
// clang-format on
|
|
198
|
+
if (!getNextNodes) {
|
|
199
|
+
getNextNodes = node => node.getDependents();
|
|
200
|
+
}
|
|
201
|
+
// @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one
|
|
202
|
+
const queue = [[this]];
|
|
203
|
+
const visited = new Set([this.id]);
|
|
204
|
+
while (queue.length) {
|
|
205
|
+
// @ts-expect-error - queue has length so it's guaranteed to have an item
|
|
206
|
+
const traversalPath = queue.shift();
|
|
207
|
+
const node = traversalPath[0];
|
|
208
|
+
yield { node, traversalPath };
|
|
209
|
+
for (const nextNode of getNextNodes(node)) {
|
|
210
|
+
if (visited.has(nextNode.id)) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
visited.add(nextNode.id);
|
|
214
|
+
queue.push([nextNode, ...traversalPath]);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns whether the given node has a cycle in its dependent graph by performing a DFS.
|
|
220
|
+
*/
|
|
221
|
+
static hasCycle(node, direction = 'both') {
|
|
222
|
+
// Checking 'both' is the default entrypoint to recursively check both directions
|
|
223
|
+
if (direction === 'both') {
|
|
224
|
+
return BaseNode.hasCycle(node, 'dependents') || BaseNode.hasCycle(node, 'dependencies');
|
|
225
|
+
}
|
|
226
|
+
const visited = new Set();
|
|
227
|
+
const currentPath = [];
|
|
228
|
+
const toVisit = [node];
|
|
229
|
+
const depthAdded = new Map([[node, 0]]);
|
|
230
|
+
// Keep going while we have nodes to visit in the stack
|
|
231
|
+
while (toVisit.length) {
|
|
232
|
+
// Get the last node in the stack (DFS uses stack, not queue)
|
|
233
|
+
// @ts-expect-error - toVisit has length so it's guaranteed to have an item
|
|
234
|
+
const currentNode = toVisit.pop();
|
|
235
|
+
// We've hit a cycle if the node we're visiting is in our current dependency path
|
|
236
|
+
if (currentPath.includes(currentNode)) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
// If we've already visited the node, no need to revisit it
|
|
240
|
+
if (visited.has(currentNode)) {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
// Since we're visiting this node, clear out any nodes in our path that we had to backtrack
|
|
244
|
+
// @ts-expect-error
|
|
245
|
+
while (currentPath.length > depthAdded.get(currentNode)) {
|
|
246
|
+
currentPath.pop();
|
|
247
|
+
}
|
|
248
|
+
// Update our data structures to reflect that we're adding this node to our path
|
|
249
|
+
visited.add(currentNode);
|
|
250
|
+
currentPath.push(currentNode);
|
|
251
|
+
// Add all of its dependents to our toVisit stack
|
|
252
|
+
const nodesToExplore = direction === 'dependents' ? currentNode._dependents : currentNode._dependencies;
|
|
253
|
+
for (const nextNode of nodesToExplore) {
|
|
254
|
+
if (toVisit.includes(nextNode)) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
toVisit.push(nextNode);
|
|
258
|
+
depthAdded.set(nextNode, currentPath.length);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
canDependOn(node) {
|
|
264
|
+
return node.startTime <= this.startTime;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
export { BaseNode };
|
|
268
|
+
//# sourceMappingURL=BaseNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseNode.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/lantern/BaseNode.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAY7B;;;;;;;;;;;GAWG;AAEH,MAAM,QAAQ;IACZ,MAAM,CAAC,KAAK,GAAG;QACb,OAAO,EAAE,SAAS;QAClB,GAAG,EAAE,KAAK;KACF,CAAC;IAEX,GAAG,CAAS;IACZ,eAAe,CAAU;IACzB,WAAW,CAAS;IACpB,aAAa,CAAS;IAEtB,YAAY,EAAU;QACpB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,IAAI,IAAI;QACN,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACnC,CAAC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AM,GAAG,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACxD,WAAW,CAAC,GAAG,EAAE,CAAC;YACpB,CAAC;YAED,gFAAgF;YAChF,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;YACzB,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAE9B,iDAAiD;YACjD,MAAM,cAAc,GAAG,SAAS,KAAK,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC;YACxG,KAAK,MAAM,QAAQ,IAAI,cAAc,EAAE,CAAC;gBACtC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC/B,SAAS;gBACX,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvB,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,IAAU;QACpB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;;AAGH,OAAO,EAAC,QAAQ,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {type CPUNode} from './CPUNode.js';\nimport {type NetworkNode} from './NetworkNode.js';\nimport type * as Lantern from './types/lantern.js';\n\n/**\n * A union of all types derived from BaseNode, allowing type check discrimination\n * based on `node.type`. If a new node type is created, it should be added here.\n */\nexport type Node<T = Lantern.AnyNetworkObject> = CPUNode<T>|NetworkNode<T>;\n\n/**\n * @fileoverview This class encapsulates logic for handling resources and tasks used to model the\n * execution dependency graph of the page. A node has a unique identifier and can depend on other\n * nodes/be depended on. The construction of the graph maintains some important invariants that are\n * inherent to the model:\n *\n * 1. The graph is a DAG, there are no cycles.\n * 2. There is always a root node upon which all other nodes eventually depend.\n *\n * This allows particular optimizations in this class so that we do no need to check for cycles as\n * these methods are called and we can always start traversal at the root node.\n */\n\nclass BaseNode<T = Lantern.AnyNetworkObject> {\n static types = {\n NETWORK: 'network',\n CPU: 'cpu',\n } as const;\n\n _id: string;\n _isMainDocument: boolean;\n _dependents: Node[];\n _dependencies: Node[];\n\n constructor(id: string) {\n this._id = id;\n this._isMainDocument = false;\n this._dependents = [];\n this._dependencies = [];\n }\n\n get id(): string {\n return this._id;\n }\n\n get type(): 'network'|'cpu' {\n throw new Error('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get startTime(): number {\n throw new Error('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get endTime(): number {\n throw new Error('Unimplemented');\n }\n\n setIsMainDocument(value: boolean): void {\n this._isMainDocument = value;\n }\n\n isMainDocument(): boolean {\n return this._isMainDocument;\n }\n\n getDependents(): Node[] {\n return this._dependents.slice();\n }\n\n getNumberOfDependents(): number {\n return this._dependents.length;\n }\n\n getDependencies(): Node[] {\n return this._dependencies.slice();\n }\n\n getNumberOfDependencies(): number {\n return this._dependencies.length;\n }\n\n getRootNode(): Node<T> {\n let rootNode = this as BaseNode as Node;\n while (rootNode._dependencies.length) {\n rootNode = rootNode._dependencies[0];\n }\n\n return rootNode;\n }\n\n addDependent(node: Node): void {\n node.addDependency(this as BaseNode as Node);\n }\n\n addDependency(node: Node): void {\n // @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.\n if (node === this) {\n throw new Error('Cannot add dependency on itself');\n }\n\n if (this._dependencies.includes(node)) {\n return;\n }\n\n node._dependents.push(this as BaseNode as Node);\n this._dependencies.push(node);\n }\n\n removeDependent(node: Node): void {\n node.removeDependency(this as BaseNode as Node);\n }\n\n removeDependency(node: Node): void {\n if (!this._dependencies.includes(node)) {\n return;\n }\n\n const thisIndex = node._dependents.indexOf(this as BaseNode as Node);\n node._dependents.splice(thisIndex, 1);\n this._dependencies.splice(this._dependencies.indexOf(node), 1);\n }\n\n removeAllDependencies(): void {\n for (const node of this._dependencies.slice()) {\n this.removeDependency(node);\n }\n }\n\n /**\n * Computes whether the given node is anywhere in the dependency graph of this node.\n * While this method can prevent cycles, it walks the graph and should be used sparingly.\n * Nodes are always considered dependent on themselves for the purposes of cycle detection.\n */\n isDependentOn(node: BaseNode<T>): boolean {\n let isDependentOnNode = false;\n this.traverse(\n currentNode => {\n if (isDependentOnNode) {\n return;\n }\n isDependentOnNode = currentNode === node;\n },\n currentNode => {\n // If we've already found the dependency, don't traverse further.\n if (isDependentOnNode) {\n return [];\n }\n // Otherwise, traverse the dependencies.\n return currentNode.getDependencies();\n });\n\n return isDependentOnNode;\n }\n\n /**\n * Clones the node's information without adding any dependencies/dependents.\n */\n cloneWithoutRelationships(): Node<T> {\n const node = new BaseNode(this.id) as Node<T>;\n node.setIsMainDocument(this._isMainDocument);\n return node;\n }\n\n /**\n * Clones the entire graph connected to this node filtered by the optional predicate. If a node is\n * included by the predicate, all nodes along the paths between the node and the root will be included. If the\n * node this was called on is not included in the resulting filtered graph, the method will throw.\n */\n cloneWithRelationships(predicate?: (arg0: Node) => boolean): Node {\n const rootNode = this.getRootNode();\n\n const idsToIncludedClones = new Map<string, Node>();\n\n // Walk down dependents.\n rootNode.traverse(node => {\n if (idsToIncludedClones.has(node.id)) {\n return;\n }\n\n if (predicate === undefined) {\n // No condition for entry, so clone every node.\n idsToIncludedClones.set(node.id, node.cloneWithoutRelationships());\n return;\n }\n\n if (predicate(node)) {\n // Node included, so walk back up dependencies, cloning nodes from here back to the root.\n node.traverse(\n node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),\n // Dependencies already cloned have already cloned ancestors, so no need to visit again.\n node => node._dependencies.filter(parent => !idsToIncludedClones.has(parent.id)),\n );\n }\n });\n\n // Copy dependencies between nodes.\n rootNode.traverse(originalNode => {\n const clonedNode = idsToIncludedClones.get(originalNode.id);\n if (!clonedNode) {\n return;\n }\n\n for (const dependency of originalNode._dependencies) {\n const clonedDependency = idsToIncludedClones.get(dependency.id);\n if (!clonedDependency) {\n throw new Error('Dependency somehow not cloned');\n }\n clonedNode.addDependency(clonedDependency);\n }\n });\n\n const clonedThisNode = idsToIncludedClones.get(this.id);\n if (!clonedThisNode) {\n throw new Error('Cloned graph missing node');\n }\n return clonedThisNode;\n }\n\n /**\n * Traverses all connected nodes in BFS order, calling `callback` exactly once\n * on each. `traversalPath` is the shortest (though not necessarily unique)\n * path from `node` to the root of the iteration.\n *\n * The `getNextNodes` function takes a visited node and returns which nodes to\n * visit next. It defaults to returning the node's dependents.\n */\n traverse(callback: (node: Node<T>, traversalPath: Node<T>[]) => void, getNextNodes?: (arg0: Node<T>) => Node<T>[]):\n void {\n for (const {node, traversalPath} of this.traverseGenerator(getNextNodes)) {\n callback(node, traversalPath);\n }\n }\n\n /**\n * @see BaseNode.traverse\n */\n // clang-format off\n *traverseGenerator(getNextNodes?: (arg0: Node) => Node[]):\n Generator<{node: Node, traversalPath: Node[]}, void, unknown> {\n // clang-format on\n if (!getNextNodes) {\n getNextNodes = node => node.getDependents();\n }\n\n // @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one\n const queue: Node[][] = [[this]];\n const visited = new Set([this.id]);\n\n while (queue.length) {\n // @ts-expect-error - queue has length so it's guaranteed to have an item\n const traversalPath: Node[] = queue.shift();\n const node = traversalPath[0];\n yield {node, traversalPath};\n\n for (const nextNode of getNextNodes(node)) {\n if (visited.has(nextNode.id)) {\n continue;\n }\n visited.add(nextNode.id);\n\n queue.push([nextNode, ...traversalPath]);\n }\n }\n }\n\n /**\n * Returns whether the given node has a cycle in its dependent graph by performing a DFS.\n */\n static hasCycle(node: Node, direction: 'dependents'|'dependencies'|'both' = 'both'): boolean {\n // Checking 'both' is the default entrypoint to recursively check both directions\n if (direction === 'both') {\n return BaseNode.hasCycle(node, 'dependents') || BaseNode.hasCycle(node, 'dependencies');\n }\n\n const visited = new Set();\n const currentPath: BaseNode[] = [];\n const toVisit = [node];\n const depthAdded = new Map([[node, 0]]);\n\n // Keep going while we have nodes to visit in the stack\n while (toVisit.length) {\n // Get the last node in the stack (DFS uses stack, not queue)\n // @ts-expect-error - toVisit has length so it's guaranteed to have an item\n const currentNode: BaseNode = toVisit.pop();\n\n // We've hit a cycle if the node we're visiting is in our current dependency path\n if (currentPath.includes(currentNode)) {\n return true;\n }\n // If we've already visited the node, no need to revisit it\n if (visited.has(currentNode)) {\n continue;\n }\n\n // Since we're visiting this node, clear out any nodes in our path that we had to backtrack\n // @ts-expect-error\n while (currentPath.length > depthAdded.get(currentNode)) {\n currentPath.pop();\n }\n\n // Update our data structures to reflect that we're adding this node to our path\n visited.add(currentNode);\n currentPath.push(currentNode);\n\n // Add all of its dependents to our toVisit stack\n const nodesToExplore = direction === 'dependents' ? currentNode._dependents : currentNode._dependencies;\n for (const nextNode of nodesToExplore) {\n if (toVisit.includes(nextNode)) {\n continue;\n }\n toVisit.push(nextNode);\n depthAdded.set(nextNode, currentPath.length);\n }\n }\n\n return false;\n }\n\n canDependOn(node: Node): boolean {\n return node.startTime <= this.startTime;\n }\n}\n\nexport {BaseNode};\n"]}
|