Top
Best
New

Posted by mikece 18 hours ago

Making WebAssembly a first-class language on the Web(hacks.mozilla.org)
292 points | 119 commentspage 3
lasgawe 4 hours ago|
Agree with the points. But when reading this, it seems much more complicated than using JavaScript on the web when developing realworld applications. However I think that will not be an issue because of AI.
shevy-java 4 hours ago||
> Yet, it still feels like something is missing that’s holding WebAssembly back from wider adoption on the Web.

> There are multiple reasons for this, but the core issue is that WebAssembly is a second-class language on the web

It would be nice if WebAssembly would really succeed, but I have to be honest: I gave up thinking that it ever will. Too many things are unsolved here. HTML, CSS and JavaScript were a success story. WebAssembly is not; it is a niche thing and getting out of that niche is now super-hard.

dana321 3 hours ago||
This is a brilliant idea for webassembly, implementing the core browser features as libraries - they should do it.

(though i do like the open code nature of the internet even if a lot of the javascript source code is unreadable and/or obfuscated)

csmantle 5 hours ago||
Another important aspect is that, without an external library like `wabt`, I can't just open Notepad, write some inline WASM/WAT in HTML and preview it in a browser, in the same way that HTML+CSS+JS works. Having to obtain a full working toolchain is not very friendly for quick prototyping and demonstrative needs.
saghm 5 hours ago||
The same limitation exists with "non-web" assembly. It turns out that having languages that compile to assembly makes a lot of sense for almost every real-world use case than writing it by hand.
phickey 5 hours ago||
WebAssembly is a compiler target, not a human-authored language. There is exactly one audience of people for writing wat by hand: spec and tutorial authors and readers. Anyone actually developing an application they want to use will use a compiler to produce WebAssembly. Prove me wrong and write Roller Coaster Tycoon in raw wasm if you want, but having written and maintained wasm specs and toolchains for nearly a decade, I will never write any wat outside of a spec or tutorial.
JoshTriplett 4 hours ago||
There is exactly one case where I'd like to write "raw wat" (and for that matter "raw wasm bytecode"): I'd love to do something like the "bootstrappable builds" project for wasm, starting with a simple wat-to-bytecode parser/translator written in raw bytecode, then some tools wirtten in raw wat for bootstrapping into other languages. :)
patchnull 5 hours ago||
[flagged]
armchairhacker 3 hours ago||
Another example of a top comment that was definitely written by an LLM.

And to be clear, style isn't the only problem. This comment can be summarized as "WebAssembly can now interact with the DOM directly instead of through JavaScript, making it the better choice for more types of problems". One sentence instead of a paragraph of cliches ("...change how people think about this...chicken-and-egg loop..."), uncanny phrases ("...the hot-path optimization niche"), and inaccurate claims ("...the only viable use cases were compute-heavy workloads like codecs and crypto").

(For anyone who doesn't believe me, check the user's comment history)

etaioinshrdlu 3 hours ago|||
What do you think is the incentive to LLM post on HN (or any site?)
homebrewer 3 hours ago|||
The usual answer to this question is building out realistically looking accounts for later spam and/or astroturfing.
aaroninsf 3 hours ago|||
The incentive of the human who deployed it—at one remove or another—would require knowing more. But the more likely cases are easy to guess at, e.g., someone is playing with OpenClaw. I'd guess "someone is playing with OpenClaw and intends to write something about it boost their brand, could be a Show HN could be a LinkedIn screed they hope goes viral."

Could be for fun. I remember fun.

hypeatei 3 hours ago|||
Woah, you're right. The account was created a day ago and writes walls of text everywhere (sometimes multiple on the same thread!)
tcfhgj 4 hours ago|||
> no DOM access meant the only viable use cases were compute-heavy workloads like codecs and crypto,

no, it didn't mean that, because the overhead is not a deal breaker:

1) you don't have to do the glue code (libs can do it for you)

2) there's overhead due to glue, but the overhead is so small that WASM web frameworks easily can compete with fast JS frameworks in DOM heavy scenarios.

Source: Analysis of the creator of Leptos (a web framework based on WASM): https://www.youtube.com/watch?v=4KtotxNAwME

flohofwoe 4 hours ago|||
> but the end state where you import a browser API like any other library in your language is genuinely simpler than the current JS FFI dance.

Tbf, Emscripten has solved this problem long ago - I don't quite understand what's the problem for other language ecosystems.

The JS shim is still there, but you don't need to deal with it, you just include a C header and "link with a library".

