Alon Zakai
mozakai.blogspot.com · Personal blog · on HN since 2010
Alon Zakai, creator of Emscripten, writes about compiling C and C++ to JavaScript, asm.js and WebAssembly.
What HN saysCommenters cite his posts on code size, asm.js and why a universal web bytecode is hard, treating them as authoritative background on WebAssembly's origins.
36HN people shared it
21linked it in comments
23stories submitted
471story points
1 year agolast shared
2010people per year2026
Most-shared posts
- 1Code size when compiling to javascript5 people · first shared 2013
- 2The elusive universal Web bytecode4 people · 67 points · first shared 2013 · 60 comments on HN
- 3Experiments with 'Static' JavaScript: As Fast As Native Code?3 people · 55 points · first shared 2010 · 10 comments on HN
- 4Reloop All The Blocks [in Emscripten]3 people · 2 points · first shared 2012 · discussion on HN
- 5What asm.js is and isn't2 people · 167 points · first shared 2013 · 49 comments on HN
- 6Running Lua in a browser via Emscripten2 people · 91 points · first shared 2013 · 41 comments on HN
- 7Emscripten - An LLVM-to-Javascript compiler2 people · 22 points · first shared 2010 · 9 comments on HN
- 8C++ to JavaScript: Emscripten, Mandreel, and now Duetto2 people · 2 points · first shared 2013 · discussion on HN
- 9Debugging JavaScript is Awesome2 people · 1 points · first shared 2012 · discussion on HN
- 10The Elusive Universal Web Bytecode1 people · 32 points · first shared 2015 · 34 comments on HN
- 11C++ to JavaScript: Emscripten, Mandreel, and now Duetto1 people · 12 points · first shared 2013 · discussion on HN
- 12HOWTO: Port a C/C++ Library to JavaScript (xml.js)1 people · 3 points · first shared 2012 · discussion on HN
- 13Outlining: a workaround for JITs and big functions1 people · 3 points · first shared 2013 · discussion on HN
- 14Emscripten OpenGL / WebGL Conversion Progress1 people · 2 points · first shared 2012 · discussion on HN
- 15Lua in Javascript1 people · 2 points · first shared 2013 · discussion on HN
What HN people wrote when they linked it
BrendanEich · 2015-03-26
Ecma TC39 is working on all the goodies you mention, and more (yes, even threads with shared ArrayBuffer memory). In a couple of years, you might have some of them in top JS engines.
Starting fresh would take many more than two years, and very likely end in tears. This assumes browser vendors could spare the effort to do JS and the new thing (most cannot, even Google arguably can't).
For why the best VMs are focused on one language, see
https://www.dartlang.org/support/faq.html#q-why-didnt-google-build-a-b…
and
https://www.dartlang.org/articles/why-not-bytecode/
from the Dart team. See also
http://mozakai.blogspot.fr/2013/05/the-elusive-universal-web-bytecode.…
from Alon Zakai of Mozilla.
azakai · 2014-01-14
> However, the positives of targeting any language at a stable byte code is incredibly valuable... such as an implementation of javascript itself. A bytecode approach provides a superset to our current status quo.
Not necessarily, it depends which bytecode. For example the bytecode in PNaCl, which is based on LLVM IR, is excellent for C and related languages, but not for many other important languages.
Worth reading this about the limitations of LLVM IR as a bytecode: http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043719.html
I've also written a post about the limitations of any single bytecode to achieve all the goals the web needs: http://mozakai.blogspot.com/2013/05/the-elusive-universal-web-bytecode…
pcwalton · 2013-05-18
> With the trade off that the code size is greatly increased
http://mozakai.blogspot.com/2011/11/code-size-when-compiling-to-javasc…
> If the performance of an application is only acceptable on the subset of browsers that implement asm.js then the portability advantage over PNaCL isn't worth that much.
The Unreal Engine demo has proven that, even for games, these limitations don't result in "dog slow" performance on browsers that don't support asm.js.
int_19h · 2025-09-24
To remind, the original context was transpiling another language (with semantics that allows irreducible CFGs) to Zig, not just this one specific pattern. Yes, of course, for pretty much all practical code, there is going to be a better equivalent. But the transpiler doesn't get the benefit of only working with practical code - it has to deal with whatever the source language spec says is legal. So you need to come up with a generic solution to the entire class of problems presented. Which does exist - e.g. Relooper (https://mozakai.blogspot.com/2012/05/reloop-all-blocks.html) - but the point is that it is very much a non-trivial transformation, to the point where it might actually be easier to transpile to C or something else that has full-fledged goto that you can just use directly.
flohofwoe · 2023-12-22
Text parsing isn't the bottleneck:
https://mozakai.blogspot.com/2013/05/the-elusive-universal-web-bytecod…
(this blog post is pre-WASM, but the main advantage of WASM vs asm.js isn't that WASM is a binary format or even better performance than JS, but that Javascript can focus on being a language again, while WASM can focus on being a compile target)
shakna · 2017-04-11
vmorgulis · 2016-03-11
> ... it is now utterly controlled by a small group of browser developers ...
If the group is small, it's mainly because the job is very difficult. All browsers are a big mess and it takes time to be productive.
The idea of asm.js is one of Alon Zakai. He explains on his blog all the experiments he made before concluding with that.
A quote from the oldest post I know about emscripten:
"I want the speed of native code on the web - because I want to run things like game engines there - but I don't want Java, or NaCl, or some plugin. I want to use standard, platform-agnostic web technologies."
http://mozakai.blogspot.fr/2010/07/experiments-with-static-javascript-…
eveningcoffee · 2015-07-13
> http://mozakai.blogspot.com/p/about.html
researcher at Mozilla
cpeterso · 2015-02-19
asm.js is a cross-platform bytecode; it just happens to be ASCII and look like JS. :) Arguments against asm.js as a bytecode are mostly about aesthetics and "elegance".
http://mozakai.blogspot.com/2013/05/the-elusive-universal-web-bytecode…
dochtman · 2014-08-12
The Emscripten author wrote a blog post when Cheerp (then called duetto) was first announced:
http://mozakai.blogspot.co.uk/2013/11/c-to-javascript-emscripten-mandr…
indolering · 2014-05-07
Well, that would make sense as asm.js is just a formalization of what the optimizing compilers were doing with LLVM transpiled JS code: http://mozakai.blogspot.com/2013/06/what-asmjs-is-and-what-asmjs-isnt.…
acqq · 2014-04-27
If you think about it, bytecode you wish just doesn't exist, whereas JavaScript does and it works:
http://mozakai.blogspot.co.at/2013/05/the-elusive-universal-web-byteco…
bzbarsky · 2014-04-27
> JavaScript and HTML are a lot more bloat than machine language code written to the wire.
http://mozakai.blogspot.com/2011/11/code-size-when-compiling-to-javasc… suggests otherwise in a head-to-head comparison: C code compiled to both a platform-native binary blob and JavaScript, then both gzipped (standard practice for any large JS file on the web).
And if you're talking platform-dependent machine code, that's likely _worse_ on the wire in practice, because unlike a platform-independent representation you can't do edge caching or other sorts of intermediate caches. But maybe you meant a virtual machine (i.e. what people ask for when they want a common bytecode)?
sanxiyn · 2013-11-27
For file size, see http://mozakai.blogspot.com/2011/11/code-size-when-compiling-to-javasc… Summary: it's comparable, not bigger.
cliffbean · 2013-11-12
We've had other languages running in browsers for quite a while now. eg.:
http://mozakai.blogspot.com/2013/05/lua-in-javascript-running-vm-in-vm…
surrealize · 2013-05-18
The only actual numbers I've seen, from emscripten author Alon Zakai, show gzipped minified emscripten JS output as comparable in size to gzipped native code:
http://mozakai.blogspot.com/2011/11/code-size-when-compiling-to-javasc…
politician · 2012-12-10
The Emscripten Relooper algorithm "takes basic blocks of code - chunks of simple code, at the end of which are branches to other blocks of code - and generates high-level structure from that using loops and ifs."
http://mozakai.blogspot.com/2012/05/reloop-all-blocks.html
dbaupp · 2012-08-24
Do you happen to know which of the Empscripten or Mandreel compiled versions is fastest?
(After searching a bit, it seems that the emscripten version is the faster one[1], at least in February, but the testing methodology in that post isn't clear.
[1]: http://mozakai.blogspot.se/2012/02/box2djs-box2d-on-web-is-getting-fas… )
tiles · 2011-01-01
We can. http://mozakai.blogspot.com/2010/08/emscripten-llvm-to-javascript-comp… or its kin will definitely see a place in the future of web development.
x86 is a sucky architecture to target but we target it cause that's what's worked on. Path of least resistance. Same will happen to JavaScript as a bytecode target, inevitably, and when it's abstracted away and browsers speed up even faster, we won't be bothered by the pain points, just use the implementation.
bhiggins · 2010-10-29
on the flip side, here's an experiment for converting JavaScript to Python, and then if it turns out to be valid RPython (a subset of Python where among other things the types of variables don't change), converts it to a native executable.
http://mozakai.blogspot.com/2010/07/experiments-with-static-javascript…
andhow · 2013-02-15
(Luke Wagner from Mozilla here.)
> This seems very much targeted at emscripten and not to cross-compilers that start with GC'ed languages like GWT, Dart, ClojureScript, et al.
That's correct, although one could implement a garbage collector on top of the typedarray heap (we have working examples of this). There are some limitations to GCing the typed array manually, though, such as not taking advantage of the browser's ability to better schedule GCs.
Looking further in the future, though, it would be completely reasonable to extend asm.js to allow the super-optimizable use of the upcoming BinaryData API [1] in the style of JVM/CLR-style objects. Again, though, this is speculative; BinaryData isn't even standardized yet.
> It's also unclear to me how this solves the problem of startup time on mobile.
We have several strategies to improve this. The "use asm" directive, in addition to allowing us to produce useful diagnostic messages to devs when there is an asm.js type error, allows us to confidently attempt eager compilation which can happen on another thread while, e.g., the browser is downloading art assets. Looking farther in the future again, we could make some relatively simple extensions to the set of Transferrable [2] objects that would allow efficient programmer-controlled caching of asm.js code including jit code using the IndexedDB object store.
> In all likelihood, the majority of asm.js outputs would be actually be non-human readable output of optimizing…