Cheerp 2.5 released

14 March 2023 Update: Cheerp 3.0 released and relicensed to Apache 2.0 licence! Release notes here.

Today we announce the release of Cheerp 2.5, the first major release of the Cheerp compiler after the release of 2.0 — the first release to support WebAssembly — one year ago. This follows our release candidate of April 8th, announced here .

Cheerp is an open-source, enterprise-grade C/C++ compiler that can generate WebAssembly , JavaScript, or a combination of the two. It is a commercial alternative to the Emscripten toolchain, focused on providing better interoperability with JavaScript, allowing to generate garbage-collectable JavaScript, smaller WebAssembly build size and better performance.

While also based on the LLVM/Clang stack, Cheerp does not rely on the LLVM WebAssembly backend, as Emscripten does*.*Cheerp is based on a custom extended Clang frontend *and* a custom LLVM backend.

With Cheerp 2.5, we make significant steps forward in terms of performance, making Cheerp the best performing C/C++ compiler for WebAssembly, both for compiled size and execution speed.

In addition, we continue our focus on providing better WebAssembly-JavaScript interoperability. Because Cheerp can compile to a combination of WebAssembly and JavaScript outputs, it can work around many limitations of WebAssembly (such as direct DOM and WebGL/WebAudio access) without sacrificing its native-like speed.

Cheerp 2.5 introduces experimental support for WebAssembly reference type anyref, a step towards supporting typed references when they will be part of WebAssembly. This feature allows for even cleaner interoperability with JavaScript and the DOM.

New in Cheerp 2.5

Note: most of these new features were discussed in our previous release candidate post .

/*  Compile with:
 *  /opt/cheerp/bin/clang++ -target cheerp-wasm -cheerp-wasm-enable=anyref -o anyref.js anyref.cpp 
 */
 
#include <cheerp/clientlib.h>
 
void webMain()
{
    client::Element* e = client::document.createElement("p");
    client::document.get_body()->appendChild(e);
    e->set_textContent("Anyref test");
}

Experimental support for anyref allows to manipulate the DOM in WebAssembly.

Cheerp 2.5 is the first major release of Cheerp since 2.0, the first to introduce support for WebAssembly. Cheerp 2.5 introduces support for WebAssembly reference type anyref, and is mostly focused on quality-of-life improvements, cleaner code generation, and faster build times.

Modernization

Cheerp is based on the LLVM/Clang framework. Since Cheerp 2.0, we have started a long term modernization effort to bring Cheerp fully on par with the upstream LLVM/clang project. The 2.5 release includes a first big step in this effort, as Cheerp has been rebased from LLVM/Clang 3.7 to the 6.0 version.

Further rebase work will continue in the next releases of Cheerp, to finally rebase it on up-to-date LLVM/Clang. We are doing this progressively to make sure no regressions are introduced, for the sake of both the end-users of Cheerp, and our other products CheerpJ and CheerpX , which rely heavily on Cheerp.

Interoperability with the host environment

Cheerp allows classes and functions to be tagged with optional attributes such as [[cheerp::genericjs]][[cheerp::wasm]] and [[cheerp::jsexport]], instructing Cheerp on the desired compilation behaviour for each section of the code. This allows to maintain a single central code base, while targeting both WebAssembly and JavaScript.

In WebAssembly mode, code runs faster but has limited access to browser APIs. This is the default compilation mode followed by Cheerp.

In JavaScript mode conversely, the code may run somewhat slower, but full access to browser APIs is possible, as well as garbage collection. This mode can be turned on selected parts of the code with the [[cheerp::genericjs]]attribute, or on the whole code base with a compile-time flag.

Cheerp 2.0 was the first release to provide this level of interoperability, but it’s the new 2.5 release that truly delivers on this promise. This feature support is now battle-hardened by one year of testing from our users and our other tools based on Cheerp.

With mature support for interoperability, it is now both possible and easy to write large scale real-world Web applications in C++ with significant and frequent interoperability with external JavaScript, Web APIs and the DOM.

Experimental support for anyref

Note: a technical post will be published soon providing an in-depth analysis of Cheerp support for anyref / externref.

anyref / externrefis a post-MVP WebAssembly feature in a very advanced stage of the standardization process. The idea behind it is to allow to pass around opaque host references (i.e. in the browser case, JavaScript / DOM objects) to WASM functions.

