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): move types to lib/lantern #15859

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions core/computed/load-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as constants from '../config/constants.js';
import {Simulator} from '../lib/lantern/simulator/simulator.js';
import {NetworkAnalysis} from './network-analysis.js';

/** @typedef {import('../../types/internal/lantern.js').Lantern.Simulation.Options} SimulationOptions */

class LoadSimulator {
/**
* @param {{devtoolsLog: LH.DevtoolsLog, settings: LH.Audit.Context['settings']}} data
Expand All @@ -21,7 +19,7 @@ class LoadSimulator {
const {throttlingMethod, throttling, precomputedLanternData} = data.settings;
const networkAnalysis = await NetworkAnalysis.request(data.devtoolsLog, context);

/** @type {SimulationOptions} */
/** @type {Lantern.Simulation.Options} */
const options = {
additionalRttByOrigin: networkAnalysis.additionalRttByOrigin,
serverResponseTimeByOrigin: networkAnalysis.serverResponseTimeByOrigin,
Expand Down
11 changes: 5 additions & 6 deletions core/lib/lantern/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {NetworkRequest} from '../../lib/network-request.js';
/** @typedef {import('./base-node.js').Node} Node */
/** @typedef {import('./network-node.js').NetworkNode} NetworkNode */
/** @typedef {import('./simulator/simulator.js').Simulator} Simulator */
/** @typedef {import('../../../types/internal/lantern.js').Lantern.Simulation.MetricComputationDataInput} MetricComputationDataInput */

/**
* @typedef Extras
Expand Down Expand Up @@ -43,7 +42,7 @@ class Metric {
}

/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static get COEFFICIENTS() {
throw new Error('COEFFICIENTS unimplemented!');
Expand All @@ -56,7 +55,7 @@ class Metric {
* settings change.
*
* @param {number} rttMs
* @return {LH.Gatherer.Simulation.MetricCoefficients}
* @return {Lantern.Simulation.MetricCoefficients}
*/
static getScaledCoefficients(rttMs) { // eslint-disable-line no-unused-vars
return this.COEFFICIENTS;
Expand All @@ -81,16 +80,16 @@ class Metric {
}

/**
* @param {LH.Gatherer.Simulation.Result} simulationResult
* @param {Lantern.Simulation.Result} simulationResult
* @param {Extras} extras
* @return {LH.Gatherer.Simulation.Result}
* @return {Lantern.Simulation.Result}
*/
static getEstimateFromSimulation(simulationResult, extras) { // eslint-disable-line no-unused-vars
return simulationResult;
}

/**
* @param {MetricComputationDataInput} data
* @param {Lantern.Simulation.MetricComputationDataInput} data
* @param {Omit<Extras, 'optimistic'>=} extras
* @return {Promise<LH.Artifacts.LanternMetric>}
*/
Expand Down
6 changes: 2 additions & 4 deletions core/lib/lantern/network-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/** @template T @typedef {import('../../../types/internal/lantern.js').Lantern.NetworkRequest<T>} NetworkRequest */

import {NetworkRequestTypes} from './lantern.js';
import {BaseNode} from './base-node.js';
// TODO(15841): bring impl of isNonNetworkRequest inside lantern and remove this.
Expand All @@ -17,7 +15,7 @@ import UrlUtils from '../url-utils.js';
*/
class NetworkNode extends BaseNode {
/**
* @param {NetworkRequest<T>} networkRequest
* @param {Lantern.NetworkRequest<T>} networkRequest
*/
constructor(networkRequest) {
super(networkRequest.requestId);
Expand Down Expand Up @@ -51,7 +49,7 @@ class NetworkNode extends BaseNode {
}

/**
* @return {NetworkRequest<T>}
* @return {Lantern.NetworkRequest<T>}
*/
get request() {
return this._request;
Expand Down
7 changes: 3 additions & 4 deletions core/lib/lantern/page-dependency-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {CPUNode} from './cpu-node.js';
import {TraceProcessor} from '../tracehouse/trace-processor.js';
import {NetworkAnalyzer} from './simulator/network-analyzer.js';

/** @typedef {import('../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
/** @typedef {import('./base-node.js').Node} Node */
/** @typedef {Omit<LH.Artifacts['URL'], 'finalDisplayedUrl'>} URLArtifact */

Expand All @@ -31,7 +30,7 @@ const IGNORED_MIME_TYPES_REGEX = /^video/;

class PageDependencyGraph {
/**
* @param {NetworkRequest} record
* @param {Lantern.NetworkRequest} record
* @return {Array<string>}
*/
static getNetworkInitiators(record) {
Expand Down Expand Up @@ -60,7 +59,7 @@ class PageDependencyGraph {
}

/**
* @param {Array<NetworkRequest>} networkRecords
* @param {Array<Lantern.NetworkRequest>} networkRecords
* @return {NetworkNodeOutput}
*/
static getNetworkNodeOutput(networkRecords) {
Expand Down Expand Up @@ -394,7 +393,7 @@ class PageDependencyGraph {

/**
* @param {LH.Artifacts.ProcessedTrace} processedTrace
* @param {Array<NetworkRequest>} networkRecords
* @param {Array<Lantern.NetworkRequest>} networkRecords
* @param {URLArtifact} URL
* @return {Node}
*/
Expand Down
15 changes: 6 additions & 9 deletions core/lib/lantern/simulator/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */
/** @typedef {import('../../../../types/internal/lantern.js').Lantern.Simulation.Options} SimulationOptions */

import {NetworkAnalyzer} from './network-analyzer.js';
import {TcpConnection} from './tcp-connection.js';

Expand All @@ -19,16 +16,16 @@ const CONNECTIONS_PER_ORIGIN = 6;

export class ConnectionPool {
/**
* @param {NetworkRequest[]} records
* @param {Required<SimulationOptions>} options
* @param {Lantern.NetworkRequest[]} records
* @param {Required<Lantern.Simulation.Options>} options
*/
constructor(records, options) {
this._options = options;

this._records = records;
/** @type {Map<string, TcpConnection[]>} */
this._connectionsByOrigin = new Map();
/** @type {Map<NetworkRequest, TcpConnection>} */
/** @type {Map<Lantern.NetworkRequest, TcpConnection>} */
this._connectionsByRecord = new Map();
this._connectionsInUse = new Set();
this._connectionReusedByRequestId = NetworkAnalyzer.estimateIfConnectionWasReused(records, {
Expand Down Expand Up @@ -126,7 +123,7 @@ export class ConnectionPool {
* If ignoreConnectionReused is true, acquire will consider all connections not in use as available.
* Otherwise, only connections that have matching "warmth" are considered available.
*
* @param {NetworkRequest} record
* @param {Lantern.NetworkRequest} record
* @param {{ignoreConnectionReused?: boolean}} options
* @return {?TcpConnection}
*/
Expand All @@ -152,7 +149,7 @@ export class ConnectionPool {
* Return the connection currently being used to fetch a record. If no connection
* currently being used for this record, an error will be thrown.
*
* @param {NetworkRequest} record
* @param {Lantern.NetworkRequest} record
* @return {TcpConnection}
*/
acquireActiveConnectionFromRecord(record) {
Expand All @@ -163,7 +160,7 @@ export class ConnectionPool {
}

/**
* @param {NetworkRequest} record
* @param {Lantern.NetworkRequest} record
*/
release(record) {
const connection = this._connectionsByRecord.get(record);
Expand Down
6 changes: 2 additions & 4 deletions core/lib/lantern/simulator/dns-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */

// A DNS lookup will usually take ~1-2 roundtrips of connection latency plus the extra DNS routing time.
// Example: https://www.webpagetest.org/result/180703_3A_e33ec79747c002ed4d7bcbfc81462203/1/details/#waterfall_view_step1
// Example: https://www.webpagetest.org/result/180707_1M_89673eb633b5d98386de95dfcf9b33d5/1/details/#waterfall_view_step1
Expand All @@ -25,7 +23,7 @@ class DNSCache {
}

/**
* @param {NetworkRequest} request
* @param {Lantern.NetworkRequest} request
* @param {{requestedAt: number, shouldUpdateCache: boolean}=} options
* @return {number}
*/
Expand All @@ -47,7 +45,7 @@ class DNSCache {
}

/**
* @param {NetworkRequest} request
* @param {Lantern.NetworkRequest} request
* @param {number} resolvedAt
*/
_updateCacheResolvedAtIfNeeded(request, resolvedAt) {
Expand Down
28 changes: 13 additions & 15 deletions core/lib/lantern/simulator/network-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

/** @typedef {import('../../../../types/internal/lantern.js').Lantern.NetworkRequest} NetworkRequest */

import UrlUtils from '../../url-utils.js';

const INITIAL_CWD = 14 * 1024;
Expand Down Expand Up @@ -33,8 +31,8 @@ class NetworkAnalyzer {
}

/**
* @param {NetworkRequest[]} records
* @return {Map<string, NetworkRequest[]>}
* @param {Lantern.NetworkRequest[]} records
* @return {Map<string, Lantern.NetworkRequest[]>}
*/
static groupByOrigin(records) {
const grouped = new Map();
Expand Down Expand Up @@ -89,10 +87,10 @@ class NetworkAnalyzer {
return summaryByKey;
}

/** @typedef {{record: NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */
/** @typedef {{record: Lantern.NetworkRequest, timing: LH.Crdp.Network.ResourceTiming, connectionReused?: boolean}} RequestInfo */

/**
* @param {NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @param {(e: RequestInfo) => number | number[] | undefined} iteratee
* @return {Map<string, number[]>}
*/
Expand Down Expand Up @@ -251,7 +249,7 @@ class NetworkAnalyzer {
/**
* Given the RTT to each origin, estimates the observed server response times.
*
* @param {NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @param {Map<string, number>} rttByOrigin
* @return {Map<string, number[]>}
*/
Expand All @@ -272,7 +270,7 @@ class NetworkAnalyzer {
}

/**
* @param {NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @return {boolean}
*/
static canTrustConnectionInformation(records) {
Expand All @@ -292,7 +290,7 @@ class NetworkAnalyzer {
* Returns a map of requestId -> connectionReused, estimating the information if the information
* available in the records themselves appears untrustworthy.
*
* @param {NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @param {{forceCoarseEstimates: boolean}} [options]
* @return {Map<string, boolean>}
*/
Expand Down Expand Up @@ -336,7 +334,7 @@ class NetworkAnalyzer {
* Attempts to use the most accurate information first and falls back to coarser estimates when it
* is unavailable.
*
* @param {NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @param {RTTEstimateOptions} [options]
* @return {Map<string, Summary>}
*/
Expand Down Expand Up @@ -417,7 +415,7 @@ class NetworkAnalyzer {
* Estimates the server response time of each origin. RTT times can be passed in or will be
* estimated automatically if not provided.
*
* @param {NetworkRequest[]} records
* @param {Lantern.NetworkRequest[]} records
* @param {RTTEstimateOptions & {rttByOrigin?: Map<string, number>}} [options]
* @return {Map<string, Summary>}
*/
Expand All @@ -443,7 +441,7 @@ class NetworkAnalyzer {
* Excludes data URI, failed or otherwise incomplete, and cached requests.
* Returns Infinity if there were no analyzable network records.
*
* @param {Array<NetworkRequest>} networkRecords
* @param {Array<Lantern.NetworkRequest>} networkRecords
* @return {number}
*/
static estimateThroughput(networkRecords) {
Expand Down Expand Up @@ -496,7 +494,7 @@ class NetworkAnalyzer {
}

/**
* @template {NetworkRequest} T
* @template {Lantern.NetworkRequest} T
* @param {Array<T>} records
* @param {string} resourceUrl
* @return {T|undefined}
Expand All @@ -510,7 +508,7 @@ class NetworkAnalyzer {
}

/**
* @template {NetworkRequest} T
* @template {Lantern.NetworkRequest} T
* @param {Array<T>} records
* @param {string} resourceUrl
* @return {T|undefined}
Expand All @@ -530,7 +528,7 @@ class NetworkAnalyzer {
* Resolves redirect chain given a main document.
* See: {@link NetworkAnalyzer.findLastDocumentForUrl}) for how to retrieve main document.
*
* @template {NetworkRequest} T
* @template {Lantern.NetworkRequest} T
* @param {T} request
* @return {T}
*/
Expand Down
Loading
Loading