Cheerp creator: Our C++-to-JavaScript compiler beats Emscripten

Cheerp 1.2 offers speedier compilation with no memory size limitations

Cheerp creator: Our C++ to JavaScript compiler beats Emscripten
Thinkstock

Cheerp, a C++ compiler that generates JavaScript code for use in any browser, is being upgraded this week with improved performance, reduced output code size, and  backing for 64-bit integers.

Open source Cheerp, from Leaning Technologies, is based on LLVM, which features a set of modular, reusable compiler technologies. Version 1.2, introduced this week, "comes with some big performance improvements, both in execution time and in startup time," according to a blog post by Leaning Technologies CEO Stefano De Rossi.

Cheerp reached a slowdown of  "only 2 to 6 times compared to native," while still allowing full dynamic memory management and no memory size limitations, the blog states. "Compared with Emscripten in split memory mode, Cheerp is always as fast but most often 2-3 times faster, has a 10-11 times faster startup, requires no effort from the developer to fine-tune compilation parameters, and allows for real dynamic memory management." The rival Emscripten compiler, which also leverages LLVM, converts C/C++ code into the Asm.js JavaScript subset.

In addition to native 64-bit integer capabilities, Cheerp 1.2 supports a PreExecuter capability, currently in an experimental state. "The PreExecuter is a technique that converts C++ code used to initialize global structures into simple data," De Rossi said. "Its main effect is a further reduction of the output JavaScript startup time and a much reduced output code size."

In an email, De Rossi championed the use of C++ for Web development:

C++ is the world's most widespread language for medium and large-scale applications, and has been a de facto industry standard for decades. C++ has been and still is used on virtually any available device and platform, and it is very natural to allow developers to use it also for Web applications. Using a C++ to JavaScript compiler allows developers to reuse existing C++ code such as complex, high-performing legacy libraries, to share code between the client and the server when needed, and to make multi-platform applications which can also run on browsers.

Also new in version 1.2 are Runtime Type Information support, dynamic_cast, and covariant return types. "Cheerp now also experimentally supports the module pattern to isolate generated code from other scripts," De Rossi said.

Copyright © 2016 IDG Communications, Inc.