In Cheerp we have added experimental support for this feature as an extension of our existing DOM and JavaScript interoperability paradigm.

Without anyref, a WebAssembly application that needs to interact with the DOM needs to use methods tagged with [[cheerp::genericjs]]*.* We know from experience that this is not a problem in practice, but can be a little cumbersome for very short sections of code.

Having introduced anyref support, it is now possible to directly interact with the DOM from WebAssembly sections of code (usually, the whole source, or [[cheerp::wasm]]sections).

Compilation time

Compilation time has also been significantly reduced, especially for large codebases.

The PreExecuter , one of Cheerp’s custom optimisations, is now mature and fast enough to be recommended for any build (just add — cheerp-preexecute).

Cheerp 2.5 also introduces reproducible builds, which will simplify debugging. If you run the compiler twice on the same input code, the output will be the same.

Code generation

Many small improvements to WebAssembly code generation have also been implemented, which together sums up to an impressive reduction in code size, for the same (or better) performance.

To name a few interventions:

  1. CFGStackifier v2. We implemented a fully redesigned unified algorithm to render the control flow in WebAssembly and JavaScript. For more info see our original post .
  2. Globalization. Cheerp now takes advantage of WebAssembly globals to encode constants and global data when convenient.
  3. Improved GlobalDCE. Cheerp now removes global data which, even if modified, does never alter the observable state of the program.

Usability

Cheerp 2.5 includes several quality-of-life improvements for our users. The command-line options have been simplified and now WebAssembly is generated by default. Old command-line options are still fully supported and internally mapped to the new ones, for compatibility with existing build scripts.

Performance

Note: a detailed performance comparison with Emscripten was provided in our previous release candidate post (Cheerp 2.5-rc1). Benchmarks for Cheerp 2.5 lead to extremely similar results.

With every release of Cheerp, we commit to ensure that the compiled WebAssembly output is best in class in terms of build size and performance. Cheerp 2.5 continues to maintain this commitment with on average smaller builds compared to the latest release of Emscripten, even when the Emscripten MINIMAL_RUNTIME is enabled. On both Firefox and Chrome, WebAssembly code generated by Cheerp is 5–6% faster than Emscripten.

Cheerp allows to compile a single C++ code base to a combination of WebAssembly and JavaScript output, working around the limitations of WebAssembly (such as direct DOM and WebGL/WebAudio access). This can be done with no performance overhead.

In addition to the end-users of Cheerp, the main forces driving the optimisations of Cheerp are the other tools that we develop at Leaning Technologies, CheerpJ, our Java-to-WebAssembly and JavaScript converter and our experimental x86-to-WebAssembly virtualization solution CheerpX. Both projects rely very heavily on Cheerp and its optimisations.

Getting started with Cheerp 2.5

Cheerp 2.5 is available for Windows macOS and Linux . To get started with Cheerp, please visit the main Documentation page . You will find instructions on how to download, install and use Cheerp, as well as step-by-step tutorials.

HomeByMe , a home planning service developed by Dassault Systemes using Cheerp.

Summary

Cheerp 2.5 is the first major version of Cheerp after 2.0 was released one year ago, the first version of Cheerp supporting WebAssembly.

Cheerp 2.5 adds support for anyref, leading to even cleaner interoperability between WebAssembly and the host environment (DOM, Web APIs and JavaScript).

As with any release, Cheerp 2.5 introduces significant size and performance optimisations, maintaining Cheerp as the best-in-class tool for WebAssembly generation.

Cheerp 2.5 is a highly-optimised, robust, enterprise-grade WebAssembly compiler ready for applications of any scale.

Get in touch

Cheerp is an actively developed project backed by Leaning Technologies , a company with years of experience in compile-to-JavaScript and compile-to-WebAssembly solutions, and a strong technical team that can provide support and professional services if needed.

Tested on millions of lines of code, chosen by many commercial products , Cheerp is the best technology to enable complex, large-scale applications to be converted to a Web application.

For more information on how Cheerp can help your organization to leverage your existing C++ code to develop HTML5 web applications that work on any device, with no need for plug-ins or download, please check out our website .

Follow us on twitter or drop us a line on Gitter ! For additional technical information on Cheerp, please visit our wiki or our tech blog .

Thanks to Alessandro Pignotti, Carlo Piovesan, and Ryan Forde.

14 March 2023 Update: Cheerp 3.0 released and relicensed to Apache 2.0 licence! Release notes here.

Today we announce the release of Cheerp 2.5, the first major release of the Cheerp compiler after the release of 2.0 — the first release to support WebAssembly — one year ago. This follows our release candidate of April 8th, announced here .

Cheerp is an open-source, enterprise-grade C/C++ compiler that can generate WebAssembly , JavaScript, or a combination of the two. It is a commercial alternative to the Emscripten toolchain, focused on providing better interoperability with JavaScript, allowing to generate garbage-collectable JavaScript, smaller WebAssembly build size and better performance.

While also based on the LLVM/Clang stack, Cheerp does not rely on the LLVM WebAssembly backend, as Emscripten does*.*Cheerp is based on a custom extended Clang frontend *and* a custom LLVM backend.

With Cheerp 2.5, we make significant steps forward in terms of performance, making Cheerp the best performing C/C++ compiler for WebAssembly, both for compiled size and execution speed.

In addition, we continue our focus on providing better WebAssembly-JavaScript interoperability. Because Cheerp can compile to a combination of WebAssembly and JavaScript outputs, it can work around many limitations of WebAssembly (such as direct DOM and WebGL/WebAudio access) without sacrificing its native-like speed.

Cheerp 2.5 introduces experimental support for WebAssembly reference type anyref, a step towards supporting typed references when they will be part of WebAssembly. This feature allows for even cleaner interoperability with JavaScript and the DOM.

New in Cheerp 2.5

Note: most of these new features were discussed in our previous release candidate post .

/*  Compile with:
 *  /opt/cheerp/bin/clang++ -target cheerp-wasm -cheerp-wasm-enable=anyref -o anyref.js anyref.cpp 
 */
 
#include <cheerp/clientlib.h>
 
void webMain()
{
    client::Element* e = client::document.createElement("p");
    client::document.get_body()->appendChild(e);
    e->set_textContent("Anyref test");
}

Experimental support for anyref allows to manipulate the DOM in WebAssembly.

Cheerp 2.5 is the first major release of Cheerp since 2.0, the first to introduce support for WebAssembly. Cheerp 2.5 introduces support for WebAssembly reference type anyref, and is mostly focused on quality-of-life improvements, cleaner code generation, and faster build times.

Modernization

Cheerp is based on the LLVM/Clang framework. Since Cheerp 2.0, we have started a long term modernization effort to bring Cheerp fully on par with the upstream LLVM/clang project. The 2.5 release includes a first big step in this effort, as Cheerp has been rebased from LLVM/Clang 3.7 to the 6.0 version.

Further rebase work will continue in the next releases of Cheerp, to finally rebase it on up-to-date LLVM/Clang. We are doing this progressively to make sure no regressions are introduced, for the sake of both the end-users of Cheerp, and our other products CheerpJ and CheerpX , which rely heavily on Cheerp.

Interoperability with the host environment

Cheerp allows classes and functions to be tagged with optional attributes such as [[cheerp::genericjs]][[cheerp::wasm]] and [[cheerp::jsexport]], instructing Cheerp on the desired compilation behaviour for each section of the code. This allows to maintain a single central code base, while targeting both WebAssembly and JavaScript.

In WebAssembly mode, code runs faster but has limited access to browser APIs. This is the default compilation mode followed by Cheerp.

In JavaScript mode conversely, the code may run somewhat slower, but full access to browser APIs is possible, as well as garbage collection. This mode can be turned on selected parts of the code with the [[cheerp::genericjs]]attribute, or on the whole code base with a compile-time flag.

Cheerp 2.0 was the first release to provide this level of interoperability, but it’s the new 2.5 release that truly delivers on this promise. This feature support is now battle-hardened by one year of testing from our users and our other tools based on Cheerp.

With mature support for interoperability, it is now both possible and easy to write large scale real-world Web applications in C++ with significant and frequent interoperability with external JavaScript, Web APIs and the DOM.

Experimental support for anyref

Note: a technical post will be published soon providing an in-depth analysis of Cheerp support for anyref / externref.

anyref / externrefis a post-MVP WebAssembly feature in a very advanced stage of the standardization process. The idea behind it is to allow to pass around opaque host references (i.e. in the browser case, JavaScript / DOM objects) to WASM functions.

