Skip to content

Commit

Permalink
core(lantern): remove all LH types (#16061)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Jun 11, 2024
1 parent 32cafcb commit 5ef22db
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
vars: 'all',
args: 'after-used',
argsIgnorePattern: '(^reject$|^_+$)',
varsIgnorePattern: '(^_$|^LH$|^Lantern$|^TraceEngine$)',
varsIgnorePattern: '(^_$|^LH$|^Lantern$|^TraceEngine$|^Protocol$)',
}],
'no-cond-assign': 2,
'space-infix-ops': 2,
Expand Down
9 changes: 5 additions & 4 deletions core/audits/long-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../lib/lantern/types/lantern.js';
import {Audit} from './audit.js';
import {NetworkRecords} from '../computed/network-records.js';
import * as i18n from '../lib/i18n/i18n.js';
Expand Down Expand Up @@ -85,7 +86,7 @@ class LongTasks extends Audit {
* most time will be attributed to 'other' (the category of the top-level
* RunTask). See pruning in `PageDependencyGraph.linkCPUNodes`.
* @param {LH.Artifacts.TaskNode} task
* @param {Map<LH.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} taskTimingsByEvent
* @param {Map<Lantern.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} taskTimingsByEvent
* @param {Map<TaskGroupIds, number>} [timeByTaskGroup]
* @return {{startTime: number, duration: number, timeByTaskGroup: Map<TaskGroupIds, number>}}
*/
Expand Down Expand Up @@ -116,7 +117,7 @@ class LongTasks extends Audit {
/**
* @param {Array<LH.Artifacts.TaskNode>} longTasks
* @param {Set<string>} jsUrls
* @param {Map<LH.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} taskTimingsByEvent
* @param {Map<Lantern.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} taskTimingsByEvent
* @return {LH.Audit.Details.DebugData}
*/
static makeDebugData(longTasks, jsUrls, taskTimingsByEvent) {
Expand Down Expand Up @@ -154,7 +155,7 @@ class LongTasks extends Audit {
/**
* Get timing from task, overridden by taskTimingsByEvent if provided.
* @param {LH.Artifacts.TaskNode} task
* @param {Map<LH.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} taskTimingsByEvent
* @param {Map<Lantern.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} taskTimingsByEvent
* @return {Timing}
*/
static getTiming(task, taskTimingsByEvent) {
Expand Down Expand Up @@ -184,7 +185,7 @@ class LongTasks extends Audit {
const metricComputationData = Audit.makeMetricComputationDataInput(artifacts, context);
const tbtResult = await TotalBlockingTime.request(metricComputationData, context);

/** @type {Map<LH.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} */
/** @type {Map<Lantern.TraceEvent, LH.Gatherer.Simulation.NodeTiming>|undefined} */
let taskTimingsByEvent;

if (settings.throttlingMethod === 'simulate') {
Expand Down
3 changes: 2 additions & 1 deletion core/computed/tbt-impact-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as Lantern from '../lib/lantern/types/lantern.js';
import {makeComputedArtifact} from './computed-artifact.js';
import {MainThreadTasks} from './main-thread-tasks.js';
import {FirstContentfulPaint} from './metrics/first-contentful-paint.js';
Expand Down Expand Up @@ -132,7 +133,7 @@ class TBTImpactTasks {
/** @type {Map<LH.Artifacts.TaskNode, {start: number, end: number, duration: number}>} */
const topLevelTaskToEvent = new Map();

/** @type {Map<LH.TraceEvent, LH.Artifacts.TaskNode>} */
/** @type {Map<Lantern.TraceEvent, LH.Artifacts.TaskNode>} */
const traceEventToTask = new Map();
for (const task of tasks) {
traceEventToTask.set(task.event, task);
Expand Down
2 changes: 1 addition & 1 deletion core/lib/lantern-trace-saver.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function convertNodeTimingsToTrace(nodeTimings) {
const ts = eventTs + (event.ts - nestedBaseTs) * multiplier;
const newEvent = {...event, ...{pid: baseEvent.pid, tid: baseEvent.tid}, ts};
if (event.dur) newEvent.dur = event.dur * multiplier;
events.push(newEvent);
events.push(/** @type {LH.TraceEvent} */(newEvent));
}

return events;
Expand Down
10 changes: 5 additions & 5 deletions core/lib/lantern/cpu-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as LH from '../../../types/lh.js';
import * as Lantern from './types/lantern.js';
import {BaseNode} from './base-node.js';

/**
Expand All @@ -13,8 +13,8 @@ import {BaseNode} from './base-node.js';
*/
class CPUNode extends BaseNode {
/**
* @param {LH.TraceEvent} parentEvent
* @param {LH.TraceEvent[]=} childEvents
* @param {Lantern.TraceEvent} parentEvent
* @param {Lantern.TraceEvent[]=} childEvents
* @param {number=} correctedEndTs
*/
constructor(parentEvent, childEvents = [], correctedEndTs) {
Expand Down Expand Up @@ -53,14 +53,14 @@ class CPUNode extends BaseNode {
}

/**
* @return {LH.TraceEvent}
* @return {Lantern.TraceEvent}
*/
get event() {
return this._event;
}

/**
* @return {LH.TraceEvent[]}
* @return {Lantern.TraceEvent[]}
*/
get childEvents() {
return this._childEvents;
Expand Down
4 changes: 3 additions & 1 deletion core/lib/lantern/lantern.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

/** @type {LH.Util.SelfMap<LH.Crdp.Network.ResourceType>} */
import * as Lantern from './types/lantern.js';

/** @type {Lantern.Util.SelfMap<Lantern.ResourceType>} */
const NetworkRequestTypes = {
XHR: 'XHR',
Fetch: 'Fetch',
Expand Down
8 changes: 4 additions & 4 deletions core/lib/lantern/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {RESOURCE_TYPES} from '../../lib/network-request.js';
/**
* @typedef Extras
* @property {boolean} optimistic
* @property {LH.Artifacts.LanternMetric=} fcpResult
* @property {LH.Artifacts.LanternMetric=} lcpResult
* @property {LH.Artifacts.LanternMetric=} interactiveResult
* @property {Lantern.Metric=} fcpResult
* @property {Lantern.Metric=} lcpResult
* @property {Lantern.Metric=} interactiveResult
* @property {number=} observedSpeedIndex
*/

Expand Down Expand Up @@ -92,7 +92,7 @@ class Metric {
/**
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
* @return {Promise<Lantern.Metric>}
*/
static async compute(data, extras) {
const {simulator, graph, processedNavigation} = data;
Expand Down
10 changes: 5 additions & 5 deletions core/lib/lantern/metrics/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CRITICAL_LONG_TASK_THRESHOLD = 20;

class Interactive extends Metric {
/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
return {
Expand Down Expand Up @@ -61,9 +61,9 @@ class Interactive extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result} simulationResult
* @param {Lantern.Simulation.Result} simulationResult
* @param {import('../metric.js').Extras} extras
* @return {LH.Gatherer.Simulation.Result}
* @return {Lantern.Simulation.Result}
*/
static getEstimateFromSimulation(simulationResult, extras) {
if (!extras.lcpResult) throw new Error('missing lcpResult');
Expand All @@ -81,7 +81,7 @@ class Interactive extends Metric {
/**
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
* @return {Promise<Lantern.Metric>}
*/
static async compute(data, extras) {
const lcpResult = extras?.lcpResult;
Expand All @@ -95,7 +95,7 @@ class Interactive extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
* @param {Lantern.Simulation.Result['nodeTimings']} nodeTimings
* @return {number}
*/
static getLastLongTaskEndTime(nodeTimings, duration = 50) {
Expand Down
8 changes: 4 additions & 4 deletions core/lib/lantern/metrics/largest-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {LanternError} from '../lantern-error.js';

class LargestContentfulPaint extends Metric {
/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
return {
Expand Down Expand Up @@ -74,8 +74,8 @@ class LargestContentfulPaint extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result} simulationResult
* @return {LH.Gatherer.Simulation.Result}
* @param {Lantern.Simulation.Result} simulationResult
* @return {Lantern.Simulation.Result}
*/
static getEstimateFromSimulation(simulationResult) {
const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())
Expand All @@ -91,7 +91,7 @@ class LargestContentfulPaint extends Metric {
/**
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
* @return {Promise<Lantern.Metric>}
*/
static async compute(data, extras) {
const fcpResult = extras?.fcpResult;
Expand Down
10 changes: 5 additions & 5 deletions core/lib/lantern/metrics/max-potential-fid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {BaseNode} from '../base-node.js';

class MaxPotentialFID extends Metric {
/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
return {
Expand All @@ -39,9 +39,9 @@ class MaxPotentialFID extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result} simulation
* @param {Lantern.Simulation.Result} simulation
* @param {import('../metric.js').Extras} extras
* @return {LH.Gatherer.Simulation.Result}
* @return {Lantern.Simulation.Result}
*/
static getEstimateFromSimulation(simulation, extras) {
if (!extras.fcpResult) throw new Error('missing fcpResult');
Expand All @@ -66,7 +66,7 @@ class MaxPotentialFID extends Metric {
/**
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
* @return {Promise<Lantern.Metric>}
*/
static compute(data, extras) {
const fcpResult = extras?.fcpResult;
Expand All @@ -78,7 +78,7 @@ class MaxPotentialFID extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
* @param {Lantern.Simulation.Result['nodeTimings']} nodeTimings
* @param {number} fcpTimeInMs
* @return {Array<{duration: number}>}
*/
Expand Down
12 changes: 6 additions & 6 deletions core/lib/lantern/metrics/speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mobileSlow4GRtt = 150;

class SpeedIndex extends Metric {
/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
return {
Expand All @@ -28,7 +28,7 @@ class SpeedIndex extends Metric {

/**
* @param {number} rttMs
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static getScaledCoefficients(rttMs) { // eslint-disable-line no-unused-vars
// We want to scale our default coefficients based on the speed of the connection.
Expand Down Expand Up @@ -70,9 +70,9 @@ class SpeedIndex extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result} simulationResult
* @param {Lantern.Simulation.Result} simulationResult
* @param {import('../metric.js').Extras} extras
* @return {LH.Gatherer.Simulation.Result}
* @return {Lantern.Simulation.Result}
*/
static getEstimateFromSimulation(simulationResult, extras) {
if (!extras.fcpResult) throw new Error('missing fcpResult');
Expand All @@ -91,7 +91,7 @@ class SpeedIndex extends Metric {
/**
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
* @return {Promise<Lantern.Metric>}
*/
static async compute(data, extras) {
const fcpResult = extras?.fcpResult;
Expand All @@ -115,7 +115,7 @@ class SpeedIndex extends Metric {
* different methods. Read more in the evaluation doc.
*
* @see https://docs.google.com/document/d/1qJWXwxoyVLVadezIp_Tgdk867G3tDNkkVRvUJSH3K1E/edit#
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
* @param {Lantern.Simulation.Result['nodeTimings']} nodeTimings
* @param {number} fcpTimeInMs
* @return {number}
*/
Expand Down
10 changes: 5 additions & 5 deletions core/lib/lantern/metrics/total-blocking-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {BLOCKING_TIME_THRESHOLD, calculateSumOfBlockingTime} from '../tbt-utils.

class TotalBlockingTime extends Metric {
/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
return {
Expand All @@ -40,9 +40,9 @@ class TotalBlockingTime extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result} simulation
* @param {Lantern.Simulation.Result} simulation
* @param {import('../metric.js').Extras} extras
* @return {LH.Gatherer.Simulation.Result}
* @return {Lantern.Simulation.Result}
*/
static getEstimateFromSimulation(simulation, extras) {
if (!extras.fcpResult) throw new Error('missing fcpResult');
Expand Down Expand Up @@ -84,7 +84,7 @@ class TotalBlockingTime extends Metric {
/**
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<import('../metric.js').Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
* @return {Promise<Lantern.Metric>}
*/
static async compute(data, extras) {
const fcpResult = extras?.fcpResult;
Expand All @@ -101,7 +101,7 @@ class TotalBlockingTime extends Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result['nodeTimings']} nodeTimings
* @param {Lantern.Simulation.Result['nodeTimings']} nodeTimings
* @param {number} minDurationMs
*/
static getTopLevelEvents(nodeTimings, minDurationMs) {
Expand Down
Loading

0 comments on commit 5ef22db

Please sign in to comment.