Cheerp C++ To JavaScript
Written by Ian Elliot   
Friday, 26 June 2015

You may know of emscripten as being the goto C++ to JavaScript compiler, but there are others. Cheerp, for example, does the job in a slightly different way and its latest version 1.1 is faster.

Version 1 of Cheerp was released about a year ago. It is an open source C++ to JavaScript compiler that has optional commercial support. 

 

 

The key feature of the new version of Cheerp is that it is now faster. It compiles to JavaScript rather than asm.js like emscripten and it makes use of a different memory model. Instead of using a large typed array as working memory, Cheerp compiles C++ objects to JavaScript objects.

The only downside of this more sophisticated approach is that the C++ source is subject to stricter-than-usual typing. It is claimed that in practice most C++ code is already well-typed and the extra work needed is minimal.

The key feature of using JavaScript objects for all data is that memory usage is not limited by a fixed size array. Another almost incidental advantage is that Cheerp code isn't vulnerable to buffer overruns as the memory layout isn't globally linear and JavaScript's memory protection is always applied. 

As the code is just standard JavaScript it loads faster than asm.js, which has to be validated before it can start. Benchmarks reveal a typical reduction from 50  ms to about 10 ms for asm.js emscripten compared to Cheerp. 

Once the code is loaded, Cheerp 1.1 is also faster; compared to version1 the latest Cheerp manages to run four to six times faster. This isn't enough to make it faster than emscripten, but the two are now comparable on small benchmarks and which one is out in front depends on the task and the JavaScript engine in use. In tests Cheerp always managed to run no worse than 10x native performance and for many tasks this is enough. 

For larger, more complex, programs Cheerp is still slower than emscripten by at worse a factor of 3 to 5, but the team is sure that it knows how to catch up in the next version as there are optimizations still to be made. You also need to remember that all of this is done without making use of the speedup that asm.js might provide. In future versions is it is planned to allow asm.js compilation to be selected on an object-by-object basis. 

Overall, Cheerp is an interesting alternative to emscripten that provides faster startup, better scalability because of the way memory is allocated, and better security with a relatively small performance hit in some cases.

cheerpsq

Banner


PostScript Source Code Released
04/01/2023

The source code for PostScript has been publicly released for the first time ever by the Computer History Museum with permission from both Adobe and John Warnock, the inventor of PostScript.



Online Tracking And How To Avoid It
30/12/2022

Whether you are aware of it or not, most websites routinely gather information about you. How is this done? Should you care that your data harvested in this way and if you object what can you do about [ ... ]


More News

 

picobook

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Friday, 26 June 2015 )