468 points · by todsacerdoti · 3y ago · 81 comments
But at least there is hope, that these interfaces will be available once GC is final and supported by browsers:
Once GC is supported, WebAssembly code would be able to reference and access JavaScript, DOM, and general WebIDL-defined objects.
Last paragraph at https://webassembly.org/docs/web/Seems like an awefully long time for progress to be made, given all the possibilities it would unlock.
But I wouldn't hold my breath to being able to call web APIs directly from WASM ;)
Am I getting this right?
I don't know that their Wasm module is necessarily "broken", so I'm unsure whether my contributions would be welcome.
In other words, it's just a bunch of leetcode-like questions, ordered by difficulties.
A proper course should order the exercises by language features. Exercism actually has built a fantastic interface for this[1], but not utiltized it for most langauges.
However, the problems they offer do not help you learn the syntax or quirks of specific languages and for me are only a place to practice leetcode/codewars style logic. Also important! But not what I need when I first begin a language.
One of my favorite ways to learn a new language or framework is via "koans"[1], which this reminds me of. It's a gentle ramp up from basic to advanced features, and the TDD-like workflow of seeing a test fail, understanding why, and fixing it, is really conducive to learning, while giving you that dopamine jolt from "a-ha!".
[1]: https://github.com/ahmdrefat/awesome-koans/blob/master/koans...
I haven't really explored WASM hands-on (I'll give this guide a try) but, given that it's already been a few years, I think it's been hugely beneficial for web development.
Not the "JavaScript killer" some where hoping for, though it was never meant to be one. Instead it integrates pretty nicely within the existing ecosystem, optimizing existing use-cases and allowing new ones when heavy computations are required. Net benefit for all web devs - faster libraries, impressive dev tools and more portable node binaries.
Let WASM do the number crunching, let JS do the UI.
For a lot of companies the only place JavaScript is ever used is on their website frontend. And it makes you wonder, why does it even still need to be JavaScript? With the rise of SPAs and the fall of normal document based websites, browsers are basically just becoming their own platform like Windows Desktop, Mac, Linux, Android, iOS, etc. You could say it's been that way for a long time, but more and more apps are becoming web based only because the browser is now powerful enough to run what used to be a desktop application.
Browsers are literally just a VM with an address bar. We go to a URL and run a program, except right now there's basically the limitation that the program has to be written at least partly in JavaScript. Being able to deploy an entire website as WASM is just the next logical step from what I see.
And currently using anything but C, C++ or Rust isn't feasible, as the runtime needed for a GC is way too big. A Haskell "Hello World" for example is about 1MB (even after running `wasm-opt` on the generated WASM binary).
This is kind of subjective, and in the context of "is this a JS killer" which is what you're answering, I'd agree, it makes sending the Wasm to the browser a bit of a non-starter that it requires a large bundle most of which is simply boilerplate for whatever runtime, without some type of local storage and persistent cache it's difficult to imagine using Ruby in a Wasm for example. If you're deploying to a container, where you're able to use a cache warmer to ensure the wasm is ready before it's called, then a 1mb binary might not be such a big issue.
(I mean, it is still a big issue because the point was fast cold starts, and big assemblies mean no fast cold starts, but again, subjective value judgments... 1mb isn't too big in many cases and I'd wager most of the cases that I'd really care about. But in a browser...)
But if you're not trying to run the Wasm in a browser then it's still potentially quite useful. You might not be running all of your Wasm in a browser and it might still be a JS killer, and all of those might not be in conflict.
Someone should tell Anaconda that they can't do this, then: https://pyscript.net/
Doing so would almost always be a security risk, as validation would presumably still run client side, but that doesn’t mean it’s not possible to actually achieve such an engine.
I mostly get the impression that the compiler in browser is the problem.
If it's adopted natively, that should disappear.
All I'd need is Firefox, edge and chrome to switch to publishing wasm.
I maintain a somewhat related repo here: https://github.com/eliben/wasm-wat-samples/
https://developer.fermyon.com/spin/sqlite-api-guide#using-sq...
I'm not sure what holds back from being a completely language agnostic solution, but I know when I tried binding functions into my Ruby app with wasmer I had nothing but problems, I wound up using WASI exclusively to communicate with my WASM modules. I don't honestly know how good the WASM language agnostic story is today. I gave a talk with my perspective as a Rubyist at OSS Summit and CDCon/GitOpsCon a few months ago in Vancouver. The talk (and lightning talk variant) are called "Exotic Runtime Targets: Ruby and Wasm on Kubernetes and GitOps Delivery Pipelines"
As WebAssembly becomes the lingua franca of different ecosystems, having a strong grasp of how it works is worth the time investment. Thanks for this.
Personally, I didn't find the author's sample app to load very quickly- I think it was 10 seconds or so just to get something on the screen- and it was useless on my phone.
That same app would easily perform better and have better device support were it written in js/html/css.
I just don't see a place for things like QT or native gui stuff in real world WASM. Number crunching or fast data processing, sure, or maybe a game, but a standard UI is crap if the whole thing is in a big canvas.
https://learn.microsoft.com/en-us/aspnet/core/blazor/host-an...
It isn't, really, what the Rust frameworks do is compile down to a specific interop, sure (JS + WASM, its not pure WASM due to lack of DOM access for starters).
That said, no reason a hand written WASM app isn't feasible, with appropriate JS glue
That's a record with 3 fields, its constructor and getters using the GC extension:
;; A `struct` with 3 fields, all immutable.
(type $testStruct
(struct
(field $first i64)
(field $foo f32)
(field $baz f64)))
;; Constructor. `ref` is a reference
(func $mkTestStruct
(param $a i64) (param $b f32) (param $c f64) (result (ref $testStruct))
(struct.new $testStruct (local.get $a) (local.get $b) (local.get $c)))
(export "mkTestStruct" (func $mkTestStruct))
;; Getter function for the three fields:
(func $getTestStruct1 (param $rs (ref $testStruct)) (result i64)
(struct.get $testStruct 0 (local.get $rs)))
(export "getTestStruct1" (func $getTestStruct1))
(func $getTestStruct2 (param $rs (ref $testStruct)) (result f32)
(struct.get $testStruct 1 (local.get $rs)))
(export "getTestStruct2" (func $getTestStruct2))
(func $getTestStruct3 (param $rs (ref $testStruct)) (result f64)
(struct.get $testStruct 2 (local.get $rs)))
(export "getTestStruct3" (func $getTestStruct3))My initial motivation to learn WASM (as someone from a primarily web background) was that I had a pretty poor understanding of WASM in general and so I had a lot of difficulty working with WASM builds in just about any capacity other than a heavy JS wrapper.
There are aspects to how WASM works that are quite different from other kinds of assembly formats that make learning the basics pretty important. e.g. how memory is requested, provided, grown. How functions are received and exported. Capabilities of tables.
A lot of this might be abstracted by massive wrappers, but you're losing a lot in perf and debugability when using them.
By limitations I mean things that a POSIX program would expect that aren't generally available from WASM, like network programming, file system access, processes and threads, pipes and signals. Emscripten and WASI help to some extent, but the replacement APIs are rarely fully compatible.
You are embedding a WASM engine and want to better grok how the import or exporting works.
You are writing a compiler that targets WASM.
Eventually I moved the whole game engine into wasm & at that point it all got ported to Rust
https://github.com/serprex/openEtG/blob/8b7069cc52ec8db3406a...