Hacker News new | past | comments | ask | show | jobs | submit login

good point. in a sense webassembly is that minimal very performant language. let javascript and typescript compile to webassembly, and you essentially got what is being proposed here



WebAssembly could replace JavaScript, the assembly language, once it has reached feature parity.

But there's still far to go. Large parts of the browser API are still not directly available in WASM.

I very much look forward to WASM reaching stability. It's very enjoyable to run Rust code in the browser.


What parts are not available?

WebAssembly can call arbitrary JavaScript through imports. You could literally provide an `eval` function if you were motivated to.


direct access to the DOM for example without having to go through the javascript host, which is slow and makes DOM intensive applications impractical


The DOM itself is very slow, much slower than Javascript, so you're not going to be seeing any great performance increase if WASM can access the DOM directly.

I also have to wonder if people are excited about replacing Javascript, why they would want to have HTML/CSS/DOM on top of WASM. A different front-end UI tech could be much better than slow, old DOM.


All imports have to come from the host, which in the case of the web means they have to be expressed as JavaScript. Behind the scenes they could be optimized, though, and I've heard that JS/Wasm engines maybe already be doing this with well-known imports (think Math.sin).


Or you can just draw to canvas to make the UI fast which is what Flutter does now:

https://flutterweb-wasm.web.app/

https://www.youtube.com/watch?v=Nkjc9r0WDNo


Drawing to canvas means recreating the UI and all its wide-sweeping concerns, which is quite an undertaking. And even if it were accomplished in a central open source library like Flutter, that adds a considerable amount to the package size of any application. Acceptable (or even preferred) for certain applications but not for most.

Providing access to an already proven DOM would be the better solution.


> And even if it were accomplished in a central open source library like Flutter, that adds a considerable amount to the package size of any application.

The download isn't much different to a typical website. That Flutter demo in wasm is 2 megabytes.

Avalonia UI's WebAssembly uses canvas in C#: https://avaloniaui.net/

Uno Platform's WebAssembly implementation uses the DOM rather than drawing to canvas: https://platform.uno/

Uno's philosophy is to use platform native controls. The benefit is that you get platform native characteristics, the cost is it will never be exactly the same in each browser and platform.


You're joking, right? A 2mb bundle is *absolutely unacceptable*. People complain about React which is less than 100kb minified and gzipped. This website doesn't even include any images or anything...


It's clearly not. Real world applications exist today. Here's one:

https://earth.google.com/


2mb for Google Earth might be fine, but Google Earth is not your typical web app.

A 2mb base floor before any code or assets is not acceptable for most use cases.


What would access to the DOM look like? WASM already has import and export (nearly) arbitrary functions. People keep saying it can't manipulate the DOM, but it clearly can. So, what's missing?


What is missing is that I never want to touch js for anything, so how do I do that if I have to write glue and imports in js/ts?


I thing we agree. JavaScript is awful, and TypeScript is simultaneously impressive and still awful. I think we have three options:

A) Get your hands dirty and write what you want. Once.

B) Chant along with the mob who doesn't even understand what they're asking for.

C) Wait several years for some super complicated solution to be designed by committee.

I wouldn't even want direct access to the DOM if we had it today. The DOM as an API is atrocious.

Instead, I want a set of nice functions that do things like put a graphical chart on the page - all in one call. Or one call to pass a bunch of 3D triangles or splats to visualize in a WebGL canvas. Or one call to play some audio samples. Or a function to poll for recording audio. And so on...

I choose option A.


there is also option D.

wait for a framework that implements option A.

if option A works, why aren't there any frameworks yet that implement it?

maybe all the framework devs are waiting for C?

but why?

you could be right about A but at present the majority view seems to be that C is the right option. which is what pushes me into going with B because i have no interest in developing my own framework.

if a framework appears that implements option A i'll gladly consider it. (just as long as it isn't tightly coupled with a backend)


So throwing out literally 99% of what makes the web actually portable and useful?

