Add CPU throttling option#337
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a cpu-throttling-rate input to the GitHub Action, enabling CPU slowdown simulation in Chromium during performance tests. The changes include documentation updates, action configuration, and the implementation of throttling via Playwright's Chrome DevTools Protocol (CDP). Feedback suggests refining the input validation to handle zero consistently and optimizing the code to skip CDP session creation when the throttling rate is 1 or less.
| if ( ! Number.isFinite( parsedRate ) || parsedRate <= 0 ) { | ||
| throw new Error( 'CPU_THROTTLING_RATE must be a positive number.' ); | ||
| } |
There was a problem hiding this comment.
The validation logic is inconsistent: an empty string returns 0 (disabling throttling), but an explicit "0" string causes an error. Additionally, the error message 'positive number' technically excludes zero. Allowing 0 as a valid input for 'no throttling' would be more consistent.
| if ( ! Number.isFinite( parsedRate ) || parsedRate <= 0 ) { | |
| throw new Error( 'CPU_THROTTLING_RATE must be a positive number.' ); | |
| } | |
| if ( ! Number.isFinite( parsedRate ) || parsedRate < 0 ) { | |
| throw new Error( 'CPU_THROTTLING_RATE must be a non-negative number.' ); | |
| } |
| browserName: string, | ||
| rate: number | ||
| ) { | ||
| if ( rate === 0 || browserName !== 'chromium' ) { |
There was a problem hiding this comment.
A CPU throttling rate of 1 represents no slowdown. Since Playwright provides a fresh page for each test iteration, we can optimize by skipping the CDP session creation and command if the rate is 1 or less.
| if ( rate === 0 || browserName !== 'chromium' ) { | |
| if ( rate <= 1 || browserName !== 'chromium' ) { |
Summary
cpu-throttling-rateaction input for Chromium runs.Verification
npx wp-scripts lint-js tests/performance/specs/main.spec.tsnpx tsc --noEmitgit diff --checkUltimate-Multisite/ultimate-multisiteinto WordPress Playground with its existing.github/performance-blueprint.json, setCPU_THROTTLING_RATE=4, and rannpm run test:performancewithURLS_TO_TEST=/,TEST_ITERATIONS=1, andTEST_REPETITIONS=1; Playwright reported1 passedand produced performance metrics for/.Note:
npm run lintstill reports existing errors in untouched files (tests/performance/cli/results.js,tests/performance/config/performance-reporter.ts, andtests/performance/playwright.config.ts).Closes #85
aidevops.sh v3.15.10 plugin for OpenCode v1.14.41 spent 26m on this as a headless worker.