Best-in-class WebAssembly with Cheerp 2.5 (RC1)
Smaller and faster WebAssembly from C++ compared with Emscripten
Today we are proud to announce the first release candidate of Cheerp 2.5 (2.5RC1), a major update to the Cheerp toolchain since the release of Cheerp 2.0 — the first release to support WebAssembly — one year ago.
While also based on the LLVM/Clang stack, Cheerp does not use the upstream LLVM WebAssembly backend, as Emscripten does. Cheerp is based on a custom extended Clang frontend and a custom LLVM backend.
We are strong believers in the WebAssembly ecosystem, and on the power of healthy competition in pushing the envelope of what is possible, particularly when it comes to performance and optimisations. We were therefore particularly interested to see Emscripten now being based on the LLVM WebAssembly backend for code generation, and excited to see if we could achieve better WebAssembly performance with Cheerp.
New in Cheerp 2.5
Cheerp 2.5 is the result of 12+ months of hard work by our development team. While this release does not introduce major new features, it is fully focused on quality-of-life improvements, cleaner code generation, and faster build times.
Cheerp is based on the LLVM/Clang framework. Since the 2.0 release, 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. This work will be ongoing for the next few releases, to finally rebase Cheerp 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 for the sake of our other products CheerpJ and CheerpX.
Cheerp allows classes and functions to be tagged with optional attributes such as
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. Compilation time has also been significantly reduced, especially for large codebases. Debugging should also be simpler as now the builds are fully reproducible: if you run the compiler twice on the same input, the output will be the same.
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:
- Globalization. Cheerp now takes advantage of WebAssembly globals to encode constants and global data when convenient.
- Improved GlobalDCE. Cheerp now removes global data which, even if modified, does never alter the observable state of the program.
Benchmarks — Cheerp vs. Emscripten
The performance was evaluated on Google Chrome (standalone v8 — version 8.3.12) and Mozilla Firefox (standalone SpiderMonkey — version shipped with Firefox 74). The performance was compared with the latest release of Emscripten (version 1.39.11).
For the scope of evaluating this release candidate, we focused on the four largest (the
zzz_ suite) test cases. These tests are part of Emscripten’s benchmark suite, we have sent a pull request to update the existing Cheerp support to the new command-line options in Cheerp 2.5.
Size benchmarks are platform-independent. The total output size was compared after gzip- compression, which is better related to real-world download time over HTTP.
Compared to Cheerp 2.0, this is an improvement of over 18% in raw size on average, making Cheerp the best-in-class tool for the generation of WebAssembly from C/C++.
We believe that these results show that our single-step, integrated codegen is a better approach to size optimization compared to Emscripten’s approach of codegen followed by a separate optimization step using wasm-opt.
Run time performance was averaged on three runs on a standard reference Linux machine. Similar results have been achieved on other hardware.
On Firefox’s SpiderMonkey engine, Cheerp 2.5 WebAssembly output is on average 5% faster than Emscripten (16% faster if not excluding an outlier). The zlib benchmark is 51% faster on Cheerp compared to Emscripten, suggesting some missed opportunities in Emscripten’s codegen on this specific test case, or perhaps a regression.
On Chrome’s v8, Cheerp 2.5 is 5% faster than Emscripten on average (16% faster if not excluding an outlier). The zlib anomaly can be replicated also on Chrome, with Cheerp 50% faster than Emscripten.
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.
Cheerp 2.5 is the result of one year of active development focused on optimisation starting from version 2.0.
With a build size on average 8% smaller compared to Emscripten, and performance 5% faster on average compared to Emscripten on both Chrome and Firefox, Cheerp 2.5 is now the best-in-class compiler for the generation of WebAssembly from C/C++.
Get in touch
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.
Last minute note
After this post and Cheerp 2.5rc1 were finalized, @Alon Zakai got in touch with us to recommend we use the MINIMAL_RUNTIME of Emscripten when comparing size and performance vs. Cheerp. In this post, we used the latest tagged release of Cheerp and Emscripten at the time of writing, which does not activate the MINIMAL_RUNTIME option.
For the final release of Cheerp 2.5, we will run the numbers again on the latest release of Emscripten, which will most likely enable the MINIMAL_RUNTIME.
A preliminary test run on our four benchmarks suggests that while this option of Emscripten indeed appears to reduce build sizes significantly, Cheerp still leads to a smaller build size on average.