X
Business

'Fastest ECMAScript engine on market' for Opera

Developer Jens Lindström writes on the Opera Core Concerns blog that a small team of developers and testers have been working on implementing a new ECMAScript/JavaScript engine for Opera over the past few months named "Carakan."The new project aims to develop "the fastest ECMAScript engine on the market.
Written by Andrew Nusca, Contributor

Developer Jens Lindström writes on the Opera Core Concerns blog that a small team of developers and testers have been working on implementing a new ECMAScript/JavaScript engine for Opera over the past few months named "Carakan."

The new project aims to develop "the fastest ECMAScript engine on the market."

Lindström writes:

When Opera's current ECMAScript engine, called Futhark, was first released in a public version, it was the fastest engine on the market. That engine was developed to minimize code footprint and memory usage, rather than to achieve maximum execution speed. This has traditionally been a correct trade-off on many of the platforms Opera runs on. The Web is a changing environment however, and tomorrow's advanced web applications will require faster ECMAScript execution, so we have now taken on the challenge to once again develop the fastest ECMAScript engine on the market.

Improvements upon the previous engine come in three main areas:

  • Register-based bytecode. The last couple of generations of Opera's ECMAScript engine have used a stack-based bytecode instruction set...In the new engine, we've instead opted for a register-based bytecode instruction set. In a register-based machine, instead of a dynamically sized stack of values, there's a fixed size block of them, called "registers". Instead of only looking at the values at the top of the stack, each instruction can access any register. Since there is no need to copy values to and from the top of the stack to work on them, fewer instructions need to be executed, and less data needs to be copied.
  • Native code generation. Although our new engine's bytecode instruction set permits the implementation of a significantly faster bytecode execution engine, there is still significant overhead involved in executing simple ECMAScript code, such as loops performing integer arithmetics, in a bytecode interpreter. To get rid of this overhead we are implementing compilation of whole or parts of ECMAScript programs and functions into native code. [...]

    The register allocator is designed to be architecture independent, and so is the code generation "frontend" where most of the complicated decisions are made. We have initially implemented a backend for 32- and 64-bit x86, but some preliminary work has already started to generate native code for other CPU architectures, such as ARM. [...]

    In addition to generating native code from regular ECMAScript code, we also generate native code that performs the matching of simple regular expressions. This improves performance a lot when searching for matches of simple regular expressions in long strings.

  • Automatic object classification. In the new engine, each object is assigned a class that collects various information about the object, such as its prototype and the order and names of some or all of its properties. Class assignment is naturally very dynamic, since ECMAScript is a very dynamic language, but it is organized such that objects with the same prototype and the same set of properties are assigned the same class.

    This representation allows compact storage of individual objects, since most of the complicated structures representing the object's properties are stored in the class, where they are shared with all other objects with the same class. In real-world programs with many objects of the same classes, this can save significant amounts of memory.

...all resulting in better performance. How fast, you ask?

Using a regular cross-platform switch dispatch mechanism (without any generated native code) Carakan is currently about two and a half times faster at the SunSpider benchmark than the ECMAScript engine in Presto 2.2 (Opera 10 Alpha).

The native code generation in Carakan is not yet ready for full-scale testing, Lindström writes, but "the few individual benchmark tests that it is already compatible with runs between 5 and 50 times faster."

Nice.

CNET's Stephen Shankland also has some nice insight into the speed issue.

Editorial standards