6 ms·
If webassembly is essentially asm.js directly converted to a more compact bytecode format but with the same semantics - and emscripten already provides llvm wit
by andybak 11y ago
If webassembly is essentially asm.js directly converted to a more compact bytecode format but with the same semantics - and emscripten already provides llvm with a backend that outputs asm.js, then what's significant about this?
I had assumed from the original webassembly announcement that this would be a fairly trivial step but I expect I've misunderstood something.
- serve_yay 11y agoFrom what I have heard, with asm.js, the parser becomes the hotspot. And WebAssembly is a compressed representation of the AST. (Please note that everything I've written could be completely incorrect)
- StefanKarpinski 11y agoMy understanding is that it will only initially mirror asm.js but will eventually become a full-blown, independent bytecode IR that departs from JavaScript semantics (while continuing to support expressing them), allowing other languages to be compiled down to WebAssembly and run in the browser efficiently. Having a bytecode format also eases the considerable burden of parsing JavaScript – which is especially problematic on constrained devices like mobile phones.
- jashkenas 11y agoGot some Julia plans or hopes?
- StefanKarpinski 11y agoSure – with a first-class LLVM backend for WebAssembly, we could absolutely compile to it, which would mean running fully in the browser, which is something Emscripten can't quite manage at this point. That would certainly be very cool (and useful too). See https://github.com/JuliaLang/julia/issues/9430 https://github.com/JuliaLang/julia/issues/9430.
- cordite 11y agoThere's already ASICs for Lua and other to-simplistic-bytecode out there for low power applications (If I recall correctly anyway with tessel.) What's to say when these things are settled, we are left with something that handles asynchrony well and it becomes the basis for IoT?
- bcheung 11y agoIt's just a binary encoding of the AST. Nothing more, nothing less. It's not quite a bytecode, those are typically for interpreters. Binary encoding would be more accurate. The semantics will be identical to JavaScript but the syntax obviously can be completely different depending on the language.
- TazeTSchnitzel 11y agoIt's a binary encoding of a WebAssembly AST. It's not JavaScript, though it lives in the same universe.
- bcheung 11y agoThat's exactly what I said. Why did I get downvoted?
- TazeTSchnitzel 11y agoBecause your comment is misleading or inaccurate. The comment you had replied to was completely correct. > It's just a binary encoding of the AST. Nothing more, nothing less. No, it is not a binary encoding of the JavaScript/asm.js AST. It is a binary encoding of the WebAssembly AST. > It's not quite a bytecode, those are typically for interpreters. It is a bytecode, by any normal meaning of the term. WebAssembly could be interpreted, or could be AOT compiled.
- bcheung 11y agoYou're right, I could have been clearer about saying it is a new AST and not a JavaScript/asm.js AST. That is what I meant. Bytecodes are for instruction sets, not trees though. From wikipedia, "Bytecode, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter." There are no instructions to interpret since there is no instruction set defined. It is possible though that certain browsers may take the AST and create an instruction set for an interpreter or they may compile it to native code but that is entirely browser specific and has nothing to do with WebAssembly. https://github.com/WebAssembly/design/blob/master/TextFormat.md https://github.com/WebAssembly/design/blob/master/TextFormat... "Given that the code representation is actually an Abstract Syntax Tree, the syntax would contain nested statements and expressions (instead of the linear list of instructions most assembly languages have)."
- sklogic 11y agoemscripten (fastcomp) is not a proper LLVM backend (i.e., not a tablegen-based one).
- juliangoldsmith 11y agoBased on a post from Brendan Eich [0], it looks like WebAssembly was created to get around JS parsing times on mobile devices, and also to get around some quirks of JS. [0] https://brendaneich.com/2015/06/from-asm-js-to-webassembly/ https://brendaneich.com/2015/06/from-asm-js-to-webassembly/
- vcarl 11y agoIt would allow languages that use JS as a compile target to skip that intermediate step and output bytecode for the VM, but as I understand it would also allow Javascript to skip that step. Right now every client needs to JIT compile and optimize all code, but if a compiled blob could be sent down instead of minified code, it would be a pretty dramatic shift.
- sunfish 11y agoMultiple things are happening in parallel here. On Emscripten's side, we're going to add a feature which translates Emscripten's asm.js output into WebAssembly, so that existing Emscripten users can easily use WebAssembly. This will indeed be a fairly simple step. [0] The new WebAssembly backend is being developed in upstream LLVM from the beginning, and will be targetting WebAssembly directly rather than going through asm.js, so it will eventually have several advantages. And when it's ready, Emscripten itself will make use of it (though that won't be the only way it can be used) [1]. [0] https://github.com/WebAssembly/design/blob/master/FAQ.md#whats-the-story-for-emscripten-users https://github.com/WebAssembly/design/blob/master/FAQ.md#wha... [1] https://github.com/WebAssembly/design/blob/master/FAQ.md#what-compilers-can-i-use-to-build-webassembly-programs https://github.com/WebAssembly/design/blob/master/FAQ.md#wha...
- echeese 11y agoAre there any examples of the text format of wasm?
- TazeTSchnitzel 11y agoIt doesn't yet exist. The specifications haven't been written, these are high-level design documents.
- kayamon 11y agoBased on the spec so far, there's a very good chance it'll look _almost exactly like asm.js_
- TazeTSchnitzel 11y agoYes. Like asm.js it will more closely resemble C than assembly language, having expressions and variables.
- cpeterso 11y agoWill there be any advantage to generating asm.js over WebAssembly+polyfill for clients that don't support WebAssembly natively?
- bobajeff 11y agoEmscripten doesn't provide LLVM with a backend it uses a fork of LLVM called Fastcomp and that has a asm.js backend. Also the current backend isn't integrated with LLVM the way normal ISA backends are. This I believe (can't access page either) will be upstream and integrated with LLVM proper. Providing performance advantages as well as allowing frontends that aren't supported in Fastcomp but are based off upstream LLVM to support WebAssembly.
- azakai 11y agoAll of those advantages are true, except for performance. We actually don't know which approach will be faster to compile, nor which approach will emit faster code. There are reasons to guess either way. The new backend being begun here is something of an experiment, as LLVM shared backend infrastructure was just not designed for this kind of thing (emitting a high-level AST IR without physical registers, etc.). There are still significant open questions regarding which parts to use there. It will be interesting to see how this develops. Regardless, a new backend makes sense for the other advantages you mentioned, especially that wasm will grow and add features, and a new wasm backend is the best place for that.
- vmorgulis 11y agoWill you continue with C++ (especially for tools outside LLVM)? Do you plan to use something else (like Rust)?
- 11y ago
- bcheung 11y agoWebAssembly itself doesn't have anything to do with asm.js near as I can tell. It's more the ecosystem surrounding WebAssembly. I looked through the specs a little bit. What it is, is a binary encoding of the AST with some optimizations thrown in to decrease size (symbol tables instead of using the full tokens). I'm unclear on why asm.js is even mentioned but I suspect it is a temporary stop gap since those languages using LLVM currently target asm.js. Now, they can just target the AST but it will take some time for the tools to change. In the meanwhile they will look like: C -> AST -> asm.js -> AST -> binary. In the future, it can just look like C -> AST -> AST -> binary. Why is it significant? 1) Language designers can just target the AST, then pass that to WebAssembly to compile to a binary. There's no need to compile to JavaScript. It saves them a step. 2) Size. They are claiming 20-30% smaller than minimized gzip versions of Javascript. There are optimizations that can be done (at the AST level) that exceed what is possible with generic compression like gzip. 3) Load time. Since it can be decoded straight to the AST, it saves the Javascript parsing step. This results in faster page loads. 4) Non-Javascript tooling support will improve. Javascript will still be the canonical language but other languages will increasingly get first class tooling support.