Skip to content

Commit

Permalink
core(lantern): remove usage of Lighthouse constants module (#16062)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 11, 2024
1 parent 34d913c commit a0d78ce
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
45 changes: 2 additions & 43 deletions core/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Adjustments needed for DevTools network throttling to simulate
* more realistic network conditions.
* @see https://crbug.com/721112
* @see https://docs.google.com/document/d/10lfVdS1iDWCRKQXPfbxEn4Or99D64mvNlugP1AQuFlE/edit
*/
const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75;
const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9;
import * as Lantern from '../lib/lantern/lantern.js';

const throttling = {
DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
// These values align with WebPageTest's definition of "Fast 3G"
// But offer similar characteristics to roughly the 75th percentile of 4G connections.
mobileSlow4G: {
rttMs: 150,
throughputKbps: 1.6 * 1024,
requestLatencyMs: 150 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
downloadThroughputKbps: 1.6 * 1024 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
uploadThroughputKbps: 750 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
cpuSlowdownMultiplier: 4,
},
// These values partially align with WebPageTest's definition of "Regular 3G".
// These values are meant to roughly align with Chrome UX report's 3G definition which are based
// on HTTP RTT of 300-1400ms and downlink throughput of <700kbps.
mobileRegular3G: {
rttMs: 300,
throughputKbps: 700,
requestLatencyMs: 300 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
downloadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
uploadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
cpuSlowdownMultiplier: 4,
},
// Using a "broadband" connection type
// Corresponds to "Dense 4G 25th percentile" in https://docs.google.com/document/d/1Ft1Bnq9-t4jK5egLSOc28IL4TvR-Tt0se_1faTA4KTY/edit#heading=h.bb7nfy2x9e5v
desktopDense4G: {
rttMs: 40,
throughputKbps: 10 * 1024,
cpuSlowdownMultiplier: 1,
requestLatencyMs: 0, // 0 means unset
downloadThroughputKbps: 0,
uploadThroughputKbps: 0,
},
};
const throttling = Lantern.constants.throttling;

/**
* @type {Required<LH.SharedFlagsSettings['screenEmulation']>}
Expand Down
42 changes: 42 additions & 0 deletions core/lib/lantern/lantern.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,48 @@ const NetworkRequestTypes = {
Prefetch: 'Prefetch',
};

const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75;
const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9;

const throttling = {
DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
// These values align with WebPageTest's definition of "Fast 3G"
// But offer similar characteristics to roughly the 75th percentile of 4G connections.
mobileSlow4G: {
rttMs: 150,
throughputKbps: 1.6 * 1024,
requestLatencyMs: 150 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
downloadThroughputKbps: 1.6 * 1024 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
uploadThroughputKbps: 750 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
cpuSlowdownMultiplier: 4,
},
// These values partially align with WebPageTest's definition of "Regular 3G".
// These values are meant to roughly align with Chrome UX report's 3G definition which are based
// on HTTP RTT of 300-1400ms and downlink throughput of <700kbps.
mobileRegular3G: {
rttMs: 300,
throughputKbps: 700,
requestLatencyMs: 300 * DEVTOOLS_RTT_ADJUSTMENT_FACTOR,
downloadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
uploadThroughputKbps: 700 * DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR,
cpuSlowdownMultiplier: 4,
},
// Using a "broadband" connection type
// Corresponds to "Dense 4G 25th percentile" in https://docs.google.com/document/d/1Ft1Bnq9-t4jK5egLSOc28IL4TvR-Tt0se_1faTA4KTY/edit#heading=h.bb7nfy2x9e5v
desktopDense4G: {
rttMs: 40,
throughputKbps: 10 * 1024,
cpuSlowdownMultiplier: 1,
requestLatencyMs: 0, // 0 means unset
downloadThroughputKbps: 0,
uploadThroughputKbps: 0,
},
};

const constants = {throttling};

export {
NetworkRequestTypes,
constants,
};
10 changes: 5 additions & 5 deletions core/lib/lantern/simulator/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {TcpConnection} from './tcp-connection.js';
import {ConnectionPool} from './connection-pool.js';
import {DNSCache} from './dns-cache.js';
import {SimulatorTimingMap} from './simulator-timing-map.js';
import * as constants from '../../../config/constants.js';
import {constants} from '../lantern.js';

const mobileSlow4G = constants.throttling.mobileSlow4G;
const defaultThrottling = constants.throttling.mobileSlow4G;

/** @typedef {import('../base-node.js').Node} Node */
/** @typedef {import('../network-node.js').NetworkNode} NetworkNode */
Expand Down Expand Up @@ -113,10 +113,10 @@ class Simulator {
/** @type {Required<Lantern.Simulation.Options>} */
this._options = Object.assign(
{
rtt: mobileSlow4G.rttMs,
throughput: mobileSlow4G.throughputKbps * 1024,
rtt: defaultThrottling.rttMs,
throughput: defaultThrottling.throughputKbps * 1024,
maximumConcurrentRequests: DEFAULT_MAXIMUM_CONCURRENT_REQUESTS,
cpuSlowdownMultiplier: mobileSlow4G.cpuSlowdownMultiplier,
cpuSlowdownMultiplier: defaultThrottling.cpuSlowdownMultiplier,
layoutTaskMultiplier: DEFAULT_LAYOUT_TASK_MULTIPLIER,
additionalRttByOrigin: new Map(),
serverResponseTimeByOrigin: new Map(),
Expand Down
2 changes: 1 addition & 1 deletion core/test/lib/lantern/metrics/speed-index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as constants from '../../../../config/constants.js';
import {readJson} from '../../../test-utils.js';
import {SpeedIndex} from '../../../../lib/lantern/metrics/speed-index.js';
import {FirstContentfulPaint} from '../../../../lib/lantern/metrics/first-contentful-paint.js';
import {getComputationDataFromFixture} from './metric-test-utils.js';
import {constants} from '../../../../lib/lantern/lantern.js';

const trace = readJson('../../../fixtures/artifacts/progressive-app/trace.json', import.meta);

Expand Down

0 comments on commit a0d78ce

Please sign in to comment.