runtime/wasm: add WASI single-worker scheduler (based on xgo-dev #2192, #2208) - #100
Closed
cpunion wants to merge 17 commits into
Closed
Conversation
…/wasm-wasi-single-worker
…/wasm-wasi-single-worker
…/wasm-wasi-single-worker
…y-scheduler' into codex/wasm-wasi-single-worker
…y-scheduler' into codex/wasm-wasi-single-worker
…/wasm-wasi-single-worker
…/fork-wasm-wasi-single-worker-20260801 # Conflicts: # runtime/internal/runtime/g_pthread.go
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
LLGo baseline benchmarks
Program measurements
Core language and compiler benchmarks
Compared only with the latest matching platform in the main series. Warning
|
This was referenced Aug 1, 2026
This was referenced Aug 1, 2026
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 xgo-dev#2192 and xgo-dev#2208.
Fork-only staging PR for xgo-dev#2152. Its base branch is the validated merge of xgo-dev#2192 and xgo-dev#2208 so this PR shows only the W increment and does not add CI load to
xgo-dev/llgo.Problem
GOOS=wasip1 GOARCH=wasm llgo buildcan produce a module after xgo-dev#2192, but goroutines still select the pthread runtime. The resulting executable imports shared host memory and WASI pthread facilities, so ordinary single-worker Wasmtime execution cannot run Go scheduler behavior.The continuation implementation also needs a clear ownership boundary. Scheduler code should not depend on whether a backend uses Emscripten Fiber, a raw Asyncify save area, a future resumable ABI, or standardized stack switching.
The J32/P1 type model also previously used 4-byte maximum alignment even though LLVM wasm32 aligns 64-bit scalars to 8 bytes. For nested structs this made Go
unsafe.Offsetofdiffer from LLVM field addresses:runtimeContext.gwas 324 bytes to Go but 328 bytes to LLVM, placing later scheduler fields outside the 376-byte allocation.Implementation
LLGO_WASI_THREADS=1compatibility mode.main.mainas the first schedulable task while keeping the host entry on the system stack.runtime/internal/wasmcontext.runtime/internal/runtime; the continuation package does not inspect G/M/P state.Swap,Resume, andSuspendcalls remain concrete.LLGO_WASI_THREADS=1is set.unsafe.Offsetof/Sizeofwith actual field addresses and array stride.This is the scheduler/context foundation only. Blocking channels, timers, host async integration, wasm GC and safepoints, and optional WASI Preview2 support remain separate work tracked by xgo-dev#2152.
Validation
All local commands were bounded with
GOMAXPROCS=2,GOMEMLIMIT=6GiB, and-p=1where applicable.go test ./internal/build ./internal/crosscompile ./ssapasses.runtime/internal/wasmcontext,runtime/internal/runqueue,runtime/internal/clite/emscripten, andruntime/internal/runtimepass/build.GOOS=js GOARCH=wasm), J32 (-target wasm), and P1 (GOOS=wasip1 GOARCH=wasm) scheduler and deadlock fixtures pass.wasm-tools --features alland runs under Wasmtime 39.0.1.LLGO_WASI_THREADS=1P1 runtime selection builds.wasmcontextandrunqueueare 100%;genMainModuleis 96.1%;defineWasmMainTaskandeffectiveTypeSizesare 100%; wasm post-link main paths are covered.panic: uint64 field layout mismatch) and passes on J32, J64, and P1 after the fix; P1 also passeswasm-tools validate --features all.runtimeContextallocation from the incorrect 376 B to 384 B (+8 B); the 64 KiB stack and 64 KiB Asyncify reservations are unchanged. On the same B fixture, J32 wasm changes from 554,724 B to 554,612 B (-112 B), P1 from 531,242 B to 530,866 B (-376 B), and the J32 JS loader is byte-size identical. J64 and all native/embedded type models are unchanged.50866cd89also completed 39 checks across Ubuntu, macOS, Go 1.24/1.26, wasm runtime execution, LTO, coverage, release artifacts, and embedded targets; only release publication was intentionally skipped.Independent diff over the xgo-dev#2192 + xgo-dev#2208 base: 32 files, +1,438/-105. No previously runnable test is skipped or ignored.