Re:Experimental support for WebAssembly in V8
by xigency on Tuesday March 15, 2016 @05:20PM
(#11293106)
What about this JavaScript: https://raw.githubusercontent.com/gregtour/gameboy/master/JS...
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.
Re:Experimental support for WebAssembly in V8
by bcheung on Tuesday March 15, 2016 @03:01PM
(#11292134)
WebAssembly is a binary representation of the Javascript AST. Optimizations usually happen AFTER it is parsed. That's all WebAssembly is -- the parsed result. Targeting WebAssembly from Javascript is the most natural fit that could possibly exist.
Re:Experimental support for WebAssembly in V8
by azakai on Tuesday March 15, 2016 @03:02PM
(#11292148)
Not quite. WebAssembly is not a representation of general JS. It can just represent a small subset of it, very similar to the asm.js subset.
Re:Experimental support for WebAssembly in V8
by bcheung on Tuesday March 15, 2016 @04:44PM
(#11292832)
Good to know. So it doesn't implement any of the ES6 concepts then I take it.
Re:Experimental support for WebAssembly in V8
by esailija on Tuesday March 15, 2016 @03:45PM
(#11292428)
The format is just an AST in general, nothing to do with JavaScript. You can even see all the possible instructions here to confirm [1].
1. https://github.com/WebAssembly/design/blob/master/AstSemanti...
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.).