[ close ]
Help Upgrade the Web: Download Firefox 3.5

tracemonkey and you

There have been a pile of posts about the TraceMonkey code that just landed in mozilla-central. mozilla-central is the source code repository we’re using in the lead up to Firefox 3.1. Here are some posts if you want to read about it:

The heart of the story is that we’re seeing performance increases on benchmarks of anywhere from 1.8x to 37.5x depending on the benchmark used.

But the thing that most people don’t realize is that you can take advantage of the work that we’re doing in SpiderMonkey in your program as an embedded JS interpreter. It’s a pretty tiny engine, has a relatively stable API and even has useful documentation. John’s post contains four commands that you can use to build the engine. In fact, it’s so short, I’ll re-paste it here:

hg clone http://hg.mozilla.org/tracemonkey/
cd tracemonkey/js/src
make -f Makefile.ref BUILD_OPT=1
Linux_All_OPT.OBJ/js -j

And you’re in a command line JS interpreter. No fuss, no muss.

Many people don’t realize it but most of what people think of as JavaScript is the browser API, not the JavaScript language. To quote from the JavaScript C Engine Embedder’s Guide:

The word JavaScript may bring to mind features such as event handlers (like onclick), DOM objects, window.open, and XMLHttpRequest. But in Mozilla, all of these features are actually provided by other components, not the SpiderMonkey engine itself. SpiderMonkey provides a few core JavaScript data types—numbers, strings, Arrays, Objects, and so on—and a few methods, such as Array.push. It also makes it easy for each application to expose some of its own objects and functions to JavaScript code. Browsers expose DOM objects. Your application will expose objects that are relevant for the kind of scripts you want to write. It is up to the application developer to decide what objects and methods are exposed to scripts.

The Embedder’s Guide does contain a lot of good information you can use to get started embedding SpiderMonkey into your application. It’s worth a read if you’re looking for a decent scripting engine for your app.

  1. James Duncan’s avatar

    That’s exactly what we’re doing with reasonably smart. We’ve integrated tracemonkey in development now, but we’ve not turned it on in production yet, but this will probably change soon.

    As soon as I get a clean build in production tracemonkey is a go.

  2. blizzard’s avatar

    Nice! Keep an eye on the tracemonkey stuff. It’s likely to be in flux for some time to come.