Compiling C/C++ to JavaScript


Compiled programs are not necessarily the fastest way to execute programming code. In quite many cases, interpreted programs can be much faster since they can take into consideration the exact inputs upon which the the program is operating, while compiled programs must optimize for the entire range of input parameters. Unfortunately, most programmers still consider Visual Basic as a typical representative of interpreted languages which makes it hard to appreciate how much interpreted languages have evolved over the last decade or so. Only recently, with the introduction of powerful JavaScript engines such as V8, TraceMonkey, and Nitro have the mainstream programers started to appreciate the full potential of interpreted languages not only with regards to portability but also performance. One development that I find particularly amazing is the possibility of compiling low-level languages such as C/C++ to JavaScript without actually sacrificing much of performance, while gaining portability to almost all computing devices in the world. More than four decades of research has been invested by computer industry in optimal compilation of C/C++ code into machine instructions. If we could simulate machine instructions with JavaScript with reasonable performance all hell would break loose. Can you imagine Adobe Flash running not as a browser plug-in, but as a JavaScript code? Or FinalCut written entirely in JavaScript? This might soon become a reality as demonstrated by progress of asm.js project. For a good overview of the project check the amazing presentation at

Enhanced by Zemanta