Repository navigation
runtime: stack switching on wasm #81963
Description
Go Wasm Stack Switching
As an experiment in the WebAssembly backend, under a GOWASM feature-flag, retarget the compilation of goroutine switching to use WebAssembly's experimental suspend and resume instructions.
Why
The existing method for switching stacks (goroutines) in Go Wasm is to insert code to manage the stack explicitly and step by step. To this end, every function call is checked for a switching boolean return and
stack frames are returned one by one. Every function has a jump table at the top which allows explicit representation of resume-points within the function, but which muddies the debuggability of the generated Wasm code, and has a run-time cost.
The experimental suspend/resume instructions in Wasm are designed precisely to give a direct way to compile things like thread (goroutine) switching. "Suspend" captures a current stack, up to some point, and "resume" installs a given stack that was captured earlier.
Behavior and compatibility
A prototype has been implemented that shows how the suspend/resume instructions can integrate into the Go runtime and compiler. Using suspend/resume should make it possible to remove the checks on every call routine and the top-of-function jump table, making for much more straightforward compilation and code reading.
The change is intended to be invisible to programmers and only to streamline the compiler implementation. However, the WebAssembly feature is not universally deployed, so the new work needs to be kept in an
experiment.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
gabyhelp commentedon Oct 2, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
cagedmantis commentedon Oct 2, 2026
@golang/compiler @golang/runtime
[-]Go Wasm Stack Switching[/-][+]runtime: stack switching on wasm[/+]gopherbot commentedon Oct 12, 2026
Change https://go.dev/cl/845786 mentions this issue:
cmd/internal/obj/wasm, cmd/link/internal/wasm: Define opcodes for WasmFX suspend/resume extention.