Some of the Emscripten-specific C APIs are also much saner than their web counterparts, which is an important aspect that would be lost with an automatic binding approach. And EM_JS (e.g. directly embedding JS code into C/C++ files) is just pure bliss, because it allows to easily write 'non-standard' binding layers that go beyond a simple 1:1 mapping.

Those features won't go away of course, I just feel like the work could be spent on solutions that provide more 'bang for the buck' (yeah, I've never been a fan of the component model to begin with).

nikeee 4 hours ago|||
> the only viable use cases were compute-heavy workloads like codecs and crypto,

I tried using it for crypto, but WASM does not have instructions for crypto. So it basically falls back to be non-hw-accelerated. Tried to find out why and the explanation seems to be that it's not needed because JS has a `crypto` API which uses hw intrinsics.

embedding-shape 4 hours ago|||
> meant the only viable use cases were compute-heavy workloads like codecs and crypto

And games, which the web is now a viable platform for a huge range of them, albeit not the top of the range, AAA and all that (yet?). Also some new graphical editors taking advantage of it, probably Figma being the most famous example so far.

usefulposter 3 hours ago|||
Generated comments are not welcome here. Please respect the guidelines of the community.

https://news.ycombinator.com/newsguidelines.html#generated

>Don't post generated comments or AI-edited comments. HN is for conversation between humans.

shevy-java 4 hours ago||
It will take a LOT more to make WebAssembly win now.

People have the impression that WebAssembly has failed. After so many years, I sort of agree with that notion. WebAssembly is soon 10 years old by the way:

https://en.wikipedia.org/wiki/WebAssembly

mitchbob 17 hours ago||
Discussed 12 days ago (13 comments):

https://news.ycombinator.com/item?id=47167944

