runtime/wasm: add bounded Web worker scheduling (based on #2214) - #2216
Draft
cpunion wants to merge 65 commits into
Draft
runtime/wasm: add bounded Web worker scheduling (based on #2214)#2216cpunion wants to merge 65 commits into
cpunion wants to merge 65 commits into
Conversation
…orker-asyncify-scheduler # Conflicts: # internal/build/source_patch_test.go
…/wasm-wasi-single-worker
# Conflicts: # .github/workflows/llgo.yml
…orker-asyncify-scheduler # Conflicts: # runtime/internal/runtime/z_default.go
…/wasm-wasi-single-worker
…nts-roots-v2 # Conflicts: # cl/compile.go
# Conflicts: # .github/workflows/llgo.yml
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Depends on #2214.
Implements the M1 bounded-Web-worker stage of #2152.
Problem
The cooperative
js/wasmscheduler from #2214 can multiplex goroutines, but all Go work still runs on one host thread. CPU-bound goroutines cannot overlap, and simply creating one pthread per goroutine would make resource use unbounded.Design
LLGO_WASM_WORKERS=Nopts into a fixed Emscripten pthread pool (2 <= N <= 16); the default value1is inert.getgandruntime_procPinare O(1).main; LLGo exposes__main_argc_argvand runs package init/main as the schedulable main G.Build configuration lives in
internal/wasmworkers; the runtime host boundary lives inruntime/internal/wasmworkers. Existing single-worker files are selected unchanged through build tags.The current collector is deliberately disabled when workers are enabled. Explicitly combining
llgo_wasm_gcwithLLGO_WASM_WORKERS>1is rejected until the M2 allocator/STW work lands.Validation
internal/wasmworkers: 100% statement coverage.configureWasmWorkers: 88.2%;configureWasmGC: 95.8%; worker entry generation: 100%.internal/build,internal/crosscompile, and runtime module tests passed on macOS and Ubuntu.132/0/10.Median of 7 J32 runs in the same constrained Ubuntu container:
These are stage-level measurements, not a scheduler-only comparison: M1 temporarily disables the collector pending M2. The worker host adds about 29 KiB of generated J32 JavaScript; non-worker builds add no generated runtime code or embedded cost.