Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(lantern): separate TraceEngine specific code #16051

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/computed/metrics/lantern-metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {LoadSimulator} from '../load-simulator.js';
import {ProcessedNavigation} from '../processed-navigation.js';
import {PageDependencyGraph} from '../page-dependency-graph.js';
import {TraceEngineResult} from '../trace-engine-result.js';
import {createProcessedNavigation} from '../../lib/lantern/lantern.js';
import {createProcessedNavigation} from '../../lib/lantern/trace-engine-computation-data.js';

/**
* @param {LH.Artifacts.MetricComputationDataInput} data
Expand Down
6 changes: 4 additions & 2 deletions core/computed/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {NetworkRequest} from '../lib/network-request.js';
import {ProcessedTrace} from './processed-trace.js';
import {NetworkRecords} from './network-records.js';
import {TraceEngineResult} from './trace-engine-result.js';
import * as TraceEngineComputationData from '../lib/lantern/trace-engine-computation-data.js';

/** @typedef {import('../lib/lantern/base-node.js').Node<LH.Artifacts.NetworkRequest>} Node */

Expand All @@ -28,8 +29,9 @@ class PageDependencyGraph {

if (data.fromTrace) {
const traceEngineResult = await TraceEngineResult.request({trace}, context);
const {graph} = await LanternPageDependencyGraph.createGraphFromTrace(
trace, traceEngineResult, URL);
const requests = TraceEngineComputationData.createNetworkRequests(trace, traceEngineResult);
const graph =
TraceEngineComputationData.createGraph(requests, trace, traceEngineResult, URL);
return graph;
}

Expand Down
47 changes: 0 additions & 47 deletions core/lib/lantern/lantern.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from './types/lantern.js';

/** @typedef {import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricName} MetricName */
/** @typedef {import('@paulirish/trace_engine/models/trace/handlers/PageLoadMetricsHandler.js').MetricScore} MetricScore */

/** @type {LH.Util.SelfMap<LH.Crdp.Network.ResourceType>} */
const NetworkRequestTypes = {
XHR: 'XHR',
Expand All @@ -31,48 +26,6 @@ const NetworkRequestTypes = {
Prefetch: 'Prefetch',
};

/**
* @param {LH.Artifacts.TraceEngineResult} traceEngineResult
* @return {Lantern.Simulation.ProcessedNavigation}
*/
function createProcessedNavigation(traceEngineResult) {
const Meta = traceEngineResult.data.Meta;
const frameId = Meta.mainFrameId;
const scoresByNav = traceEngineResult.data.PageLoadMetrics.metricScoresByFrameId.get(frameId);
if (!scoresByNav) {
throw new Error('missing metric scores for main frame');
}

const lastNavigationId = Meta.mainFrameNavigations.at(-1)?.args.data?.navigationId;
const scores = lastNavigationId && scoresByNav.get(lastNavigationId);
if (!scores) {
throw new Error('missing metric scores for specified navigation');
}

/** @param {MetricName} metric */
const getTimestampOrUndefined = metric => {
const metricScore = scores.get(metric);
if (!metricScore?.event) return;
return metricScore.event.ts;
};
/** @param {MetricName} metric */
const getTimestamp = metric => {
const metricScore = scores.get(metric);
if (!metricScore?.event) throw new Error(`missing metric: ${metric}`);
return metricScore.event.ts;
};
// TODO: should use `MetricName.LCP`, but it is a const enum.
const FCP = /** @type {MetricName} */('FCP');
const LCP = /** @type {MetricName} */('LCP');
return {
timestamps: {
firstContentfulPaint: getTimestamp(FCP),
largestContentfulPaint: getTimestampOrUndefined(LCP),
},
};
}

export {
NetworkRequestTypes,
createProcessedNavigation,
};
Loading
Loading