For me Rust offers the best WASM experience and tooling at the moment.
Rust has no GC and (almost) no runtime.
It also has official wasm build target support out of the box, including generating Typescript definitions for Rust types.
The ecosystem is somewhat well-developed:
* wasm-bindgen for general interop in both directions
* js-sys / web-sys for (low-level) type-safe and surprisingly efficient browser API bindings
* wasm-bindgen-futures for easy Promise <-> Future interop
* wasm-pack for easy building
* ...
Getting the code size low is still a challenge though.
A Rust implementation of the Krausest frontend framework benchmark takes a top 4 spot [1]. Despite this benchmark not favouring wasm at all since it requires little computation and mostly does FFI calls.
(ps: C++ is in a decent state as well)
[1] https://rawgit.com/krausest/js-framework-benchmark/master/we...
I’d still choose Go or Rust over C++, though, because they’re memory-safe. This recent discussion shows that’s still important in the context of WebAssembly: https://news.ycombinator.com/item?id=24216764
But a huge amount of the worlds software is written in C++, and will remain so for decades.
Getting some of that code to run well in WASM can be a big win for certain domains.
I expect that WASM doesn't have the concurrency model required by a modern concurrent garbage collector like Go's, but perhaps I'm wrong.
Years ago, I wanted to write some code that could run both as part of a command-line app and an in-browser tool. I asked what language I should use for this shared code and was told, basically, that there was no suitable language.
Now, thanks to WASM, there are lots!
Tools like GopherJS, Elm, Dart and such output JavaScript no human could reasonably interpret. WASM seems logical for them. TypeScript outputs very human readable JS (for the most part) and WASM seems to have little virtue.
As someone who learned JavaScript in the late 90s / early 2000s reading websites code, outputting readable JS feels like giving back.
This has been true for years, various languages can compile down to JavaScript. Kotlin and Dart, for instance.
Also, doesn't WASM lack a garbage collector? I imagine porting a language to WASM is still quite a task, and presumably a GC written in WASM is going to be far inferior to one provided by the browser, as with JavaScript. (Corrections welcome if I'm wrong about that.) That's not to dismiss the potential for performance gains in situations well suited to WASM.
(I see the_duke already mentioned the GC situation.)
That's because officially Go has not support for web APIs(as wasm has no access to web apis) so you have to callback through JavaScript. However once you build the right wrappers around JS APIs and the tools to deal with HTML the experience is pretty nice.
You can also see this with Gio UI library in Go where they try to minimize GC overhead yet one keeps hitting GC pauses in WASM. The author talks about some of the issues with Go on WASM here: https://changelog.com/gotime/128
It did help that after diving back into the new stuff in 'modern C++' with auto, lambdas and move semantics I was able to write quite ergonomic code without any actual manual memory management stuff going on.
I have done a number of experiments with Go’s WASM target, one of the earliest and silliest porting Go’s “Otto” JavaScript runtime to WASM, so you can much less efficiently run ES3 JavaScript in a browser.
I have also been working on porting a number of tools I currently have that run server side with web frontends to pure WASM. I have had mixed success here however and have found interacting with web elements and JavaScript from Go an awkward, non statically validated, frustrating experience of trial-and-error that somewhat undermines the joy of a statically typed language. On top of everything, Go’s .wasm files are frustratingly large, “Hello World” starting at 1mb and growing quickly from there.
All that said though, it is pretty magical seeing something written as a CLI tool running in a browser with minimal changes.