Archive for April, 2013
Duetto: A faster and smarter alternative to Emscripten. And more.
Posted by Alessandro Pignotti in Leaningtech on April 16, 2013
We have seen a lot of hype on the Web recently after the announcement of Asm.js by Mozilla: a new “extraordinarily optimizable, low-level subset of JavaScript”. The system builds on the work that has been done on Emscripten: a LLVM-based solution which compiles C++ to JavaScript, allowing for an easy port of applications and games to the Web. The excitement for Asm.js stems from the fact that, by using a special virtual machine integrated in Firefox, it can improve the performance of emscripten-generated code and get it even closer to native performance.
We (Leaning Technologies Ltd) would like to introduce Duetto, our own LLVM-based solution for programming the Web using C++. And by the Web, we mean both the client and server side of it, but let’s talk about the client side first.
Emscripten handles C++ code by emulating a full byte-addressable address space. This is definitely a good solution, but suboptimal. Javascript is not based on a byte-addressable address model, but on an object-addressable model: all the accessible memory is contained in some object. But when you think about it, C++ is not that different.
Our solution integrates with clang and the LLVM toolchain and is able to map C++ object-oriented constructs to native JavaScript objects. It turns out that accessing objects on modern JavaScript engines is faster than accessing arrays. By using this (and a few more) tricks we managed to get the following, preliminary, results on micro benchmarks.
We managed to do this by realizing that by disallowing some unsafe C++ capabilities (such as type unsafe pointer casting and pointer arithmetics inside structures) it’s actually possible to create more efficient, smaller and faster JavaScript code from C++. Interestingly enough, we discovered that, in most cases, the needed limitations on the language are actually specified as undefined behaviour!
So, yes, Duetto does need some minimal porting to bring C++ code to the Web while emscripten makes it mostly free. What you get in exchange for that is faster performance with no need of a special VM and deep integration with the browser. Duetto creates a really seamless C++ programming experience for the Web:
- Seamless integration with the browser environment, complete access to the DOM and HTML5 technologies including WebGL. You can even access and use your favourite JavaScript library or existing JavaScript from C++ by declaring the available interfaces in the C++ code using a simple convention.
- Seamless client/server programming, using transparent RPCs in single codebase. The compiler will split the code automatically in the client part (compiled to JavaScript) and server part (compiled to native code).
The Duetto backend is already in a very advanced state, and we believe it’s already suitable to bring the first applications to the Web. Especially games, which are our primary target. Unfortunately our front end is not yet as polished as we would like, as we want to improve the error reporting to make the porting experience as smooth as possible.
We are not yet ready to release Duetto, but we are eager to start opening collaborations, so if you are interested in bringing your C++ application or game to the web, feel free to contact me (alessandro@leaningtech.com). We believe that in six months or less from now we will be able to release a robust product, most probably capable of generating even faster code. And we want to release it as open source.
For more information please visit our site: http://www.leaningtech.com
Duetto: A faster and smarter alternative to Emscripten. And more.
Posted by Alessandro Pignotti in Leaningtech on April 16, 2013
We have seen a lot of hype on the Web recently after the announcement of Asm.js by Mozilla: a new “extraordinarily optimizable, low-level subset of JavaScript”. The system builds on the work that has been done on Emscripten: a LLVM-based solution which compiles C++ to JavaScript, allowing for an easy port of applications and games to the Web. The excitement for Asm.js stems from the fact that, by using a special virtual machine integrated in Firefox, it can improve the performance of emscripten-generated code and get it even closer to native performance.
We (Leaning Technologies Ltd) would like to introduce Duetto, our own LLVM-based solution for programming the Web using C++. And by the Web, we mean both the client and server side of it, but let’s talk about the client side first.
Emscripten handles C++ code by emulating a full byte-addressable address space. This is definitely a good solution, but suboptimal. Javascript is not based on a byte-addressable address model, but on an object-addressable model: all the accessible memory is contained in some object. But when you think about it, C++ is not that different.
Our solution integrates with clang and the LLVM toolchain and is able to map C++ object-oriented constructs to native JavaScript objects. It turns out that accessing objects on modern JavaScript engines is faster than accessing arrays. By using this (and a few more) tricks we managed to get the following, preliminary, results on micro benchmarks.
We managed to do this by realizing that by disallowing some unsafe C++ capabilities (such as type unsafe pointer casting and pointer arithmetics inside structures) it’s actually possible to create more efficient, smaller and faster JavaScript code from C++. Interestingly enough, we discovered that, in most cases, the needed limitations on the language are actually specified as undefined behaviour!
So, yes, Duetto does need some minimal porting to bring C++ code to the Web while emscripten makes it mostly free. What you get in exchange for that is faster performance with no need of a special VM and deep integration with the browser. Duetto creates a really seamless C++ programming experience for the Web:
- Seamless integration with the browser environment, complete access to the DOM and HTML5 technologies including WebGL. You can even access and use your favourite JavaScript library or existing JavaScript from C++ by declaring the available interfaces in the C++ code using a simple convention.
- Seamless client/server programming, using transparent RPCs in single codebase. The compiler will split the code automatically in the client part (compiled to JavaScript) and server part (compiled to native code).
The Duetto backend is already in a very advanced state, and we believe it’s already suitable to bring the first applications to the Web. Especially games, which are our primary target. Unfortunately our front end is not yet as polished as we would like, as we want to improve the error reporting to make the porting experience as smooth as possible.
We are not yet ready to release Duetto, but we are eager to start opening collaborations, so if you are interested in bringing your C++ application or game to the web, feel free to contact me (alessandro@leaningtech.com). We believe that in six months or less from now we will be able to release a robust product, most probably capable of generating even faster code. And we want to release it as open source.
For more information please visit our site: http://www.leaningtech.com