Reference articles on history, science, culture and more
Encyclopedia

Asm.js

Intermediate programming language

asm.js is a subset of JavaScript designed to allow computer software written in languages such as C to be run as web applications while maintaining performance characteristics considerably better than standard JavaScript, which is the typical language used for such applications.

asm.js consists of a strict subset of JavaScript, into which code written in statically typed languages with manual memory management (such as C) is translated by a source-to-source compiler such as Emscripten (based on LLVM). Performance is improved by limiting language features to those amenable to ahead-of-time optimization and other performance improvements.

The project was started at Mozilla, and Firefox 22 released in 2013, was the first web browser to ship asm.js-specific optimizations.

Compiler and browser makers' experience with asm.js influenced the development of WebAssembly, which has largely supplanted asm.js since its release. Firefox 148, shipped in 2026, disabled asm.js optimizations and asm.js, with old code transparently continuing to run using the main JavaScript engine.

01Design

asm.js enables significant performance improvements for web applications, but does not aim to improve the performance of hand-written JavaScript code, nor does it enable anything other than enhanced performance.

It is intended to have performance characteristics closer to that of native code than standard JavaScript by limiting language features to those amenable to ahead-of-time optimization and other performance improvements. By using a subset of JavaScript, asm.js is largely supported by all major web browsers, unlike alternative approaches such as Google Native Client.

02Code generation

asm.js is not typically written directly: instead, as an intermediate language, it is generated through the use of a compiler that takes source code in a language such as C++ and outputs asm.js.

For example, given the following C code:

int f(int i) { return i + 1; }

Emscripten would output the following JS code:

function f(i) { i = i | 0; return (i + 1) | 0; }

Note the addition of | 0 and the lack of type specifiers. In JavaScript, bitwise operators convert their operands to 32-bit signed integers and give integer results. This means that a bitwise OR with zero converts a value to an integer (a very simple "conceptual" presentation of bitwise operators may not deal with type conversion at all, but every programming language defines operators for its own convenience, as Javascript does here). By doing this for each parameter, this ensures that if the function is called from outside code, the value will be converted to the correct type. This is also used on the return value, in this case to ensure that the result of adding 1 to i will be an integer (as otherwise it could become too large), and to mark the return type of the function. These conversions are required by asm.js, so that an optimising compiler can produce highly efficient native code ahead-of-time. In such an optimising compiler, no conversions are performed when asm.js code calls other asm.js code, as the required type specifiers mean it is guaranteed that values will already have the correct type. Furthermore, rather than performing a floating-point addition and converting to an integer, it can simply do a native integer operation. Together, this leads to significant performance benefits.

Here is another example to calculate the length of a string:

size_t strlen(char* s) { char* current = s; while (*current != 0) { ++current; } return (current - s); }

This would result in the following asm.js code:

function strlen(s) { s = s | 0; var current = 0; current = s; while ((MEM8[current >> 0] | 0) != 0) { current = (current + 1) | 0; } return (current - s) | 0; }

In the generated code, the variable MEM8 is actually a byte-by-byte "view" of a typed buffer, which serves as the "heap" of the asm.js code.

03Performance

Since asm.js runs in a browser, the performance heavily depends on both the browser and hardware. Preliminary benchmarks of C programs compiled to asm.js are usually within a factor of 2 slower than native compilation with Clang.

Much of this performance gain over normal JavaScript is due to 100% type consistency and virtually no garbage collection (memory is manually managed in a large typed array). This simpler model with no dynamic behavior, no memory allocation or deallocation, just a narrow set of well-defined integer and floating point operations enables much greater performance and potential for optimization.

Mozilla's benchmark from December 2013 showed significant improvements: "Firefox with float32 optimizations can run all those benchmarks at around 1.5× slower than native, or better." Mozilla points out that the performance of natively compiled code is not a single measure but rather a range, with different native compilers (in this case Clang and GCC) delivering code of differing performance. "In fact, on some benchmarks, like Box2D, FASTA and copy, asm.js is as close or closer to Clang than Clang is to GCC. In one case, asm.js even beats Clang by a slight amount on Box2D."

04Implementations

The Emscripten project provides tools that can be used to compile C and C++ codebases (or any other languages that can be converted to LLVM IR) into asm.js (now WebAssembly).

All browsers with support for ECMAScript 6 should be able to run asm.js code, as it is a subset of that specification. However, since features were added in that edition to enable full asm.js support (Math.fround()), older browsers lacking those features may encounter problems.

Some browser implementations are especially optimised for asm.js:

  • Mozilla Firefox was the first web browser to implement asm.js-specific optimizations, starting with Firefox 22. OdinMonkey, Mozilla's asm.js ahead-of-time compiler used in Firefox, is a component of IonMonkey, the JIT compiler of SpiderMonkey.
  • Microsoft was implementing support for asm.js in Chakra, the JavaScript engine used by Microsoft Edge Legacy, performing validation to produce highly optimised JIT code.
  • The optimizations of Google Chrome's V8 JavaScript engine in Chrome 28 made asm.js benchmarks more than twice as fast as prior versions of Chrome, although Chrome's V8 does not use ahead-of-time compilation.

05Adoption

Most applications using asm.js were C or C++ applications compiled using tools such as Emscripten or Mandreel. asm.js was primarily used for applications whose existing native codebases could be translated automatically for execution in web browsers.

So far, a number of programming languages, application frameworks, programs, libraries, games, game engines and other software have already been ported. Some of them are given below.

Programming languages

Application frameworks

  • pepper.js: Ports of miscellaneous PNaCl apps (earth, voronoi, bullet, etc.)
  • Qt: ports of various Qt demos, plus KDE apps, such as Kate

Programs and libraries

Game engines

Games

Emulators

  • EM-DOSBox: an Emscripten port of DOSBox
  • Start9.io: a web emulation platform targeting multiple gaming architectures
  • JSMESS: a port of the MESS emulator for many game consoles and computer systems

Mathematics

06Deprecation

asm.js is mostly rendered obsolete with the introduction of WebAssembly (wasm), which has a bytecode format that is faster to parse. Efforts to extend JavaScript with more low-level features like SIMD.js has also been suspended since 2017.

asm.js remains useful primarily as a "fallback" for wasm, through a program written by the WebAssembly organization that converts wasm to asm.js. There is no dedicated converter from asm.js to wasm, but TypeScript-to-wasm compilers can be partially used. The reference WebAssembly emitter, Binaryen , used to contain an asm2wasm module, but it was removed after Emscripten stopped using it.

On May 20, 2026, Mozilla announced deprecation of asm.js: the feature is disabled by default since Firefox 148 released in February 2026 and Firefox developers "plan to remove the code entirely in a future release."

Watch videos about Asm.jsExplainers and documentaries on YouTube (opens in a new tab)

Sources and credits

This article is adapted from the Wikipedia article Asm.js, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.

Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.