In Cheerp we have added experimental support for this feature as an extension of our existing DOM and JavaScript interoperability paradigm.

Without anyref, a WebAssembly application that needs to interact with the DOM needs to use methods tagged with [[cheerp::genericjs]]*.* We know from experience that this is not a problem in practice, but can be a little cumbersome for very short sections of code.

Having introduced anyref support, it is now possible to directly interact with the DOM from WebAssembly sections of code (usually, the whole source, or [[cheerp::wasm]]sections).

Compilation time

Compilation time has also been significantly reduced, especially for large codebases.

The PreExecuter , one of Cheerp’s custom optimisations, is now mature and fast enough to be recommended for any build (just add — cheerp-preexecute).

Cheerp 2.5 also introduces reproducible builds, which will simplify debugging. If you run the compiler twice on the same input code, the output will be the same.

Code generation

Many small improvements to WebAssembly code generation have also been implemented, which together sums up to an impressive reduction in code size, for the same (or better) performance.

To name a few interventions:

  1. CFGStackifier v2. We implemented a fully redesigned unified algorithm to render the control flow in WebAssembly and JavaScript. For more info see our original post .
  2. Globalization. Cheerp now takes advantage of WebAssembly globals to encode constants and global data when convenient.
  3. Improved GlobalDCE. Cheerp now removes global data which, even if modified, does never alter the observable state of the program.

Usability

Cheerp 2.5 includes several quality-of-life improvements for our users. The command-line options have been simplified and now WebAssembly is generated by default. Old command-line options are still fully supported and internally mapped to the new ones, for compatibility with existing build scripts.

Performance

Note: a detailed performance comparison with Emscripten was provided in our previous release candidate post (Cheerp 2.5-rc1). Benchmarks for Cheerp 2.5 lead to extremely similar results.

With every release of Cheerp, we commit to ensure that the compiled WebAssembly output is best in class in terms of build size and performance. Cheerp 2.5 continues to maintain this commitment with on average smaller builds compared to the latest release of Emscripten, even when the Emscripten MINIMAL_RUNTIME is enabled. On both Firefox and Chrome, WebAssembly code generated by Cheerp is 5–6% faster than Emscripten.

Cheerp allows to compile a single C++ code base to a combination of WebAssembly and JavaScript output, working around the limitations of WebAssembly (such as direct DOM and WebGL/WebAudio access). This can be done with no performance overhead.

In addition to the end-users of Cheerp, the main forces driving the optimisations of Cheerp are the other tools that we develop at Leaning Technologies, CheerpJ, our Java-to-WebAssembly and JavaScript converter and our experimental x86-to-WebAssembly virtualization solution CheerpX. Both projects rely very heavily on Cheerp and its optimisations.

Getting started with Cheerp 2.5

Cheerp 2.5 is available for Windows macOS and Linux . To get started with Cheerp, please visit the main Documentation page . You will find instructions on how to download, install and use Cheerp, as well as step-by-step tutorials.

HomeByMe , a home planning service developed by Dassault Systemes using Cheerp.

Summary

Cheerp 2.5 is the first major version of Cheerp after 2.0 was released one year ago, the first version of Cheerp supporting WebAssembly.

Cheerp 2.5 adds support for anyref, leading to even cleaner interoperability between WebAssembly and the host environment (DOM, Web APIs and JavaScript).

As with any release, Cheerp 2.5 introduces significant size and performance optimisations, maintaining Cheerp as the best-in-class tool for WebAssembly generation.

Cheerp 2.5 is a highly-optimised, robust, enterprise-grade WebAssembly compiler ready for applications of any scale.

Get in touch

Cheerp is an actively developed project backed by Leaning Technologies , a company with years of experience in compile-to-JavaScript and compile-to-WebAssembly solutions, and a strong technical team that can provide support and professional services if needed.

Tested on millions of lines of code, chosen by many commercial products , Cheerp is the best technology to enable complex, large-scale applications to be converted to a Web application.

For more information on how Cheerp can help your organization to leverage your existing C++ code to develop HTML5 web applications that work on any device, with no need for plug-ins or download, please check out our website .

Follow us on twitter or drop us a line on Gitter ! For additional technical information on Cheerp, please visit our wiki or our tech blog .

Thanks to Alessandro Pignotti, Carlo Piovesan, and Ryan Forde.

Latest Blogs