News for hackers. Stuff that matters.
Re:Is WebAssembly faster than JavaScript? by flohofwoe on Wednesday October 24, 2018 @03:50AM (#18290441)
I'm getting the opposite results from my work with WebAssembly (https://floooh.github.com/tiny8bit, https://floooh.github.io/sokol-html5/, https://floooh.github.io/oryol/).

As for the size vs JS: this depends a lot on the language used to compile to WASM, rule-of-thumb: the higher level the language, the more complicated it is to keep the size down. But if you use an 'embedded style' of C, it is quite trivial to keep the size below even compressed Javascript code that does the same, as long as the Javascript code isn't just glueing together a few HTML5 APIs and the DOM.

Some of my findings:

- https://floooh.github.io/2018/05/01/cpp-to-c-size-reduction....

- https://floooh.github.io/2016/08/27/asmjs-diet.html

As for performance: you need to show the code and benchmark results since JS being faster than WASM is against what most people who actually worked with both are seeing. It's definitely possible that badly written C code compiled to WASM is slower than well written JS code, but that takes a lot of effort ;)

WASM allows control over the memory layout that's just not possible with "idiomatic" JS, unless throwing most of Javascript's convenience away and directly poke into ArrayBuffers.

One reason why JS could be faster than WASM is (or rather was) when the WASM code needs to do a lot of calls into JS, but this has recently been addressed in Firefox (and other browsers hopefully follow soon).

Some more info on why WASM is faster then "idiomatic JS":

https://floooh.github.io/2017/06/09/webassembly-demystified....

Re:Is WebAssembly faster than JavaScript? by vanderZwan on Thursday October 25, 2018 @07:20AM (#18300034)
Wow, nice demos! You got yourself a new Github follower.

Out of curiosity, because you seem to focus on 3D graphics or really old-school emulation: have you given any thought in how WASM might be beneficial for rendering 2D graphics? What would you expect to be the best approach to squeeze more performance out of that use-case?

Re:Is WebAssembly faster than JavaScript? by flohofwoe on Thursday October 25, 2018 @03:03PM (#18303599)
I think 2D graphics is also mainly a WebGL problem. Fill a vertex buffer with 2D vertices each frame, and try to render it with as few draw calls as possible (e.g. fill vertices sorted by texture, and only issue a new draw call when the texture changes, pack small textures into a bigger texture atlas etc...). Most what makes this fast is how WebGL is used and can be done quite efficiently from JS too. WASM may help in the tight loop where the vertex buffer is filled with data though.