What are the benefits of a tracing JIT?

Firefox uses a tracing JIT.  Adobe’s been using it for a while.  A Python interpreter uses tracing.  Microsoft is also researching its possibilities.  So what’s the big deal?

What is a tracing JIT?

Although tracing JITs are a complex technology, the core concept is about optimizing execution of the hot paths in a program.  The emphasis is specifically on hot paths that return to the start of a path which sounds very much like a loop.  However, the traditional definition of a programming loop is only a subset of these hot paths.  The broader definition includes code that spans methods and possibly even modules.  This broader definition of a loop is what’s called a trace.

Why use traces?

By JIT compiling the traces, code that is executed frequently runs faster.  Code that isn’t included in traces isn’t compiled.  The claim is untraced code would not benefit as greatly from JIT compilation since it is not executed as frequently.  The basic trade-off is the time needed to JIT compile and cache the resulting code versus the time needed to execute the code.

When does tracing happen?

Tracing takes place as instructions are interpreted.  Whether it’s Java, Python or Javascript, the code must be interpreted by a virtual machine.  It is during this stage that loops are detected and identified as traces.

How is a tracing JIT different from other JITs?

Run-time profiling for optimization and specific CPU and memory optimizations are done with most JITs to adapt the application for best performance.  However, non-tracing JIT implementations (Sun’s Java VM and Microsoft’s CLR) do this at the method level.  When code is determined to be “hot,” the entire method containing that code is JIT compiled and cached.  Tracing JITs do this at the trace level and may consist of a portion of a method (just a specific loop), multiple methods and even multiple methods from different modules.

Who is using tracing JITs?

The Mozilla Team uses a tracing JIT in the JavaScript engine for Firefox.  It’s codenamed TraceMonkey and is enabled by default in Firefox since version 3.5.  Adobe Labs has a tracing JIT called Tamarin.  It’s basically a JavaScript engine as well.  Technically, it’s an implementation of ActionScript which is based on ECMAScript which JavaScript is based on.  Tamarin and TraceMonkey are so closely related that they both use the same backend: NanoJit.

A Python interpreter called PyPy recently switched from being based on partial evaluation to a tracing JIT.  Microsoft is researching and prototyping a tracing JIT compiler (TJIT) for the common intermediate language (CIL) called SPUR.

Where can I find out more?

This post only scratches the surface.  There’s plenty more about tracing JITs!

Like what you’ve read?

If so, please enter your email address to get free updates, stuff you can’t find on the blog and a free report: The Top 10 Tools I Use To Supercharge My Learning (Hint: The Top 5 Are Free)

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × one =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>