ASM.js – What It Means for Developers and Users

compilerjavascript

I'm starting to hear rumblings about this project called ASM.js. Currently their web site is terrible and confusing. Here's what I know from my research on the web.

  • It is a subset of JavaScript that can be highly optimized. I'm guessing because it avoids the more dynamic parts of the language.
  • Performance of code compiled to ASM.js runs at about half the speed of C (not light).
  • The intention is for compilers to make their target language ASM.js.
  • Firefox is going to be shipping with ASM.js optimization baked in.
  • The Mozilla and Unreal teams ported the Unreal Engine to the web with it and its running in a build of Firefox at near-native speeds.

There doesn't seem to be any concrete information on the web about what this really is or the usefulness or ultimate purpose. Is it that I can compile my otherwise server-side code bases and have it run in the browser at close-to-native speeds? What are the ramifications for developers?

Best Answer

You already described what it is. The use is that it's a low-level language that works across all browsers, is quite fast in most and very fast in some. What you make of this is as open-ended as what you do with any other programming language.

The use case Mozilla seems most keen on is this: There are already ways of compiling languages with LLVM backends (most prominently C and C++) to JavaScript, via Emscripten. asm.js is very close to what Emscripten already emits, so this allows Emscripten code (which is already impressively fast on today's JavaScript JIT compilers) to become even faster, furthering the goal of porting existing code bases to the web. Again, what exactly you use this for is your decision. Porting games is one use cases (which Mozilla is apparently actively involved in), but there are countless things written in C and C++, quite a few of which might come in handy for someone's web site. Some I've seen flung around (plus some of my own devising), with no guarantee regarding feasibility:

  • Porting general-purpose algorithms (e.g. zlib, libjpeg, openssl, FFT implementations) to empower JavaScript/websites to do more, without having to create a new web standard and depending on individual browsers to implement it.
  • Porting interpreters, so that languages other than JavaScript can run in the browser, with less overhead and minimal porting effort.
  • Using asm.js as a backend for more compilers, especially those that don't map well to JavaScript and don't need most of its features and overhead. An example could be a language designed for fast numeric work with no memory allocation.
  • Using asm.js to create a JIT in JavaScript. It may implement any language at all -- for example ActionScript.
  • In the same vein, porting existing JIT compilers to run in the browser (cf. porting interpreters, with effectively nil overhead over JS). This is probably only feasible when JIT compilers are automatically generated, as with PyPy.
Related Topic