A random drawn rectangle is not a UI, it’s not accessible, not inspectable, not part of the de facto OS native toolkit.

If all we wanted is a random cross-platform canvas element to draw onto from a vm, it could be solved in a weekend. There are million examples of that.


> A random drawn rectangle is not a UI

Of course it is. All screen based user interfaces are blinking lights.

> it’s not accessible

It's best to read the documentation first. It's a low effort thing to do:

https://docs.flutter.dev/ui/accessibility-and-internationali...


Its web targeted version is still not accessible, even though they promised that they will actually render to HTML elements as much as possible. A single canvas element is not that.


If you're not going to read the documentation, read a blog post:

https://medium.com/flutter/accessibility-in-flutter-on-the-w...


From your own article:

> The Flutter team would like to eventually turn the semantics on by default in Flutter Web. However, at the moment, this would lead to noticeable performance costs in a significant number of cases, and requires some optimization before the default can be changed


Ah, so you admit it does indeed include accessibility but now what you're complaining about is performance. Not that you've actually tried it of course.

But good. That's a kind of progress.


Can you give an example of anything anywhere that manipulates the DOM without using JavaScript? Because it seems to me that pretty much every web application is currently using the javascript host, and the well written ones are pretty snappy.


this is going beyond my level of experience, but i thought there can't be any such example because javascript is the only way. the difference is between code written in javascript which is fast of course and accessing js functions from WASM, which is slower. how much slower, i don't know. i also don't know how old that discussion is where i learned about this. so maybe it improved since. that would be good news.

did you mean there are snappy webapplications running in WASM? if you have any examples, i'd be curiuos to learn more.


> i thought there can't be any such example because javascript is the only way. the difference is between code written in javascript which is fast of course and accessing js functions from WASM

That doesn't have to be true.

Eventually WASM will get direct access to the full browser API, without going through JavaScript.

The browser exposes a browser API to the JavaScript VM it hosts, so things like the DOM are available.

Those things aren't available in other JavaScript VMs, like Node. (There's no DOM to interact with.)

And they're not yet available in the WASM VM in the browser, either.

The reason is that the WASM APIs/ABIs have not stabilised. It takes time to make right, but there is progress.


That doesn't have to be true.

Eventually WASM will get direct access to the full browser API, without going through JavaScript.

well, that is what i am waiting for. my point is that it's not the case yet, while the gp seemed to suggest that it's not needed because access through the host is available


A fundamental aspect of the Wasm capability security model is that all access to the outside world (I/O) is controlled via imports. Direct access to the entire browser API doesn't make sense in this context.


Previously you said:

> [...] go through the javascript host, which is slow

And now you admit:

> this is going beyond my level of experience [...]

> how much slower, i don't know

I guess people just repeat what they hear without questioning or understanding it, and then it becomes dogma.

> did you mean there are snappy webapplications running in WASM?

No. I meant that all existing web apps go through the "javascript host", using JavaScript. So if any of them are fast enough, and some certainly are, the problem isn't the "javascript host".


you are not answering my question. most existing webapps are not running inside WASM.

i am only talking about webapps running inside WASM. are there any WASM based webapps that are as fast as pure js webapps?


> you are not answering my question

Lol, your question asked me what I meant. I told you what I meant.

> are there any WASM based webapps that are as fast as pure js webapps?

You can browse links from Google for examples and benchmarks. Maybe one of these will scratch your itch, but I won't vouch for any of them:

https://madewithwebassembly.com/

But really, JavaScript and WebAssembly are both very fast. I don't think speed is the reason to choose one or the other.

For me, I like WebAssembly because it lets me program in languages other than JavaScript. JavaScript makes me want to scratch my eyes out.


right, making those APIs accessible from WASM is something i am also waiting for.


So you want more rights for code that’s harder to read than obfuscated JS?


I commented this elsewhere, but the funny thing is that asm.js was the precursor to WebAssembly, and this proposal is essentially asking for asm.js back again.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: