Skip to content

Wasmroutines #1321

Open
Open
@mfateev

Description

@mfateev

Existing WebAssembly threads proposal focuses on enabling wasm compiled program to utilize multiple system threads. This is an extremely useful feature for CPU intensive tasks. But there is a large class of problems which is IO intensive and is better solved by much lighter weight coroutines than system threads. The recent addition of Rust async-wait to a language that already supports multithreading is a good example of such a need. The problem with async-await is that it requires a completely different way to write application code as well as different compilation techniques. From the other side, one of the major reasons for the Go popularity is goroutines which look like real threads to the developer while executed as coroutines by the runtime.
I believe that WebAssembly is uniquely positioned to bring the advantage of Go threading model to practically any multithreaded application that can be compiled to wasm. The idea is that the compiled program doesn’t need to change to leverage the green threads, this becomes the host choice on how to execute it.
Another important feature of WebAssembly is deterministic execution. With green threads it should be straightforward to implement deterministic execution mode for multithreaded targets.
The strawman name for the feature is Wasmroutines.

I found a few issues related to "native wasm threads" like #126 and #1252 but it looks like they are considered as something that wasm might get eventually, but pretty theoretical at this point.

I believe that the single system thread implementation can be done with relatively small effort (for example it could use the normal linear memory) and would provide a lot of value (like executing any multithreaded program without modification) that is worth having as a separate design proposal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    asyncstack switching, JSPI, async, green threads, coroutines

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions