-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multi threading in WASM? #2630
Comments
The current tinygo implementation supports cooperative goroutines using asyncify on wasm. Does that solve your problem? |
Wait what ? Could you give us some links to read more about it? |
Yes. The tinygo 0.22 release includes |
Thanks for your reply! I really appreciate it! From my understanding multi threading in wasm is done running multiple and separate WebWorkers and exchange data either using SharedArrayBuffer or using processMessage() . From my understanding asyncify doesn't make the goroutine run multi threaded. Am I wrong ? |
Correct, there is still only a single wasm "core". |
Then, there is no multi threading support right now in tinygo in wasm. Any plans of adding support for multi threading wasm ? Take a look here https://github.com/w3reality/wasm-mt Our open source library does a lot of heavy computations (zero knowledge proofs) and it takes 20 seconds single threaded. Using multi threading, we can reduce it down to 3-4 seconds? |
Would "multicore support" be a better title? |
It would be amazing of having multicore support wasm bundles. |
I think the easiest way to integrate it is via SharedArrayBuffer which was re-enabled in Google Chrome v67 |
The threading proposal for Wasm is not finished, and wasm-mt is a library while TinyGo is a compiler, so really you cannot compare them. Personally I don't think there is anything to do here for the time being. |
In the meantime, the threading proposal for Wasm is finished. It would be very interesting (really very interesting) to use tinygo to write multithreaded wasm programs. Please consider this. https://webassembly.org/roadmap/ |
Unfortunately, the "threading proposal" doesn't actually provide a way to start a thread. It's only about shared memory and atomics. No idea who thought that would be a good name. So that proposal is useless in itself, it only becomes useful together with an embedder specified way of starting threads (Web Workers for example). Last time I checked, WASI didn't have a way of starting threads making it pretty useless there. Also, wasm threading depends on general support for parallelism is TinyGo, which doesn't exist at the moment: #2446 |
The last article I mentioned addresses a list of problems (with solutions) and one of them is the inability to start a thread. "In C, particularly on Unix-like systems, the common way to use threads is via POSIX Threads provided by the pthread library. Emscripten provides an API-compatible implementation of the pthread library built atop Web Workers, shared memory and atomics, so that the same code can work on the web without changes." If it's available in C, it should be available in TinyGo, I suppose.
Oh, that's too bad, I didn't know. I'll stick with C, then. I don't want to sound harsh. I think TinyGo is an interesting project, both for wasm and for microcontrollers. I'm looking forward to the moment parallelism is added. |
This looks apropos: https://bytecodealliance.org/articles/wasi-threads |
Hi folks, any plans to address this now that the WASM threads proposal has entered Stage 4 of standardization and is supported in all modern browsers? https://github.com/webassembly/threads There's a similar issue in the main Go repo that was stalled pending standardization of the proposal, it's far enough along that there's little chance of spec change at this point. This feature is blocking Go's utility in the WASM world, since one of the main benefits of Go (the versatility of goroutines) is kneecapped without proper procs. golang/go#28631 |
The standard still doesn't specify how to create a thread, so it seems incomplete...? |
Maybe a bit naive but the spec sounds to me like an abstraction of Web Workers and there's a |
TinyGo does not support multithreading yet, on any platform.
Indeed. On the web it's typical to use Web Workers. For WASI there's the wasi-threads proposal that has been deprecated already. The consensus seems to be that both should be replaced with shared-everything threads, which will be built into WebAssembly instead of being specific to every host API. |
Ah, didn't realize it wasn't supported by TinyGo period, that would certainly be a blocker. I was imagining it would be more like a thread pool like in other runtime langs, but yeah if it's not supported at all that's a different story. Will pursue in the main Go repo... |
It's possible that even big Go will have trouble here. Often tinygo leads on wasm support, and big go follows. |
As far as I'm aware, they don't support threading either. |
Big Go definitely supports concurrency via procs, which queue on threads... |
According to this issue, they don't support multithreading in WebAssembly: golang/go#28631 |
Right, that's what I want to push them on 😉 AFAICT all the prerequisite features should be there now so it's just a matter of implementation. Not discounting that that is a tall order, but it feels weird that no effort is even being made... |
Does Tinygo support multi threading in web assembly? If not, is there any date when tinygo would add support for multi threading ? WebAssembly is useful for CPU intensive, but it such a pity that golang doesn't support multi threading in wasm...
The text was updated successfully, but these errors were encountered: