EN FR
EN FR


Section: New Results

JavaScript ahead-of-time compilation

Nowadays, JavaScript is no longer confined to the programming of web pages. It is also used for programming server-side parts of web applications, compilers, and there is a growing trend for using it for programming internet-of-things (IoT) applications. All major industrial actors of the field are looking for, or are already providing, JavaScript based development kits (IoT.js, Espruino, JerryScript, Kinoma.js, ...). In this application domain, JavaScript programs execute on tiny devices that have limited hardware capacities, for instance only a few kilobytes of memory. Just-in-time (JIT) compilation, which has proved to be so effective for improving JavaScript performances, is unthinkable in these constrained environments. There would be just not enough memory nor CPU capacity to execute them at runtime. Pure JavaScript interpreters are then used but this comes with a strong performance penalty, especially when compared to assembly or C programs, that limits the possible uses.

When JIT compilation is not an option and when interpretation is too slow, the alternative is static compilation, also known as ahead-of-time (AOT) compilation. It has the promise of combining small memory footprints and good performances. However, this implementation technique seems not to fit the JavaScript design whose unique combination of antagonistic features such as functional programming support, high mutation rates of applications, introspection, and dynamicity, makes most known classical AOT compilation techniques ineffective.

Indeed, JavaScript is hard to compile, much harder than languages such as C, Java, and even harder than other functional languages like Scheme and ML. This is because a JavaScript source code accepts many more possible interpretations than other languages do. It forces JavaScript compilers to adopt a defensive position by generating target codes that can cope with all the possible, even unlikely, interpretations. This difficulty probably explains why JavaScript AOT compilation has received so little attention from the scientific community. All these difficulties cannot be solved with traditional compilation techniques. They demand new strategies. This is what we explore. We are developing a prototype of a new compiler that distinguishes from classical compilers by relying on static program analyses that are not governed by approximating all possible program executions but by inferring properties that suit the compiler back-end. For instance, instead of inferring types that describe a super set of all possible executions, this compiler infers types for which the compiler is able to deliver good code.

The whole year has been devoted to implementing an operational prototype of the compiler. The preliminary results we have obtained are very promising but we still have to improve the code generation quality before writing and publishing complete reports describing it. This will be one of our main objectives for 2018.