WasmGC – Run GC languages such as Kotlin, Java in Chrome browser
developer.chrome.com
developer.chrome.com
JavaScript is suddenly no longer the only real game in town it seems.
I mean sure WASM has allowed C, C++ and Rust to run on the web for awhile now but they aren’t typically languages that web developers tend to have a lot of knowledge of or interest in learning.
But Dart, Kotlin and Java for example, they very much are viable replacements for many TypeScript or JavaScript use cases and the mental jump from TypeScript to any one of those three isn’t particularly onerous.
We still don’t yet have direct DOM access from within WASM but I know both Kotlin and Dart at least are building a glue layer to fix that. (Example of Dart’s here: https://github.com/dart-lang/web/blob/main/test/smoke_test.d...)
It also opens up the door for a UI framework that skips the DOM and goes directly down the canvas and WebGPU path which is what Flutter are aiming towards.
The web platform needs to decouple accessibility from the DOM in order to make that not just an opaque blob of pixels that a canvas element is currently but work is already underway on that via the Accessibility Object Model API.
I think this gets us to a pretty exciting place just over the horizon.
I’m excited to see the next few years but I think it’s at least start thinking about if JavaScript or a compile to JavaScript language is really the best option in the near future now that it’s no longer the only choice available.
I think that main use case is not for the web developers who already know the tech needed for web development but actually vice-versa. E.g. you're a C/C++/Rust developer and you want to expose your product as a browser service - you transpile it to wasm and with a bit of JavaScript you integrate it into the end service. And that landscape is now expanding to other languages too, namely the ones with the GC.
Speaking as someone who worked for two companies that tried to do exactly that, it's not that simple. The "bit of JavaScript" ends up requiring huge amounts of work, and the user experience feels un-browser-like, because you're fitting everything through a canvas element.
To me the most challenging part seemed to be in the domain of debugging when things would go south because all of the sudden you have to become very intimate with how things work under the hood and across the whole stack: JS -> V8 -> WASM runtime -> Emscripten -> C++. There's not many people capable of doing that job.
> user experience feels un-browser-like
Perhaps Photoshop is not the classical example but I think it's one of the most craziest ones out there - humongous and extremely complicated C++ codebase consisting of every imaginable optimization and heavy lifting deployed as a WASM "plugin".
[1] https://medium.com/@addyosmani/photoshop-is-now-on-the-web-3...
If your application is built upon a web framework which already has this translation layer, like Blazor, then the amount of harness/shim-glue code you need to write goes down.
I really don't think the use of this is running existing Java swing applications on the web. Maybe a bit of a hack for legacy software, but it's really using Java instead of Javascript, but using the normal DOM/HTML.
* user "menaerus" goal is have "C/C++/Rust developer [...] expose your product as a browser service", which they can transpile to wasm - cool.
* they will need "a bit of JavaScript you integrate it into the end service" - UI targets the DOM, sounds great.
The questions become:
* how much code will need to be written into each layer (rust wasm, react html ui, bridge between the 2)?
* what level of experience with that tech will you need todo that? ie: writing a react ui which interfaces with a wasm shim is some non-trivial javascript to say the least.
* based on the above: how far has wasm enabled a "c/c++/rust developer" to easily port their application to the web without also being a super strong frontend developer?
I'm trying to draw a contrast between:
A) I have business logic which is not well suited for javascript (image processing on binary data, figma, etc), and I have rust/c++ developers AND javascript frontend developers to build the application
B) I am a rust/c++ developer who wants to target the web with their rust/c++ product, but doesn't want to dive deep into frontend/js/react tech.
In the long term, I am optimistic that scenarios like "B" will be opened up by application (web) frameworks which target wasm via backend technologies and their MVC patterns. But in the short term, the amount of "glue code" to be written is non-trivial.
But if you’re comparing to proprietary examples, you could go all the way back to ActiveX in 1996.
Or, since today’s news is about Java, you could go back to Java applets in 1995. (At least those were somewhat secure, unlike ActiveX.)
[1] https://www.clojure.org/news/2011/07/22/introducing-clojures...
Notice the footprint is very small (3k for an hello world).
(See https://linuxontheweb.github.io/ for my implementation of a new kind of web application platform where these kinds of ideas can start becoming a reality.)
Maybe we could use it to write some small applications with it, let's call them "applets".
There is a free Chrome extension for it
Let's call this language Java Script so that it's clear what its narrowly defined intended purpose is.
But that raises the question - wouldn't it imply that this GC needs to support every special feature of every language (interior pointers, pinning, value types etc.), and have access to the stack layout to have a chance of working?
Sounds like a hairy problem to me.
Although not having to ship a GC might be a major boon since in my experience, WASM runtimes tend to be on the larger size.
https://github.com/WebAssembly/gc/blob/main/proposals/gc/Pos...
What launched now is enough WasmGC to support a big and useful set of languages (Java, Kotlin, Dart, OCaml, Scheme), but a lot more work will be required here!
WASM still grants access to a PL to simply decide to allocate a byte and manage it itself. interior pointers and value types seem like they could be handled by reference counting + native memory allocation. Much like Python is trying to do to introduce tracing GC. Use RC when you can't use the tracing GC.
I remember following the GC proposal back in 2019 when the WebAssembly standard was barely out. Back then it felt like GC was right around the corner. Then as time went on, more parts were split off the proposal, and progress slowed more and more.
I can't believe it's finally coming out!
https://discuss.ocaml.org/t/announcing-the-ocaml-wasm-organi...
https://discuss.ocaml.org/t/an-update-from-the-ocaml-wasm-or...
It seems like it’s a relatively easy swap from js_of_ocaml to WASM. That’s the option I’ve chosen for my experiments.
Time will tell if both survive, they are both under active development. IMHO target different use cases.
But currently these apps just don't have the fluidity, that's there with native apps, also maintaining large JS codebase is horrible, Typescript doesn't help much in my opinion.
WebGPU + new development languages, will hopefully send web-apps to the next level.
You are trying to put types on top of something that wasn’t designed with types in mind at all and you often end up with some insanely and unnecessarily complicated types as a result.
Take this as an example of mixins which are a fairly common pattern.
https://lit.dev/docs/composition/mixins/#mixins-in-typescrip...
Now take a look at the same thing in a modern well designed language
https://dart.dev/language/mixins
It’s not just that but even when you consider some of the design decisions.
To stick with TypeScript and Dart once again, I mean, they both technically have enums which is an incredibly useful data type but the difference between them is like night and day.
TypeScript: https://www.typescriptlang.org/docs/handbook/enums.html
Dart: https://dart.dev/language/enums
And then finally on top of that, because the goal is no longer to compile to JavaScript you can bring in all kinds of useful language features like this which don’t have an equivalent that I know of https://dart.dev/language/extension-methods
Unless you enjoy trying to make up what 3D rendering calls belong to the browser, and which ones belong to the actual application.
Current JS-in-WASM approaches compiler a whole runtime like the SpiderMonkey interpreter to WASM then use that to run JS source. That leaves a ton of performance on the table, though it sounds like it can start up sometimes faster than a JS VM.
But with WASM GC, we should be able compile JavaScript to WASM (disabling eval() and new Function()) and not ship JS source, or even bytecode. The compiled output would be like the first compiler tier in V8 - very unoptimized, but still better than an interpreter running in WASM.
Maybe you could even use profile-guided optimization (or TypeScript?) to output optimized fast paths.
I feel like this solution in superior to both those things but it still feels like a step backwards.
First, the Java plugin required a JDK installation, which was a considerable download. At the time, many apps/tools included some JDK version, but as a developer, you can't count on that. It took many years for Java to have a modular JDK, but when it happened, applets were already gone. By comparison, the user experience of Flash was orders of magnitude better.
UI programming was problematic. AWT was ugly, and Swing was too slow for the machines then. In comparison, Flash had tools to create excellent interactive games and small UIs. Also, as HTML/CSS/JS supported more and more UI patterns, there wasn't a need to use applets for complex UIs.
The JVM is sandboxed, but there are so many moving pieces and outdated JDKs installed that they become a security problem and attackers started to poke into the applet plugin bugs to find holes.
Finally, another issue shared with frameworks like ActiveX or browser plugins was DOM integration. When you mix an applet with a page, the applet feels alien. You can't navigate inside the applet without breaking the browser navigation, and using apples for small UI pieces (Sun's home page used to have a news ticker applet) is an overkill. The best use case for applets or ActiveX was video playback, but browsers added native support. That's why Java Web Start was more interesting than applets. But, at the time, Sun was spread too thin. Adobe did the same with the Rich Internet Apps and Flex but with a better execution (until the iPhone killed the RIA hype).
Also, object tag let languages compete on the quality of their runtime. This also doesn't allow that. You can't ever do better than V8, and V8 isn't going to care about features unique to your language.
The main win is that the browser will keep the WASM interpreter/JIT up to date for you, and it will drop OS privs for you, and it will download and cache the bytecode for you.
The same reason why Flash was a persona non grata still apply.
Safari is the only reason why we still don't update CVs from Web Developer into ChromeOS Developer.
If you mean compile Dart to WASM, leveraging WasmGC, yes that's being worked on a prototype has been available for months now:
- https://docs.flutter.dev/platform-integration/web/wasm.
- https://flutterweb-wasm.web.app/
If you mean integrate the Dart runtime into browsers...that ship sailed a long time ago. Wasm is a more flexible way to accomplish that, amongst other reasons.
+ Nice to have would be multithreading without impractically restrictive browser headers
I guess wasm is essentially trying to be a dynamic c library without being requiring OS specific binaries and being written in languages other than C
It'll be interesting to see how & when js-on-wasm comes about that uses wasm-gc.
It has a lot of limitations, currently, but you may get your app working if you don't use native plugins. Let us know if you manage to get it working.
Now with Unity, Flutter, Qt, Blazor, .... as alternative to Flash tooling.
(Not contradicted the in article, just in the editorialized submission title)