tomhow 7 hours ago|
We've decided to give it another try as it didn't get much front page time or discussion.
devwastaken 5 hours ago||
[flagged]
zb3 4 hours ago||
No no no, wasm has shitty speed if you want to emulate something (it doesn't even support JIT), the problem is in its architecture (tons of restrictions like no self modifying code, no jumps).. this can't be fixed, we need something real, something like WebKVM.
titzer 4 hours ago|
On the web you can dynamically create new Wasm modules and use JS APIs to load them, though there are ergonomic issues. There are per-module costs and systems like CheerpJ and CheerpX currently do batching of multiple functions into a module to mitigate the per-module costs.

I've created a proposal to add a fine-grained JIT interface: https://github.com/webassembly/jit-interface

It allows generating new code one function at a time and a robust way to control what the new code can access within the generating module.

hexo 5 hours ago||
[flagged]
dang 3 hours ago|
Could you please stop posting unsubstantive comments? You've unfortunately been doing it repeatedly. It's not what this site is for, and destroys what it is for.

If you wouldn't mind reviewing https://news.ycombinator.com/newsguidelines.html and taking the intended spirit of the site more to heart, we'd be grateful.

pizlonator 6 hours ago|
It's simple.

JavaScript is the right abstraction for running untrusted apps in a browser.

WebAssembly is the wrong abstraction for running untrusted apps in a browser.

Browser engines evolve independently of one another, and the same web app must be able to run in many versions of the same browser and also in different browsers. Dynamic typing is ideal for this. JavaScript has dynamic typing.

Browser engines deal in objects. Each part of the web page is an object. JavaScript is object oriented.

WebAssembly is statically typed and its most fundamental abstraction is linear memory. It's a poor fit for the web.

Sure, modern WebAssembly has GC'd objects, but that breaks WebAssembly's main feature: the ability to have native compilers target it.

I think WebAssembly is doomed to be a second-class citizen on the web indefinitely.

eqrion 6 hours ago||
I'm not sure I follow this.

> WebAssembly is the wrong abstraction for running untrusted apps in a browser

WebAssembly is a better fit for a platform running untrusted apps than JS. WebAssembly has a sandbox and was designed for untrusted code. It's almost impossible to statically reason about JS code, and so browsers need a ton of error prone dynamic security infrastructure to protect themselves from guest JS code.

> Browser engines evolve independently of one another, and the same web app must be able to run in many versions of the same browser and also in different browsers. Dynamic typing is ideal for this. JavaScript has dynamic typing.

There are dynamic languages, like JS/Python that can compile to wasm. Also I don't see how dynamic typing is required to have API evolution and compt. Plenty of platforms have static typed languages and evolve their API's in backwards compatible ways.

> Browser engines deal in objects. Each part of the web page is an object. JavaScript is object oriented

The first major language for WebAssembly was C++, which is object oriented.

To be fair, there are a lot of challenges to making WebAssembly first class on the Web. I just don't think these issues get to the heart of the problem.

perfmode 5 hours ago|||
There's something real in the impedance mismatch argument that I think the replies here are too quick to dismiss. The browser's programming model is fundamentally about a graph of objects with identity, managed by a GC, mutated through a rich API surface. Linear memory is genuinely a poor match for that, and the history of FFI across mismatched memory models (JNI, ctypes, etc.) tells us this kind of boundary is where bugs and performance problems tend to concentrate. You're right to point at that.

Where I think the argument goes wrong is in treating "most websites don't use WASM" as evidence that WASM is a bad fit for the web. Most websites also don't use WebGL, WebAudio, or SharedArrayBuffer. The web isn't one thing. There's a huge population of sites that are essentially documents with some interactivity, and JS is obviously correct for those. Then there's a smaller but economically significant set of applications (Figma, Google Earth, Photoshop, game engines) where WASM is already the only viable path because JS can't get close on compute performance.

The component model proposal isn't trying to replace JS for the document-web. It's trying to lower the cost of the glue layer for that second category of application, where today you end up maintaining a parallel JS shim that does nothing but shuttle data across the boundary. Whether the component model is the right design for that is a fair question. But "JS is the right abstraction" and "WASM is the wrong abstraction" aren't really in tension, because they're serving different parts of the same platform.

The analogy I'd reach for is GPU compute. Nobody argues that shaders should replace CPU code for most application logic, but that doesn't make the GPU a "dud" or a second-class citizen. It means the platform has two execution models optimized for different workloads, and the interesting engineering problem is making the boundary between them less painful.

saghm 4 hours ago||
> The browser's programming model is fundamentally about a graph of objects with identity, managed by a GC, mutated through a rich API surface.

Even more to the point, for the past couple of decades the browser's programming model has just been "write JavaScript". Of course it's going to fit JavaScript better than something else right now! That's an emergent property though, not something inherent about the web in the abstract.

There's an argument to be made that we shouldn't bother trying to change this, but it's not the same as arguing that the web can't possibly evolve to support other things as well. In other words, the current model for web programming we have is a local optimum, but statements like the the one at the root of this comment chain talk like it's a global one, and I don't think that's self-evident. Without addressing whether they're opposed to the concept or the amount of work it would take, it's hard to have a meaningful discussion.

pizlonator 6 hours ago|||
> WebAssembly has a sandbox and was designed for untrusted code.

So does JavaScript.

> It's almost impossible to statically reason about JS code, and so browsers need a ton of error prone dynamic security infrastructure to protect themselves from guest JS code.

They have that infrastructure because JS has access to the browser's API.

If you tried to redesign all of the web APIs in a way that exposes them to WebAssembly, you'd have an even harder time than exposing those APIs to JS, because:

- You'd still have all of the security troubles. The security troubles come from having to expose API that can be called adversarially and can pass you adversarial data.

- You'd also have the impedence mismatch that the browser is reasoning in terms of objects in a DOM, and WebAssembly is a bunch of integers.

> There are dynamic languages, like JS/Python that can compile to wasm.

If you compile them to linear memory wasm instead of just running directly in JS then you lose the ability to do coordinated garbage collection with the DOM.

If you compile them to GC wasm instead of running directly in JS then you're just adding unnecessary overheads for no upside.

> Also I don't see how dynamic typing is required to have API evolution and compt.

Because for example if a browser changes the type of something that happens to be unused, or removes something that happens to be unused, it only breaks actual users at time of use, not potential users at time of load.

> Plenty of platforms have static typed languages and evolve their API's in backwards compatible ways.

We're talking about the browser, which is a particular platform. Not all platforms are the same.

The largest comparable platform is OSes based on C ABI, which rely on a "kind" of dynamic typing (stringly typed, basically - function names in a global namespace plus argument passing ABIs that allow you to mismatch function signature and get away with it.

> The first major language for WebAssembly was C++, which is object oriented.

But the object orientation is lost once you compile to wasm. Wasm's object model when you compile C++ to it is an array of bytes.

> To be fair, there are a lot of challenges to making WebAssembly first class on the Web. I just don't think these issues get to the heart of the problem.

Then what's your excuse for why wasm, despite years of investment, is a dud on the web?

eqrion 5 hours ago|||
> If you compile them to GC wasm instead of running directly in JS then you're just adding unnecessary overheads for no upside

Language portability is a big feature. There's a lot of code that's not JS out there. And JS isn't a great compilation target for a lot of languages. Google switched to compiling Java to Wasm-GC instead of JS and got a lot of memory/speed improvements.

> Because for example if a browser changes the type of something that happens to be unused, or removes something that happens to be unused, it only breaks actual users at time of use, not potential users at time of load. > The largest comparable platform is OSes based on C ABI, which rely on a "kind" of dynamic typing (stringly typed, basically - function names in a global namespace plus argument passing ABIs that allow you to mismatch function signature and get away with it.

I don't think any Web API exposed directly to Wasm would have a single fixed ABI for that reason. We'd need to have the user request a type signature (through the import), and have the browser maximally try and satisfy the import using coercions that respect API evolution and compat. This is what Web IDL/JS does, and I don't see why we couldn't have that in Wasm too.

> Then what's your excuse for why wasm, despite years of investment, is a dud on the web?

Wasm is not a dud on the web. Almost 6% of page loads use wasm [1]. It's used in a bunch of major applications and libraries.

[1] https://chromestatus.com/metrics/feature/timeline/popularity...

I still think we can do better though. Wasm is way too complicated to use today. So users of wasm today are experts who either (a) really need the performance or (b) really need cross platform code. So much that they're willing to put up with the rough edges.

And so far, most investment has been to improve the performance or bootstrap new languages. Which is great, but if the devex isn't improved, there won't be mass adoption.

titzer 7 minutes ago|||
> Language portability is a big feature. There's a lot of code that's not JS out there. And JS isn't a great compilation target for a lot of languages. Google switched to compiling Java to Wasm-GC instead of JS and got a lot of memory/speed improvements.

It's also worth noting that Wasm wasn't born into a vacuum like JS was (and Java for that matter), so it is competing[1] in a crowded space. Wasm is making inroads into languages that already have well-developed toolchains and ecosystems like Java, Kotlin, Rust, Scala, and Go. I think the Wasm network effect is happening, it is just very slow because it's primarily been a deployment platform and not a development platform.

It's also worth noting that Wasm advancement is pretty decentralized and there are a lot of competing interests, particularly outside the web. Basically every other language had at least one massive investment in both language development and tooling from the get-go. Java=sun, C#=Microsoft, Go=Google, JavaScript=browsers, Scala=foundation, etc.

[1] "competing" only in the sense of adding value over the mainstream or mainline implementations of these languages.

> Wasm is way too complicated to use today. So users of wasm today are experts who either (a) really need the performance or (b) really need cross platform code. So much that they're willing to put up with the rough edges.

I believe we can do better; we've been counting on languages that come to Wasm as a secondary deployment strategy and have their primary devex focused on another platform where then can debug better and offer better tooling.

pizlonator 5 hours ago|||
> Language portability is a big feature.

It's a big feature of JS. JS's dynamism makes it super easy to target for basically any language.

> Google switched to compiling Java to Wasm-GC instead of JS and got a lot of memory/speed improvements.

That's cool. But that's one giant player getting success out of a project that likely required massive investment and codesign with their browser team.

Think about how sad it is that these are the kinds of successes you have to cite for a technology that has had as much investment as wasm!

> Almost 6% of page loads use wasm

You can disable wasm and successfully load more than 94% of websites.

A lot of that 6% is malicious ads running bitcoin mining.

> Wasm is way too complicated to use today.

I'm articulating why it's complicated. I think that for those same reasons, it will continue to be complicated

swiftcoder 6 hours ago||||
> Then what's your excuse for why wasm, despite years of investment, is a dud on the web?

It's not really a dud on the web. It sees a ton of use in bringing heavier experiences to the browser (i.e Figma, the Unity player, and so on).

Where it is currently fairly painful is in writing traditional websites, given all the glue code required to interact with the DOM - exactly what these folks are trying to solve.

pizlonator 5 hours ago||
Figma is one site. There are also a handful of other sites that use wasm. But most of the web does not use wasm.

> Where it is currently fairly painful is in writing traditional websites, given all the glue code required to interact with the DOM - exactly what these folks are trying to solve.

I don't think they will succeed at solving the pain, for the reasons I have enumerated in this thread.

swiftcoder 5 hours ago||
I mean, you are obviously entitely to your opinion, but folks have been solving this stuff the hard, glue-based way for ages now, and are using WASM wherever there is an advantage to do so. Getting rid of the glue layer and the associated performance problems can only accelerate those efforts
pizlonator 5 hours ago||
> I mean, you are obviously entitely to your opinion

I'm trying to explain to you why attempts to make wasm mainstream have failed so far, and are likely to continue to fail.

I'm not expressing an "opinion"; I'm give you the inside baseball as a browser engineer.

> Getting rid of the glue layer

I'm trying to elucidate why that glue layer is inherent, and why JS is the language that has ended up dominating web development, despite the fact that lots of "obviously better" languages have gone head to head with it (Java, Dart sort of, and now wasm).

Just like Java is a fantastic language anywhere but the web, wasm seems to be a fantastic sandboxing platform in lots of places other than the web. I'm not trying to troll you folks; I'm just sharing the insight of why wasm hasn't worked out so far in browsers and why that's likely to continue

swiftcoder 5 hours ago||
> why JS is the language that has ended up dominating web development

JS was dominating web development long before WASM gained steam. This isn't the same situation as "JS beating Java/ActivX for control of the web" (if I follow the thrust of your argument correctly).

WASM has had less than a decade of widespread browser support, terrible no-good DevEx for basically the whole time, and it's still steadily making it's way into more and more of the web.

pizlonator 5 hours ago||
WebAssembly has had extraordinary levels of investment from browser devs and the broader community.

> terrible no-good DevEx for basically the whole time

I'm telling you why.

> still steadily making it's way into more and more of the web.

It is, but you can still browser the web without it just fine, despite so much investment and (judging by how HN reacts to it) overwhelming enthusiasm from devs

saghm 4 hours ago|||
> Because for example if a browser changes the type of something that happens to be unused, or removes something that happens to be unused, it only breaks actual users at time of use, not potential users at time of load.

I don't understand this objection. If you compile code that doesn't call a function, and then put that artifact on a server and send it to a browser, how is it broken when that function is removed?

saghm 5 hours ago|||
I'm not convinced JavaScript is a great abstraction for the browser as much as we've forced the web into a shape that fits JavaScript because of a lack of viable alternatives. I'd argue that the popularity of TypeScript implies that dynamic typing is not a universal ideal. Browser engines deal in objects because they're currently all built on top of JavaScript only; that doesn't demonstrate anything fundamental about the web that implies object oriented is the only reasonable representation.

If it gets stuck as a second-class citizen like you're predicting, it sounds a lot more like it's due to inflexibility to consider alternatives than anything objectively better about JavaScript.

flohofwoe 6 hours ago||
That's just like your opinion man ;)

(I'm not a fan of the WASM component model either, but your generalized points are mostly just wrong)

pizlonator 6 hours ago||
Then give me a counterargument instead of just saying that I'm wrong.

My points are validated by the reality that most of the web is JavaScript, to the point that you'd have a hard time observing degradation of experience if you disabled the wasm engine.

flohofwoe 6 hours ago||
I created and maintain a couple of WASM projects and have not experienced the problems you describe:

- https://floooh.github.io/tiny8bit/

- https://floooh.github.io/sokol-webgpu/

- https://floooh.github.io/visualz80remix/

- https://floooh.github.io/doom-sokol/

All those projects also compile into native Windows/Linux/macOS/Android/iOS executables without any code changes, but compiling to WASM and running in web browsers is the most painless way to get this stuff to users.

Dealing with minor differences of web APIs in different browsers is a rare thing and can be dealt with in WASM just the same as in JS: a simple if-else will do the job, no dynamic type system needed (apart from that, WASM doesn't have a "type system" in the first place, just like CPU instruction sets don't have one - unless you count integer and float types as type system"). Alternatively it's trivial to call out into Javascript. In Emscripten you can even mix C/C++ and Javascript in the same source file.

E.g. for me, WASM is already a '1st class citizen of the web' no WASM component model needed.

pizlonator 6 hours ago|||
The fact that you made some webassembly things isn't an answer to the question of why webassembly is not used by the overwhelming majority of websites.
saghm 4 hours ago|||
That's a fairly arbitrary metric. The overwhelming majority of code running outside of the browser on my laptop isn't in Python, but it's hard to argue that's evidence of it being "doomed to being a second-class citizen on my desktop indefinitely".
flohofwoe 6 hours ago|||
> why webassembly is not used by the overwhelming majority of websites

This is such a bizarre take that I don't know whether it's just a trolling attempt or serious...

Why should web-devs switch to WASM unless they have a specific problem to solve where WASM is the better alternative to JS? The two technologies live side by side, each with specific advantages and disadvantages, they are not competing with each other.

pizlonator 6 hours ago||
> This is such a bizarre take that I don't know whether it's just a trolling attempt or serious...

I'm being serious.

> Why should web-devs switch to WASM unless they have a specific problem to solve where WASM is the better alternative to JS?

They mostly shouldn't. There are very few problems where wasm is better.

If you want to understand why wasm is not better, see my other posts in this thread.

skybrian 6 hours ago|||
What toolchain do you use to build your apps?
flohofwoe 5 hours ago||
Vanilla Emscripten. Most of the higher level platform abstraction (e.g. window system glue, 3D APIs or audio APIs) happens via the sokol headers though:

https://github.com/floooh/sokol