Skip to content

Cap WASM parallel workers under a heap budget, Emscripten-only. - #278

Merged
tameware merged 1 commit into
dds-bridge:developfrom
tameware:limit-wasm-ram
Jul 30, 2026
Merged

Cap WASM parallel workers under a heap budget, Emscripten-only.#278
tameware merged 1 commit into
dds-bridge:developfrom
tameware:limit-wasm-ram

Conversation

@tameware

Copy link
Copy Markdown
Collaborator

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.

$ bazel run //wasm:run_dtest_wasm -- -f hands/list1000.txt -s calc

Cannot enlarge memory, requested 2150969344 bytes, but the limit is 2147483648 bytes!

Keep the clamp behind EMSCRIPTEN so native resolve_worker_count stays uncapped.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
tameware marked this pull request as ready for review July 29, 2026 19:14
@tameware
tameware requested a review from zzcgumn July 29, 2026 19:14

@zzcgumn zzcgumn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we will get a request to do something similar on a raspberry pi.

@tameware

Copy link
Copy Markdown
Collaborator Author

Maybe we will get a request to do something similar on a raspberry pi.

We might! I added issue #279 to generalize this fix.

@tameware
tameware merged commit c34a467 into dds-bridge:develop Jul 30, 2026
7 checks passed
@tameware
tameware deleted the limit-wasm-ram branch July 30, 2026 17:52
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