Skip to content

Add CPU throttling option#337

Open
marcusquinn wants to merge 1 commit into
swissspidy:mainfrom
marcusquinn:feature/cpu-throttling
Open

Add CPU throttling option#337
marcusquinn wants to merge 1 commit into
swissspidy:mainfrom
marcusquinn:feature/cpu-throttling

Conversation

@marcusquinn
Copy link
Copy Markdown

@marcusquinn marcusquinn commented May 9, 2026

Summary

  • Add a cpu-throttling-rate action input for Chromium runs.
  • Apply Chrome DevTools Protocol CPU throttling before each measured navigation.
  • Document the input with a 4x slowdown example.

Verification

  • npx wp-scripts lint-js tests/performance/specs/main.spec.ts
  • npx tsc --noEmit
  • git diff --check
  • Local integration: mounted Ultimate-Multisite/ultimate-multisite into WordPress Playground with its existing .github/performance-blueprint.json, set CPU_THROTTLING_RATE=4, and ran npm run test:performance with URLS_TO_TEST=/, TEST_ITERATIONS=1, and TEST_REPETITIONS=1; Playwright reported 1 passed and produced performance metrics for /.

Note: npm run lint still reports existing errors in untouched files (tests/performance/cli/results.js, tests/performance/config/performance-reporter.ts, and tests/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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +84 to +86
if ( ! Number.isFinite( parsedRate ) || parsedRate <= 0 ) {
throw new Error( 'CPU_THROTTLING_RATE must be a positive number.' );
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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' ) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
if ( rate === 0 || browserName !== 'chromium' ) {
if ( rate <= 1 || browserName !== 'chromium' ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider supporting throttling

1 participant