From a0d78ce4716ca88f2c09e8cab3a8570fea85e5cb Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 11 Jun 2024 15:35:38 -0700 Subject: [PATCH] core(lantern): remove usage of Lighthouse constants module (#16062) --- core/config/constants.js | 45 +------------------ core/lib/lantern/lantern.js | 42 +++++++++++++++++ core/lib/lantern/simulator/simulator.js | 10 ++--- .../lib/lantern/metrics/speed-index-test.js | 2 +- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/core/config/constants.js b/core/config/constants.js index bfab9a94d69e..0d8da0a3a4fe 100644 --- a/core/config/constants.js +++ b/core/config/constants.js @@ -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} diff --git a/core/lib/lantern/lantern.js b/core/lib/lantern/lantern.js index 15e1954a7d40..b4c8f2e2fc69 100644 --- a/core/lib/lantern/lantern.js +++ b/core/lib/lantern/lantern.js @@ -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, }; diff --git a/core/lib/lantern/simulator/simulator.js b/core/lib/lantern/simulator/simulator.js index 620d84708d56..1329315a9c48 100644 --- a/core/lib/lantern/simulator/simulator.js +++ b/core/lib/lantern/simulator/simulator.js @@ -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 */ @@ -113,10 +113,10 @@ class Simulator { /** @type {Required} */ 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(), diff --git a/core/test/lib/lantern/metrics/speed-index-test.js b/core/test/lib/lantern/metrics/speed-index-test.js index 88a3f42ee89a..30223d2a629a 100644 --- a/core/test/lib/lantern/metrics/speed-index-test.js +++ b/core/test/lib/lantern/metrics/speed-index-test.js @@ -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);