Then why does WASM exist? If someone wants to compile whatever other language to run in the browser, why not just compile it to well-written JavaScript?
Simple: Javascript can focus on being a human-friendly programming language, while WASM can focus on being a compile target. If you've been around in the asm.js times, this conflict was a real concern.
That does not answer the question what the benefit of compiling to WASM rather than to JavaScript is.
If speed is fine, why would I care if a compiler compiled to a human-friendly language?
Unless you want to install a crypto miner to run locally on someone's machine when they visit a website. Now possible with this as well as even more capable closed-source untrusted binary blobs with DRM running amock on your machine. Mozilla (a member part of the W3C) and was supposed to stop such DRM-like software from reaching the web. They have proven to be powerless to allow such software like this to be approved…
Crypto miners written in JS existed long before WebAssembly. Back then people also compiled large C++ code bases to (highly obfuscated) JS code and out of these heroic efforts grew asm.js which then evolved to WebAssembly. WebAssembly is a much better compile target than JS with more low-level types and primitives, but it's very similar to JS code in what it can and can't do in the browser.
Compiling a C++ application to megabytes of JS code doesn't make the result any more open-source or non-DRM than compiling the same thing to WebAssembly (you could translate Wasm to the equivalent but slower JS code).
Then why does WASM exist? If someone wants to compile whatever other language to run in the browser, why not just compile it to well-written JavaScript?
Mozilla tried that with asmjs. Turns out javascript has pretty half-assed semantics (notably around integer types), nobody wants to expand it to a useful compilation (asmjs was mostly an optimisation for hand-written code) target, and few want to compile to text, especially javascript. Having a proper and well defined ISA is a lot more compelling. Not only that, but it allows WASM-only compilers and runtimes with non…
That makes it sound like WASM only exists because of the nerdy preferences of compiler makers, not because of any benefits to the users of applications?
If speed is fine, why would a user care if the application was compiled to a language with "half-assed semantics" in a text format?
Mozilla tried that with asmjs. Turns out javascript has pretty half-assed semantics (notably around integer types), nobody wants to expand it to a useful compilation (asmjs was mostly an optimisation for hand-written code) target, and few want to compile to text, especially javascript. Having a proper and well defined ISA is a lot more compelling. Not only that, but it allows WASM-only compilers and runtimes with non…
That makes it sound like WASM only exists because of the nerdy preferences of compiler makers, not because of any benefits to the users of applications? If speed is fine, why would a user care if the application was compiled to a language with "half-assed semantics" in a text format?
Yes, but think of DCC applications like Figma which might run into the 4 GB restriction with large data sets, not regular websites which run a couple of WebGL demos written in C. ...also WASM is starting to become popular outside the browser where requirements might be very different from running stuff in webpages.
Let figma ask me for explicit permission first, then, as opposed to making Memory64 support implicitly available.
...what's different than running any other application that uses more than 4 GB RAM on your computer, and why exactly 4 GB and not any other number? You can easily check the per-page memory footprint in Chrome's task manager and decide not to use such 'memory hogs'.
Simple: Javascript can focus on being a human-friendly programming language, while WASM can focus on being a compile target. If you've been around in the asm.js times, this conflict was a real concern.
That does not answer the question what the benefit of compiling to WASM rather than to JavaScript is. If speed is fine, why would I care if a compiler compiled to a human-friendly language?
Because Javascript would need to change a lot to better support compiled languages (for instance adding 'proper' separate integer and float types, but that's just the tip of the iceberg). This means extending the ECMAScript standard with features only few web developers care about, increased complexity in JS engines, and potential design-conflicts for new JS features between 'compile-friendly' vs 'human-friendly'. With WASM, the WASM peeps can focus on WASM and the JS peeps can focus on JS.
That makes it sound like WASM only exists because of the nerdy preferences of compiler makers, not because of any benefits to the users of applications? If speed is fine, why would a user care if the application was compiled to a language with "half-assed semantics" in a text format?
I don't think speed is fine. Here's a write-up from Mozilla which talks about the performance benefits of WASM compared to asm.js: https://hacks.mozilla.org/2017/03/why-webassembly-is-faster-...
FWIW, switching from asm.js to wasm in was hardly noticeable performance-wise for my code (at least in browsers that already had a special 'fast-path' for asm.js).
Looking forward to progress on the memory control proposal(s).
Another reason to want more than 4GB of memory is to have more address space, assuming that you have the ability to map it. With that capability Wasm64 could be useful also for apps that don't plan to use a huge amount for real.
You can do that easily with binaryen already, and make use of parseText(). https://web.dev/articles/binaryen
Not sure what you mean. I guess this is a misunderstanding. What I mean is that I would like something like this to work: code = `( func $add (param $a i32) (param $b i32) (result i32) local.get $a local.get $b i32.add )`; module = WebAssembly.compile(code); alert(module.add(3, 5)); // alerts "8".
The WebAssembly reference interpreter [0] has a JS library that lets you do this.
let wast = require("./wast.js");
let binary = wast.WebAssemblyText.encode("(module)");
The Memory64 proposal is for >4gb space -- and specifically to use it, not just reserve it. Learn context before commenting.
On the flip side, it would do you well to read this: https://news.ycombinator.com/newsguidelines.html. As for the actual content of your comment, pages already have access to more than 4 GB of RAM. It's actually quite easy to do just from JavaScript.