asm.js - frequently asked questions
Q. Is asm.js a new language?
Q. What kind of performance benefits can I expect to get with asm.js?
It's early to say, but our preliminary benchmarks of C programs compiled to asm.js are usually within a factor of 2 slowdown over native compilation with clang
. We will publish more benchmarks as we collect them.
Q. How can I track implementation progress?
Mozilla is working on a first implementation
of an optimizing asm.js compiler for SpiderMonkey. Mozilla also has a development roadmap
For compilers like Emscripten
, the syntax of a bytecode language simply isn't that important. In fact, most bytecode and machine languages have non-human-readable binary formats. However, we may create a more human-readable surface syntax for asm.js, which could be used for convenient disassembly and human read/write-ability.
A. No need to stop! But JIT compilers have less predictable performance based on complicated heuristics. The asm.js model provides a model closer to C/C++ by eliminating dynamic type guards, boxed values, and garbage collection.
Because of the directive prologue
Q. How can developers get good feedback if their code fails to validate?
The directive prologue
identifies the developer's intention that code should be considered valid asm.js. If the code fails to validate, the engine can report the validation error to e.g. a developer console or other developer tools.
Q. How can developers debug asm.js code?
This is a problem in general with compiling for the web. Source maps
can help, but browsers do have more work to do to make debugging compiled code a smoother experience.
Q. Can asm.js serve as a VM for managed languages, like the JVM or CLR?
Right now, asm.js has no direct access to garbage-collected data; an asm.js program can only interact indirectly with external data via numeric handles. In future versions we intend to introduce garbage collection and structured data based on the ES6 structured binary data API
, which will make asm.js an even better target for managed languages.
Q. Is asm.js compatible with `eval` and `Function`? Can you dynamically invoke the asm.js compiler?
Absolutely! Compilation of an asm.js module
happens at parse time of the source code. If you trigger that parse time with `eval` or `Function` then you get dynamic compilation.
Q. How much of a compile-time hit does asm.js incur?
Validation and compilation are pretty fast but they do incur a compile-time cost, but only for asm.js code
—code that does not contain the asm.js directive prologue
does not need any additional processing. If you want to avoid the up-front cost of validating and compiling asm.js code, you can use `eval` or `Function` to delay compilation to a later point.
Q. Can asm.js help with application startup times?
A. We intend to propose additional web API's to make it possible to compile asm.js in background threads and to store the results of compilation in offline storage, making it possible to start up faster in future application loads.