Blog by Brian Hackett, Firefox Engineer
Firefox 9 features the release of Type Inference, or TI, a research project under way for over a year. TI is a feature in the SpiderMonkey Javascript engine which generates type information about Javascript programs through a combination of analyzing the program’s code and monitoring the types of values as the program executes. This type information is used during JIT compilation to generate more efficient code; Firefox 9 includes modifications to the JaegerMonkey JIT compiler to use inferred type information. This compilation mode, which is the default in Firefox 9, speeds up major benchmarks like Kraken and V8 by over 30%, and gives a large speed boost to many JS heavy websites.
Javascript is a dynamically typed language, and without knowing the types of values a JIT compiler needs to generate code that accounts for all the possible types of the involved values. This significantly slows down execution of the program in comparison with a statically typed language like Java. With TI integration into JaegerMonkey, we are closing a significant part of this performance gap. Ongoing Mozilla projects are being built to leverage inferred type information. With these projects, primarily IonMonkey, Mozilla’s next generation JIT compiler, we hope to close the performance gap with Java completely. A more detailed writeup on the internal algorithms and other techniques used by Type Inference is available here.