Tombstone
HUROX compilers: JavaScriptMaster and Pudding
Nov 2006 โ Jun 2007 ยท age 24โ25
What it was
Two small C# compilers that fed hurox.com. JavaScriptMaster parsed a deliberately strict subset of JavaScript with an ANTLR 2.7.5 grammar, stripped comments, hoisted loop bounds and repeated property chains, renamed every local to a short name based on its place in the scope chain, and printed the program back on one line. Its trick was to serialise the parse tree as Lisp text and re-read it, so each optimiser simply wrote Lisp and compiled it. Run over the site, it cut 267 KB of JavaScript to 202 KB. Pudding turned HTML templates with holes into JavaScript functions, joining the string pieces lightest-first into a balanced tree, and it rebuilt the site's front page chrome at 3:44 on the final morning. JavaScriptMaster was written in six weeks from April 26, 2007.
Wins, for the age
- At twenty-five, this primate wrote a parser, a scope analyser, two optimisers and an emitter in six weeks because a website wanted smaller JavaScript. Eighteen of nineteen real files came out intact, 24.5 percent smaller.
- Found scope-aware local renaming on its own, the idea Dojo ShrinkSafe (2005) had already shipped, and kept shadowing correct.
- Blanked comments with spaces of the same length so error positions stayed valid, a trick that reappears in a later compiler.
- A redeclaration lint with a case-insensitive tier ran on every compile. The human obeyed it, renaming exception variables to satisfy it.
What it taught
- A subset grammar is a product decision. Forbidding
switch,inand regex kept the compiler small and the site's code in a shape one person could reason about. - Text is a fine intermediate representation when the program is small.
- Measure before minifying: extra parentheses in the emitter paid back bytes the renamer had saved.
- Open the output after the parse succeeds. A crash mid-build left a zero-byte file among the good ones.
Genealogy
Ancestors: JavaScript Pro: the ANTLR JavaScript parser that renamed every local to a short name. Mathml: a markup tree compiled into an expression string. Descendants: none on record. Closure Compiler and YUI Compressor won this category soon after. Part of: HUROX.
Epitaph
Here lies a compiler for exactly the JavaScript its author allowed, and a template compiler that weighed its strings before joining them. One left a zero-byte file behind; the other rebuilt the front page at 3:44 on the last morning.