Live data from Hacker News

Rust and WebAssembly in 2019

fitzgeraldnick.com

41–50 of 97 posts

Re: Rust and WebAssembly in 2019

#41

It didn't click until just now that rust is very naturally suited to WebAssembly due to its lack of garbage collection. As I understand it, there's no current plans for WebAssembly to include a garbage collector, so higher level languages that want to compile to it will need to bundle their own, increasing the size of the download quite a bit.

Yep! This is a key insight. Even beyond that, there are two approaches you can take: writing your app in wasm, or writing libraries in wasm. Languages with larger runtimes may work for apps, but you don’t want to use them for libraries, because then you lug around every runtime for every language used. Even once wasm can integrate with the host’s GC, non-GC’d languages will have a place in implementing core libraries…

[deleted]

Re: Rust and WebAssembly in 2019

#43
post #39

Until there is direct DOM access within WebAssembly, the overhead of calling back and forth to JS will prevent wider adoption and ditching JS for Web development.

That overhead has been greatly reduced in Firefox recently.

Can you explain more what changed? Super interested in this.

Re: Rust and WebAssembly in 2019

#44
post #31

Can WebAssembly be used without any JavaScript? Or JavaScript is always required in some combination with it?

It cannot be used without javascript because it currently has no interface to the DOM.

Without DOM access, you're simply running a virtual machine isolated from everything else, and that would serve no purpose aside from burning clock cycles :).

It is currently felt that Webassembly shouldn't be given access to the DOM until after a garbage collection interface is created. Until that happens, any object given to the WASM runtime cannot be safely destroyed, as the browser doesn't know, and WASM has no way of indicating, that something, such as a reference to a div element, is still needed.

Currently, the simplest[1] and most secure way of working out how a given runtime should interface with the browser is to build that compatibility layer in javascript, and expose callbacks to the WASM runtime(which is defined). This lets developers write their own DOM-interface shim, allowing them to explore the possibility space, and not accidentally restrict which languages can be implemented in WASM.

[1] From the point of view of browser vendors and standards bodies.

Re: Rust and WebAssembly in 2019

#45
post #31

Can WebAssembly be used without any JavaScript? Or JavaScript is always required in some combination with it?

It cannot be used without javascript because it currently has no interface to the DOM. Without DOM access, you're simply running a virtual machine isolated from everything else, and that would serve no purpose aside from burning clock cycles :). It is currently felt that Webassembly shouldn't be given access to the DOM until after a garbage collection interface is created. Until that happens, any object given to the…

[deleted]

Re: Rust and WebAssembly in 2019

#47

Earlier quoted context omitted.

Yep! This is a key insight. Even beyond that, there are two approaches you can take: writing your app in wasm, or writing libraries in wasm. Languages with larger runtimes may work for apps, but you don’t want to use them for libraries, because then you lug around every runtime for every language used. Even once wasm can integrate with the host’s GC, non-GC’d languages will have a place in implementing core libraries…

This only applies to libraries served from separate locations though, right? No issue writing a Haskell library for wasm and then having consumers compile their app leveraging your library (at which point it's bundled with the RTS)

I’m not sure what the serving part has to do with it; if I have a ruby library and a python library and I use them from a Haskell app, I’m getting three runtimes, regardless of if they’re bundled together or not.

Re: Rust and WebAssembly in 2019

#48
post #31

Can WebAssembly be used without any JavaScript? Or JavaScript is always required in some combination with it?

It cannot be used without javascript because it currently has no interface to the DOM. Without DOM access, you're simply running a virtual machine isolated from everything else, and that would serve no purpose aside from burning clock cycles :). It is currently felt that Webassembly shouldn't be given access to the DOM until after a garbage collection interface is created. Until that happens, any object given to the…

Thanks for clarifying the reason behind it!

Re: Rust and WebAssembly in 2019

#49
post #26
post #15

Earlier quoted context omitted.

> As I understand it, there's no current plans for WebAssembly to include a garbage collector There are plans to add a garbage collector. See https://hacks.mozilla.org/2018/10/webassemblys-post-mvp-futu... . But meanwhile, Webassembly is mainly just for C and Rust.

> Webassembly is mainly just for C and Rust That's absolutely incorrect. Go and .NET can target WASM for quite a while now. Microsoft's Blazor is specially interesting. Their FlightFinder demo written in pure C# renders a beautiful app: https://i.imgur.com/HHFkB1E.png Code here: https://github.com/aspnet/samples/tree/master/samples/aspnet...

This is literally true, but last I checked, Go’s minimum size was about a megabyte, Blazor’s was 300k, and Rust’s is ~100 bytes. That’s what your parent means.

Re: Rust and WebAssembly in 2019

#50

It didn't click until just now that rust is very naturally suited to WebAssembly due to its lack of garbage collection. As I understand it, there's no current plans for WebAssembly to include a garbage collector, so higher level languages that want to compile to it will need to bundle their own, increasing the size of the download quite a bit.

The word "assembly" should have clued you in haha. And the "observation" applies to any natively compiled language, garbage collector or otherwise.
Post reply on HN