runtime/wasm: add WASI single-worker scheduler (based on #2192, #2208) - #2197
Draft
cpunion wants to merge 27 commits into
Draft
runtime/wasm: add WASI single-worker scheduler (based on #2192, #2208)#2197cpunion wants to merge 27 commits into
cpunion wants to merge 27 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Jul 28, 2026
cpunion
force-pushed
the
codex/wasm-wasi-single-worker
branch
from
July 28, 2026 14:12
24020c3 to
e3e8ea8
Compare
…/wasm-wasi-single-worker
…orker-asyncify-scheduler # Conflicts: # internal/build/source_patch_test.go
…/wasm-wasi-single-worker
…orker-asyncify-scheduler # Conflicts: # runtime/internal/runtime/z_default.go
…/wasm-wasi-single-worker
…y-scheduler' into codex/wasm-wasi-single-worker
… codex/wasm-single-worker-asyncify-scheduler
…y-scheduler' into codex/wasm-wasi-single-worker
…orker-asyncify-scheduler
…/wasm-wasi-single-worker
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 #2192 and #2208.
Part of #2152.
Problem
GOOS=wasip1 GOARCH=wasm llgo buildcan produce a module after #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 know whether a backend uses Emscripten Fiber, a raw Asyncify save area, a future resumable ABI, or standardized stack switching.
Implementation
LLGO_WASI_THREADS=1compatibility mode.main.mainas the first schedulable task while keeping the host entry on the system stack.runtime/internal/wasmcontext.Swap,Resume, andSuspendremain direct concrete hot-path calls.runtime/internal/runtime; the continuation package does not inspect G/M/P state.LLGO_WASI_THREADS=1is set.runtime.EnsureLocalInitializerafter compiler/runtime: add //llgo:tls and //llgo:gls package variables #2079.The implementation is intentionally limited to the scheduler/context foundation. Channel blocking, timers and host async integration, wasm GC integration, root/safepoint work, and optional WASI Preview2 support remain follow-up work tracked by #2152.
Validation
All local commands use
GOMAXPROCS=2and-p=1where applicable.fatal_wasm + proc_wasip1;LLGO_WASI_THREADS=1selectsfatal_default + proc_pthread. Both build, and default P1 validates and runs under Wasmtime 39.0.1.llgo test -p=1 ./test/llgoextpass.runtime/internal/wasmcontextandruntime/internal/runqueueeach have 100% statement coverage.-O0,-O3, ThinLTO, post-link validation/execution, no default pthread/shared-memory imports, the external-module_demo/c/hellocpath, and the full Ubuntu/macOS CI matrix.runtime.printany; the same failure reproduces on the unmodified runtime/wasm: add single-worker Asyncify scheduler #2192 base.The lifecycle abstraction changes final scheduler modules by +2,991 bytes for J32 and +1,567 bytes for J64 against the same pre-lifecycle #2192/W tree. Binaryen reports six additional functions, two table entries, and seven indirect calls from the cold allocation callbacks. This is artifact size, not per-G memory; the existing 64 KiB stack and 64 KiB Asyncify reservations are unchanged. The measured P1 +172-byte integration delta uses an older W baseline and is not presented as a pure lifecycle comparison.
Independent diff over the current #2192 and #2208 merge tree: 31 files, +1,402/-101. The new lifecycle commit removes scheduler-owned backend buffers while adding focused storage failure/cleanup coverage. No previously runnable test is skipped or ignored.