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:
- Brendan Eich: TraceMonkey: JavaScript Lightspeed
- John Resig: TraceMonkey
- Mike Schroepfer: What can you do when your browser is 7 times faster?
- Mike Shaver: The birth of a faster monkey
- Ryan Paul: Firefox to get massive JavaScript performance boost
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.
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.
Nice! Keep an eye on the tracemonkey stuff. It’s likely to be in flux for some time to come.
Pingback: Christopher Blizzard » Blog Archive » initial thoughts on google chrome
Pingback: Embeddable languages : Havoc's Blog
apparently building is not that simple, anymore.
this:
make -f Makefile.ref BUILD_OPT=1
does not work anymore.
and, it’s not that simple anyway, we have to install loads of stuff before we can build, and use mercurial (hg)
i really wish it was easier.
i’m on mac os x, but i suppose that only the last line in your example should be different, right ?
OK, i think i found the way to do this.
after downloading the source with hg i configure with autoconf-2.13
(make sure you have that version, and it’s name, it varies from system to system)
here are the commands i used:
hg clone http://hg.mozilla.org/tracemonkey/
cd tracemonkey/js/src
autoconf-2.13
make