394 points · by AndrewDucker · 10y ago · 262 comments
https://blogs.windows.com/msedgedev/2016/03/15/previewing-we... https://v8project.blogspot.com/2016/03/experimental-support-... https://hacks.mozilla.org/2016/03/a-webassembly-milestone/
introducing support for the live demo:
Overall a huge thanks to our friends at Mozilla and Microsoft and Apple, with whom we've worked closely with over the past year to make this a reality.
From glossing over the wasm spec, it seems it's designed for C++ compilation, which in the environment I do development, is totally impractical. It sounds like a TypeScript to WebAssembly compiler isn't on Microsoft's radar. In that case, it might be time to work on some tools for analyzing syntax and start annotating types, because compiling from ECMAScript to WebAssembly would be a great boon in production.
Update: Here's a quote from the Microsoft announcement:
"Despite being an early implementation, the demo starts-up significantly faster than just using asm.js as the WebAssembly binaries have a smaller file size and parse more quickly than plain JavaScript that needs to be parsed in the asm.js case."
https://blogs.windows.com/msedgedev/2016/03/15/previewing-we...
A javascript application compiled to wasm doesn't really make sense. Javascript isn't a compiled language. The best you could do would be to store some kind of compressed representation of the source code, along with a JIT compiler to run that source code. It isn't a sensible thing to do.
Similar to asking why would you want to run JavaScript on the server?
There's something to be said for having your code in a single language. People can move to different parts of the project more easily and if you need to run the code in multiple places then you can do so with (mostly) a single codebase.
The real question is why WOULDN'T you compile all your JavaScript to wasm assuming the build process is easy enough. For complex site that already have a build pipeline I don't see any reason to publish minified JavaScript instead of just building it all into wasm for performance reasons (assuming mature debugging tools of course). The only question I'd have is whether you get that much gain by going from JavaScript to wasm or if the browser's JIT compiler can do a good enough job.
I'm not sure why, if you like JS, people can keep on using JS indefinitely. My theory on programming is to use the language that I prefer, and worry about everything else secondary. For me that's Python. I've mostly avoided any deep dives on learning JS so it'll be nice to be a part of a budding Python web frontend community when the time comes.
Speed. Oh and memory - if I could optimize it so that all our vectors, matrices and logic code did only stack allocations I would be a happy camper.
Why don't you compile into native platforms?
Looking at dependencies for certain key Javascript libraries makes me skeptical now that this is possible.
AOT compiling highly dynamic languages gives you very little room for optimizations.
That's not going to work well, I'm afraid.
JavaScript is a highly-dynamic language, and as a result, requires JITs that do runtime type profiling, type inference, and type-specialized code generation, in order to be fast.
WebAssembly is a low-level, statically typed language. It's like a portable C with a small binary footprint.
Even if you annotate and/or detect some of the JavaScript types at compile time, if you don't have them all, that means compiling JavaScript to WebAssembly will result in code that everywhere does "if this type, do that; if that type, do this". That's going to be bigger in code size than JavaScript currently is. It's also going to run much slower.
If you did type every single thing in your JavaScript program, somehow, then that might work well. But that's not really JavaScript anymore (or even TypeScript, etc.).
It's not asm.js, it isn't C (but it was ported from C), but it's JavaScript and it has no dynamic allocations. No variable uses more than one type. I could hand fashion asm.js and WebAssembly code and tell you which one is faster.
That's the only answer to whether a JavaScript to WebAssembly compiler would be worthwhile.
1. https://github.com/WebAssembly/design/blob/master/AstSemanti...
WebAssembly doesn't have a garbage collector (yet) which is essential for JavaScript and many other high-level languages. Shipping a garbage collector compiled to WebAssembly is going to make downloads much larger, and it's likely going to perform worse than the native garbage collector.
A compiler for a garbage-collected language is probably better off targeting JavaScript, not WebAssembly. There are already lots of languages that do this: GWT, Dart, Kotlin, ClosureScript, Elm, etc. There was already plenty of work to do for a compiler expert even before WebAssembly came along.
If only 50% of users are running the WebAssembly version of a product, and 50% are running the JavaScript version of the product, then both need to be stable.
Developing in an unrelated language is unlikely to help.
[1]: https://internals.rust-lang.org/t/need-help-with-emscripten-...
The wasm backend though is in upstream LLVM, so rustc can use it directly, bypassing emscripten for translation of Rust.
[1]: https://github.com/WebAssembly/design/blob/master/GC.md#gc--...
[0]: https://www.w3.org/community/webassembly/
[1]: https://github.com/WebAssembly/design/blob/master/TextFormat...
[2]: https://github.com/WebAssembly/design/blob/master/Tooling.md
We should make sure that browsers refuse to run any code in the future that isn’t available in its full source.
Yes, that includes ReCaptcha
/me looks angrily at Google
It's only through dynamic tools that we can even begin to understand minified JS today. Those are actually quite excellent: just try by starting the react or relay tools on facebook.
That ecosystem is hopefully not changing, so what remains is simply that the format is now binary. I agree that that makes me somewhat uncomfortable but realistically it doesn't really change anything.
View-source is an explicit goal of WebAssembly's first launch: https://github.com/WebAssembly/design/blob/master/FAQ.md#wil...
Web Assembly is a small step toward better human inspectability of the compiled blobs your browser is executing, compared to Flash, Java, and asm.js. To be sure, it doesn't mandate that the source be available in the form preferred for editing. But the Web hasn't done that since 1997.
Understand that Wasm is ideally just an alternate way to drive the same virtual machine that Javascript currently manipulates. This isn't the same thing as, say, a NPAPI plugin like Flash was. Wasm is still subject to the same security restrictions as the rest of the web platform.
Furthermore, and I could be wrong here, but I believe that the "binary" representation of Wasm is really just custom, trivially-reversible compression for faster data transfer and parsing. The OP even mentions that a "standard textual representation" is the next step on the agenda, which I imagine will work similarly to today's source maps for code that compiles to Javascript.
Unless you know the source language, and have some sort of reverse-compiler (or source maps), then getting back to a readable/usable source isn't so easy. Though that doesn't mean you can't trace through what goes down the wire, it won't be quite as low-level as x86 assembly, but will be lower level than most are comfortable with.
Today I can already do that -- look at the output of the Google closure compiler with advanced optimizations turned on. Sure it is javascript and not binary, but all comments have been removed, all variables have been given short and meaningless names that are frequently reused and all the structures have been turned inside out.
And those optimizations are only for speed.
I wonder if this will make it's way into WebKit, and if so its implications for Xombrero, will I have to maintain a seperate WASM whitelist, or disabling JS will disable it too? TBH I plan not allowing even the most trustible website run such code on my computer.
Will I have the ability to write a library in one language and use it in another as long as they both compile to wasm?
That said, modern JS, aside from getting all the tooling bootstrapped, is pretty nice to work with imho. There are also a lot of compile-to-js options, and with better sourcemap support, it's pretty clean to use.
wasm will lean heavily towards code that needs to be more secure, as well as code that needs absolute performance (gaming mostly)...
As to security, using a redux-like workflow, where all action creators use message calls to a websocket connected server-side redux store, then the updates dispatched to the client's store to the UI, so that all logic is at the server would probably be a cleaner and more secure abstraction than wasm though.
It will according to multiple sources:
"In fact, not only will the JavaScript engine be exposed to WebAssembly modules, but so will the DOM. This means you could, in theory, write whole web applications in C and/or C++ and/or other languages that compile into WebAssembly" [1]
"Beyond the MVP (Minimum Viable Product), another high-level goal is to improve support for languages other than C/C++. This includes allowing WebAssembly code to allocate and access garbage-collected (JavaScript, DOM, Web API) objects." [2]
[1] http://moduscreate.com/webassembly-explained/ [2] https://github.com/WebAssembly/design/blob/master/FAQ.md
Just like it won't have dynamic linking, SIMD, shared memory (pthreads) or support for garbage collected languages.
It's worth noting that those features were already on the path to being added to it asm.js before webassembly was even being worked on. Most of them are still going to make it to asm.js first.
You cant port the entire applet infrastructure since WASM is limited to the same API as Javascript. If WASM doesn't support multithreading, languages targetting WASM wont.
Things missing are usually specific external protocols. e.g. being able to make a TCP socket; (or higher level things like ignoring CORS).
It probably won't be as fast though but for legacy Flash content that would be fine.
Furthermore d3, typescript and jquery is javascript so the question is more like "do I need to learn how to use tools to make websites?" at which point it is kind of silly.
edit: this might actually work for some people, once you can access dom elements directly, but for now it is meant for huge WebApps, like games in the browser
That said, this should allow you to target a canvas element, with minimal JS binder to wasm code... all logic including what gets rendered could be outside JS... but you'd have to think of and control all input/output, and there are other considerations for rendering performance.
If you make few more steps in that direction, you can simply write your own operating system, make native apps for it and then call it all "a website", because you can run it in a browser using e.g. this JS computer simulator https://copy.sh/v86/
It is unlikely to ever compete battery-wise with hardware support for a codec, however.
* Assuming we're smart about security check elimination and SIMD codegen, which are both hard to do right.
It's used in production on Wikipedia: https://www.mediawiki.org/wiki/Extension:TimedMediaHandler/o...
More general-purpose GC will be supported, but not in the initial release: https://github.com/WebAssembly/design/blob/master/GC.md
Because that would pretty cool.
This allows rudimentary interop between JS and WASM, and dynamic linking will make it possible to deliver your WASM application in separate pieces, e.g. a large, rarely-changing library that is cached, precompiled, by the browser, and a small, often-changing application piece.
The hard part there is the "eventually". They do state that the missing pieces will come some time after the "Minimum Viable Product", but none of it sounds high priority.
- The current course omits features that would be needed for any dynamically typed language (including Python) to work. (garbage collectors, polymorphic inline cache, etc)
- The current course also prevents anything running in the WebAssembly space from accessing the DOM. You can call your WebAssembly from javascript, but that's it.
I suspect it will be quite a while before there's more available than "call LLVM created libraries from javascript". Technically, you could, I suppose put the entire cpython codebase into webassembly, but that seems like more of parlor trick than something useful.
How is the mapping from wasm to asm done, at all?
Are they directly mapping from web world to native world in a sandbox ?
Does anyone know if theres a webassembly to js compiler to support legacy browsers?
So either you cross-compile a JavaScript VM to be able to handle everything (super slow and bloated, especially without the ability to JIT compile executable code) or you pick a small subset of TypeScript to compile, in which case it wouldn't really be TypeScript at all.
Plus TypeScript doesn't have integer types (only doubles) so it would generate pretty inefficient code. JavaScript JITs do a lot of work to turn usage of doubles into integers based on run-time behavior that is unknowable at compile-time.
Also keep in mind that webasm doesn't include a garbage collector. If typescript relies on one, it will need to be compiled to webasm as well.
Web Assembly should make code more portable and faster on the web. No more transpiling to JavaScript (which honestly is a hack; going from one language to another language which is then compiled). If you want to use CoffeeScript, even though I dislike it, you'll be able to compile directly to WebAssembly instead.
I can't wait until this is fully baked with DOM access, etc.
It's still practical, today, should you want to use something other than JS but I don't think it's that sensible. You take one language's syntax and idiosyncrasies, convert it to another language with its own, sometimes differing, idiosyncrasies and now you have to debug it, sometimes in a different language than it was written it.
I don't mind TypeScript or any of the others but I think WebAssembly is what makes those language great; transpiling to JavaScript is a hack.
Just imagine ECMAScript 7 then ECMAScript 8 support coming in very quickly after announcement because your JavaScript now compiles to WebAssembly. You won't have to wait or deal with browsers that are lacking the necessary APIs; it'll "just work" because it's all compiled to WebAssembly.
At the point at which WebAssembly gets a JIT and GC, then the situation changes.
And it's really intended as a compilation target; I don't think anyone wants or expects average web developers to code in wasm.
Might help them improve Google Docs a lot if they could utilize some mature C++ libraries from a desktop word processor.
Is anyone working on a Go to WebAssembly compiler yet?
I don't think that'll work until WebAssembly has GC, which isn't likely to be ready for a while.
This leaves two options:
1. Go developers could write a GC especially designed to enable Go on WebAssembly.
2. Go developers could wait until WebAssembly gets its own GC implementation, and make use of that.
Considering option 2 is less work, and that a GC for WebAssembly is on the WebAssembly roadmap (check the GitHib page for details), I'd suggest option 2 is what will end up happening.
https://github.com/llvm-mirror/llvm/tree/master/lib/Target/W...
(linked to the Github mirror because the LLVM viewvc is currently down)
I'm guessing you're a JS diehard that doesn't want to see other languages hit the web? I'm not aware of any other reasons why you'd fight this otherwise.