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


Google Releases Gemini 2 And Jules Code Agent
18/12/2024

Google has announced an updated version of Gemini, saying that Gemini 2.0 Flash Experimental will "enable even more immersive and interactive applications", along with new coding agents that can take  [ ... ]



Personal Picks For Holiday Gifts
29/11/2024

It's Black Friday, the traditional day to indulge in online shopping. Not every item that is included in my selection of gifts is subject to a promotional offer, but where they aren't you might be poi [ ... ]


More News

 

espbook

 

Comments




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

Last Updated ( Friday, 26 June 2015 )