The idea of using JavaScript as a modern day assembly language for browser code is being taken very seriously by Mozilla. Asm.js is a specification for a high performance JavaScript assembly language and OdinMonkey is an engine that runs it really fast.
A compiler doesn't have to target a low level machine code. For example, the Java compiler creates byte code which is then run using a virtual machine. JavaScript is so ubiquitous that it makes sense to use it as a target for compilers of other languages so that web apps can be written using them. The best known example is probably CoffeeScript which compiles to standard JavaScript. However, CoffeeScript is already quite close to JavaScript and the compilation is a fairly easy task.
More difficult is to compile C++ to JavaScript, which is what compilers like Emscripten or Mandreel do. At the moment these compilers attempt to render C++ into JavaScript so that the result runs reasonably fast. A much better idea is to define a subset of JavaScript, which is complete in the sense that you can do anything you need to using it, but one that can be implemented efficiently.
This is what asm.js is all about. It is a detailed specification for a subset of JavaScript. Notice that while this means that this isn't a new language there are new features which would be ignored by a standard JavaScript engine. For example, the language only has strictly-typed integers, floats, arithmetic, function calls, and heap accesses. This is achieved using annotations in the form of comments and a restricted set of operations which only work with the data type - for example logical operators convert numeric values to int32.
The fact that asm.js is a subset of JavaScript means that you can take an asm.js program and run it in a standard unmodified browser or JavaScript engine. However, to get any real value from using it you need it to be run using an optimizing JavaScript engine. This is the second half of the project. Mozilla is working on OdinMonkey, a JavaScript engine that recognizes when it has been fed an asm.js program and can apply automatic optimizations.
The target for for OdinMonkey is to run compiled C++ code from Emscripten at no worse than half the speed. Current benchmarks seems to prove that it is possible. You can also try it out by compiling using emscripten with the ASM_JS=1 switch and then run it using a special Firefox build.
Click for larger version
So, putting the ideas together: build compilers from C++ and other languages to asm.js and use optimized JavaScript engines to run the code at near native speeds. If the browser doesn't have an optimized engine then the code still runs because its just JavaScript.
It remains to be seen if other JavaScript engines take up asm.js. The alternative is of course Google's NaCL and PNaCL, but again only one browser manufacturer is supporting it. We will have to wait while they fight it out.
More Information
Related Articles
Pit - F# to JavaScript Compiler
JavaScript to be the Default Language for Gnome
Chrome Native Client Goes ARM and Portable
Chrome native apps split the browser world
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
Comments
or email your comment to: comments@i-programmer.info
Google AI Studio Does Angular
27/10/2025
Google's AI Studio can now generate Angular applications. Add the Web Codegen Scorer tool on top and you get a pretty solid Angular development platform.
Robotic Gut Spider For Exploring Digestive Tract
14/11/2025
Researchers from China have demonstrated soft, magnetically controlled robot "spiders" the size of a vitamin capsule that can move through the digestive tract to avoid the need for invasive endoscopie [ ... ]
- GitHub Announces Agent HQ Organizer
- .NET 10, C# 14 and F# 10 Released Alongside Visual Studio 2026
- Missing The Point Of LLMs
- Google Tunix Hack Hackathon Now Open
- XAML.io 0.5 Adds Multi-File Project Editing
- Vibe Coding Is Collins Word of the Year 2025
- .NET 10 Final Release Candidate Focuses On MAUI
- Edera Open Sources Sprout
- W3C Adopts A New Logo
- Eclipse Foundation Adds Agentic Functionality To Eclipse LMOS
- OpenCode - The Claude Code Alternative
- Next.js 16 Adds Cache Components
- PyTorch Team Introduces Cluster Programming