runtime/wasm: add bounded Web worker scheduling (based on #116) - #119
Draft
cpunion wants to merge 3 commits into
Draft
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This was referenced Aug 1, 2026
Open
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared only with the latest matching platform in the main series. Warning
|
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 #116.
Implements the M1 bounded-Web-worker stage of xgo-dev#2152.
Problem
#116 gives J32/J64/P1 complete single-worker scheduling, timers, roots, and GC, but Web Go work still runs on one host thread. CPU-bound goroutines cannot overlap. Creating one pthread per goroutine would provide parallelism at unbounded thread and stack cost.
Design
LLGO_WASM_WORKERS=Nopts into a fixed Emscripten pthread pool for2 <= N <= 16; the default value1is inert.getgandruntime_procPinstay O(1), and continuation storage remains owned bywasmcontext.Context.main; LLGo exposes__main_argc_argvand runs package initialization andmain.mainas the schedulable main goroutine.Build-only configuration and pre-JS selection live in
internal/wasmworkers. The runtime's small Emscripten pthread/futex boundary lives inruntime/internal/wasmworkers. Scheduler policy stays inruntime/internal/runtime; existing single-worker files remain selected unchanged unless the internalllgo.wasm_workerstag is appended by the build.GC boundary
M1 deliberately disables the current single-worker collector when workers are enabled. Explicitly combining
llgo_wasm_gcwithLLGO_WASM_WORKERS>1is rejected. #116 remains the default for J32/J64/P1 when the worker setting is absent or1.M2 will add allocator synchronization, per-worker root publication, context enumeration, and the stop-the-world request/acknowledgement protocol. Those changes are not part of this PR.
Validation
All local work used
GOMAXPROCS=2,GOMEMLIMIT=4GiB, and-p=1; Ubuntu containers were limited to 2 CPUs and 6 GiB.internal/build,internal/crosscompile, and runtime-module tests pass on macOS.//llgo:glsusers per worker. Removing the persistent locality owner makes this regression fail withruntime: local context changed by nested entry.wasm-tools validate --features all.internal/wasmworkers: 100% statement coverage.configureWasmWorkers: 88.2%;configureWasmGC: 95.8%; worker main-entry generation: 100%.Performance
Apple M4 Max, J32
-O3, medians of seven rounds:These are stage-level measurements, not a scheduler-only comparison: M1 temporarily disables the collector pending M2. Parallel CPU work improves as intended, while cross-worker handoff pays locking and wakeup cost.
For the same benchmark input, the worker host adds 29,191 B of generated J32 JavaScript (234,535 B to 263,726 B). The wasm payload decreases by 126,209 B because the M1 stage excludes the single-worker collector; this is not claimed as a worker scheduler size improvement.
Default-path cost
Against #116 with the same inputs and flags:
Review scope
Excluding #116, this PR changes 39 files with +2052/-118. Three commits separate implementation, execution/benchmark/browser acceptance, and the worker-locality lifetime regression.