Skip to content

Patch Playground to reduce worker count on low-memory machines#2696

Closed
sejas wants to merge 2 commits intorelease/1.7.5from
stu-1369-patch-playground-to-reduce-multi-workers-dynamically
Closed

Patch Playground to reduce worker count on low-memory machines#2696
sejas wants to merge 2 commits intorelease/1.7.5from
stu-1369-patch-playground-to-reduce-multi-workers-dynamically

Conversation

@sejas
Copy link
Member

@sejas sejas commented Mar 3, 2026

Related issues

How AI was used in this PR

Planned with Opus 4.6 and created the code, patch, and PR fully automated. Tweaked a bit the testing instructions. Reviewed and tested the PR.

Proposed Changes

  • Patch @wp-playground/cli to dynamically set worker count based on available memory
  • When total RAM (totalmem) is less than 8GB, use 3 workers instead of the hardcoded 6
  • Reduces memory pressure on Windows and other memory-constrained environments
  • Patches both the ESM and CJS bundles

Testing Instructions

  • Run nvm use && npm i
  • Observe the patches are applied correctly, with no errors.
  • Start the app with npm start
  • Create a new site and verify it boots correctly
  • Check node_modules/@wp-playground/cli/run-cli-Cv4FHhj_.js line 1284 contains q.freemem() < 8 * 1024 ** 3 ? 3 : 6
  • Check node_modules/@wp-playground/cli/run-cli-NCnYfPz7.cjs line 47 contains G.freemem()<8*1024**3?3:6
  • Run npm install and verify the patch applies without errors

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors? (Tests pass, no errors)

Patch @wp-playground/cli to use 3 workers instead of 6 when the machine
has less than 8GB of free RAM, reducing memory pressure on Windows and
other memory-constrained environments.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sejas sejas self-assigned this Mar 3, 2026
@sejas sejas requested a review from a team March 3, 2026 13:04
@sejas sejas marked this pull request as ready for review March 3, 2026 13:04
@fredrikekelund
Copy link
Contributor

When free RAM is less than 8GB, use 3 workers instead of the hardcoded 6

This rule would make more sense if the total available system memory was 8GB. Given that a site process uses ~1.6 GB, this seems like a too harsh limit right now.

There's also the fact that this will make some sites slower than others with no clear explanation as to why…

I'm not immediately sure about the best solution here, but looking at os.totalmem() instead of os.freemem() seems like one place we could start

Copy link
Member Author

sejas commented Mar 3, 2026

What if we limit the number of workers based on OS? Windows -> 3 , else -> 6.
My Mac used the SWAP for the sites that were beyond the physical RAM, and as a user I didn't notice the difference.

Copy link
Member Author

sejas commented Mar 3, 2026

That would make consistent the performance of each site for both platforms.

Copy link
Member Author

sejas commented Mar 3, 2026

With 3 workers, Parallels (8GB RAM) can run 6 sites in parallel (from 3 without the patch).

totalmem is more reliable than freemem for determining machine capacity,
as free memory fluctuates based on caching and other transient factors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member Author

sejas commented Mar 3, 2026

@fredrikekelund, I think your suggestion is the best approach. Let's use totalmem: 31ea19f

Copy link
Contributor

@epeicher epeicher left a comment

Choose a reason for hiding this comment

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

Thanks @sejas for the fix! I can confirm that this improves the performance on Windows, and it allows to create more than 3 sites, I have tested with 5. Also, I agree with using a fix number better than a dynamic so 👍 to 31ea19f.

@sejas
Copy link
Member Author

sejas commented Mar 4, 2026

Closing in favor of #2704 and #2702.

With the new Playground version, Windows does a better job managing swap and doesn’t fail immediately when allocating memory for a new site.

@sejas sejas closed this Mar 4, 2026
@sejas sejas deleted the stu-1369-patch-playground-to-reduce-multi-workers-dynamically branch March 5, 2026 02:11
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.

3 participants