Wasm RAM - #274
Draft
tameware wants to merge 10 commits into
Draft
Conversation
Uncapped auto thread counts allocate one Large TT per worker and OOM large WASM batches; clamp to a fixed memory budget instead. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep native thread counts uncapped so the WASM heap guard does not change host performance. Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid pulling api/dds.h into the native parallel_boards TU so host codegen of the hot path stays unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep native parallel_boards identical to develop so the heap guard cannot change host codegen of the hot path. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a WASM-specific cap on parallel worker count so DDS doesn’t request more than the practical wasm32 heap limit (~2 GiB), avoiding noisy (but apparently harmless) out-of-memory warnings on large WASM batches while keeping native builds unaffected.
Changes:
- Introduces a small helper (
clamp_workers_to_memory_budget) to cap worker count by a total heap budget and per-worker footprint. - Adds an Emscripten-only
parallel_boards_wasm.cppimplementation that applies a worker cap based onTHREADMEM_LARGE_DEF_MBand a fixed heap budget. - Extends system tests to validate the clamp behavior and ensure native builds do not apply the WASM cap.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| library/tests/system/worker_count_test.cpp | Adds unit tests for the new memory-budget clamp and for WASM-vs-native worker count behavior. |
| library/src/system/worker_memory_budget.hpp | Declares the helper used to cap worker counts by a memory budget (MB). |
| library/src/system/worker_memory_budget.cpp | Implements the worker-count clamping logic. |
| library/src/system/parallel_boards_wasm.cpp | WASM-specific parallel boards implementation that applies the heap-based worker cap. |
| library/src/system/BUILD.bazel | Uses a select() to compile either the native or WASM parallel_boards implementation depending on the build platform. |
Comments suppressed due to low confidence (1)
library/src/system/worker_memory_budget.hpp:22
- The
@returndescription currently omits that the result is also capped by the requested worker count; documenting the exact clamp makes the contract clearer.
* @return workers clamped to max(1, budget_mb / per_worker_mb)
Bring in dtest WASM clean exit and board-pool shutdown so the wasm-only parallel_boards TU can stay API-compatible with develop.
Rebuild it from the current board-pool implementation so shutdown_parallel_boards_pool links under Emscripten after merging dtest clean exit. Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid referring to the develop branch in the BUILD comment so the split reads as a host/Emscripten source choice. Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid hard-coding the Large TT default so the clamp tests stay aligned if that constant changes. Co-authored-by: Cursor <cursoragent@cursor.com>
Note that the clamp lives in its own .cpp rather than referring to develop. Co-authored-by: Cursor <cursoragent@cursor.com>
Call out that only resolve_worker_count should differ, reducing drift risk between the duplicated worker-pool implementations. Co-authored-by: Cursor <cursoragent@cursor.com>
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 on exceeding it are apparently harmless, but best to avoid them.
This change must be totally isolated from the native builds, otherwise it slows them down by ~5%. I'm still trying to figure out why.