New compiler cranks up JavaScript from native code

Emscripten C/C++-to-JavaScript project uses a back end derived from LLVM for greater speed and a more dedicated compiler

At first, Emscripten sounds like the punch line to a tech joke: a compiler that converts C/C++ code into Asm.js, a subset of JavaScript that can then run via a Web browser or in the Node.js framework.

But it's no joke. Emscripten and Asm.js (the latter started as a Mozilla research project) have been making major strides since their introduction. The latest step up is an Emscripten revision that replaces the original compiler core with one derived from LLVM, a compiler technology framework used mainly for C/C++ but in theory capable of supporting many other languages.

According to Emscripten's developers, switching to LLVM gives Emscripten several advantages. For one, compilation is much quicker -- "often four times faster or more," they claim -- and requires far less memory. It also "avoids unpredictable pathological compiler slowdowns that the old compiler had." Most significant, the LLVM back end allows much tighter integration between Emscripten and LLVM.

The only downside of using LLVM is that it has to be recompiled specifically to work with Emscripten. A stock build of LLVM only gives you a subset of the available benefits, which you can get away with using if you have no other choice.

Asm.js is still considered an experimental technology, with direct browser support available only through Mozilla Firefox, but it's delivered impressive results. Most recently, it ported the Unreal game engine to JavaScript, allowing games built on that platform to run in-browser with no plug-ins and no non-native code.

Google has not yet elected to support Asm.js fully, although JavaScript applications that use it will run in Chrome, albeit not with the same speed boost that they'd obtain through Firefox. Google's plan seems to be to focus on Dart as the way to deliver near-native code execution speeds through a browser, but JavaScript's ubiquity and flexibility give it native advantages that have so far continued to prove hard to beat.

This story, "New compiler cranks up JavaScript from native code," was originally published at InfoWorld.com. Get the first word on what the important tech news really means with the InfoWorld Tech Watch blog. For the latest developments in business technology news, follow InfoWorld.com on Twitter.

Recommended
Join the discussion
Be the first to comment on this article. Our Commenting Policies