Cap WASM parallel workers under a heap budget, Emscripten-only. - #278
Merged
Conversation
Uncapped auto thread counts OOM large wasm32 batches; keep the clamp behind __EMSCRIPTEN__ so native resolve_worker_count stays uncapped. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an Emscripten-only clamp to resolve_worker_count() so WASM batch runs don’t request more heap than wasm32 can provide (avoiding the “Cannot enlarge memory… limit is 2GB” message), while keeping native builds uncapped.
Changes:
- Introduce
clamp_workers_to_memory_budget()to bound a requested worker count by a MB heap budget. - Apply a fixed WASM heap budget cap inside
resolve_worker_count()only when__EMSCRIPTEN__is defined. - Add unit tests covering the clamp behavior and verifying that the WASM cap is applied only under Emscripten.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
library/tests/system/worker_count_test.cpp |
Adds tests for the new clamp helper and validates WASM-only capping vs native behavior. |
library/src/system/parallel_boards.hpp |
Declares the new clamp_workers_to_memory_budget() helper. |
library/src/system/parallel_boards.cpp |
Implements the clamp helper and applies it to resolve_worker_count() under __EMSCRIPTEN__. |
tameware
marked this pull request as ready for review
July 29, 2026 19:14
zzcgumn
approved these changes
Jul 29, 2026
zzcgumn
left a comment
Collaborator
There was a problem hiding this comment.
Maybe we will get a request to do something similar on a raspberry pi.
Collaborator
Author
We might! I added issue #279 to generalize this fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Do not request more than 2GB RAM from WASM, its limit. The messages generated upon exceeding it are apparently harmless, but best to avoid them.
…
…
Keep the clamp behind EMSCRIPTEN so native resolve_worker_count stays uncapped.