From 7ac9485dfdaf21e794c11333b4873f62cdb5d4c5 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 11 Jun 2024 15:17:25 -0700 Subject: [PATCH 1/3] core(lantern): remove usage of Lighthouse constants module --- core/config/constants.js | 2 ++ core/lib/lantern/lantern.js | 20 +++++++++++++++++++ core/lib/lantern/simulator/simulator.js | 14 ++++++------- .../lib/lantern/metrics/speed-index-test.js | 4 ++-- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/core/config/constants.js b/core/config/constants.js index bfab9a94d69e..fafb07bb5789 100644 --- a/core/config/constants.js +++ b/core/config/constants.js @@ -13,6 +13,8 @@ const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75; const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9; +// Notes: these throttling constants should match what is in Lantern. + const throttling = { DEVTOOLS_RTT_ADJUSTMENT_FACTOR, DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR, diff --git a/core/lib/lantern/lantern.js b/core/lib/lantern/lantern.js index 15e1954a7d40..56d155b61035 100644 --- a/core/lib/lantern/lantern.js +++ b/core/lib/lantern/lantern.js @@ -28,6 +28,26 @@ const NetworkRequestTypes = { Prefetch: 'Prefetch', }; +// These constants should all match the ones inside Lighthouse's `constants.js`. +const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75; +const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9; + +const constants = { + 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, + }, +}; + export { NetworkRequestTypes, + constants, }; diff --git a/core/lib/lantern/simulator/simulator.js b/core/lib/lantern/simulator/simulator.js index 620d84708d56..16263a63a51a 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.mobileSlow4G; /** @typedef {import('../base-node.js').Node} Node */ /** @typedef {import('../network-node.js').NetworkNode} NetworkNode */ @@ -82,10 +82,10 @@ class Simulator { case 'devtools': if (throttling) { options.rtt = - throttling.requestLatencyMs / constants.throttling.DEVTOOLS_RTT_ADJUSTMENT_FACTOR; + throttling.requestLatencyMs / constants.DEVTOOLS_RTT_ADJUSTMENT_FACTOR; options.throughput = throttling.downloadThroughputKbps * 1024 / - constants.throttling.DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR; + constants.DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR; } options.cpuSlowdownMultiplier = 1; @@ -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..20c1b9bc0a81 100644 --- a/core/test/lib/lantern/metrics/speed-index-test.js +++ b/core/test/lib/lantern/metrics/speed-index-test.js @@ -4,15 +4,15 @@ * 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); -const defaultThrottling = constants.throttling.mobileSlow4G; +const defaultThrottling = constants.mobileSlow4G; describe('Metrics: Lantern Speed Index', () => { it('should compute predicted value', async () => { From cbc3155c12f554d81af1ce34313a858a1e5e52fe Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 11 Jun 2024 15:01:11 -0700 Subject: [PATCH 2/3] update --- core/config/constants.js | 47 +------------------ core/lib/lantern/lantern.js | 26 +++++++++- core/lib/lantern/simulator/simulator.js | 6 +-- .../lib/lantern/metrics/speed-index-test.js | 2 +- 4 files changed, 30 insertions(+), 51 deletions(-) diff --git a/core/config/constants.js b/core/config/constants.js index fafb07bb5789..0f2dd51306df 100644 --- a/core/config/constants.js +++ b/core/config/constants.js @@ -4,52 +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'; -// Notes: these throttling constants should match what is in Lantern. - -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; /** * @type {Required} diff --git a/core/lib/lantern/lantern.js b/core/lib/lantern/lantern.js index 56d155b61035..b4c8f2e2fc69 100644 --- a/core/lib/lantern/lantern.js +++ b/core/lib/lantern/lantern.js @@ -28,11 +28,10 @@ const NetworkRequestTypes = { Prefetch: 'Prefetch', }; -// These constants should all match the ones inside Lighthouse's `constants.js`. const DEVTOOLS_RTT_ADJUSTMENT_FACTOR = 3.75; const DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR = 0.9; -const constants = { +const throttling = { DEVTOOLS_RTT_ADJUSTMENT_FACTOR, DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR, // These values align with WebPageTest's definition of "Fast 3G" @@ -45,8 +44,31 @@ const constants = { 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 16263a63a51a..1329315a9c48 100644 --- a/core/lib/lantern/simulator/simulator.js +++ b/core/lib/lantern/simulator/simulator.js @@ -12,7 +12,7 @@ import {DNSCache} from './dns-cache.js'; import {SimulatorTimingMap} from './simulator-timing-map.js'; import {constants} from '../lantern.js'; -const defaultThrottling = constants.mobileSlow4G; +const defaultThrottling = constants.throttling.mobileSlow4G; /** @typedef {import('../base-node.js').Node} Node */ /** @typedef {import('../network-node.js').NetworkNode} NetworkNode */ @@ -82,10 +82,10 @@ class Simulator { case 'devtools': if (throttling) { options.rtt = - throttling.requestLatencyMs / constants.DEVTOOLS_RTT_ADJUSTMENT_FACTOR; + throttling.requestLatencyMs / constants.throttling.DEVTOOLS_RTT_ADJUSTMENT_FACTOR; options.throughput = throttling.downloadThroughputKbps * 1024 / - constants.DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR; + constants.throttling.DEVTOOLS_THROUGHPUT_ADJUSTMENT_FACTOR; } options.cpuSlowdownMultiplier = 1; diff --git a/core/test/lib/lantern/metrics/speed-index-test.js b/core/test/lib/lantern/metrics/speed-index-test.js index 20c1b9bc0a81..30223d2a629a 100644 --- a/core/test/lib/lantern/metrics/speed-index-test.js +++ b/core/test/lib/lantern/metrics/speed-index-test.js @@ -12,7 +12,7 @@ import {constants} from '../../../../lib/lantern/lantern.js'; const trace = readJson('../../../fixtures/artifacts/progressive-app/trace.json', import.meta); -const defaultThrottling = constants.mobileSlow4G; +const defaultThrottling = constants.throttling.mobileSlow4G; describe('Metrics: Lantern Speed Index', () => { it('should compute predicted value', async () => { From c0d0ce35f44ef27e6310038519e0be3271432a63 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Tue, 11 Jun 2024 15:07:53 -0700 Subject: [PATCH 3/3] oops --- core/config/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/config/constants.js b/core/config/constants.js index 0f2dd51306df..0d8da0a3a4fe 100644 --- a/core/config/constants.js +++ b/core/config/constants.js @@ -6,7 +6,7 @@ import * as Lantern from '../lib/lantern/lantern.js'; -const throttling = Lantern.constants; +const throttling = Lantern.constants.throttling; /** * @type {Required}