#### Performance examples

I was curious about the performance gains of functions specialized via Jeene, so I ran a simple performance example in Firefox 2 and 3; Safari 3.1.2; Opera 9.52; SquirrelFish Extreme (the new JIT); IE 6, 7 ; Google's Chrome and finally, TraceMonkey. All with great results! You can run the simple example here. The test executes the string concatenation example from the previous post. The actual example is not that interesting; what is interesting is that Jeene works in all current popular JavaScript implementations and that it gives good performance boosts also in the new JITs: V8, TraceMonkey and SquirrelFish Extreme. The figures include the time it takes to specialize the function, so they are actual performance gains. (Note that the Windows and Mac tests were on different hardware).- Firefox 2: (Windows Vista)
- Without specialization: 1430ms;
- With specialization: 635ms;
**Specialization reduces time by approx. 56%.**

- Firefox 3: (Mac)
- Without specialization: 386ms;
- With specialization: 230ms;
**Specialization reduces time by approx. 40%.**

- Opera 9.52: (Mac)
- Without specialization: 502ms;
- With specialization: 251ms;
**Specialization reduces time by approx. 50%.**

- Firefox 3.1 - TraceMonkey (Mac)
- Without specialization: 302;
- With specialization: 152ms;
**Specialization reduces time by approx. 50%**.

- Chrome - V8: (Windows Vista)
- Without specialization: 227ms;
- With specialization: 83ms;
**Specialization reduces time by approx. 63%**.

- IE6/7 (approx. the same numbers) (Windows Vista)
- Without specialization: 2672ms;
- With specialization: 1485ms;
**Specialization reduces time by approx. 44%**.

- Safari 3.1.2 (Mac)
- Without specialization: 378ms;
- With specialization: 157ms;
**Specialization reduces time by approx. 58%**.

- WebKit nightly -- SquirrelFish Extreme (Mac)
- Without specialization: 247ms;
- With specialization: 94ms;
**Specialization reduces time by approx. 61%**.

#### What can Jeene do right now?

Specialize JavaScript functions written in simplified JavaScript which contain the following constructs (note as of now you can only specialize with primitive values, e.g., strings and numbers; this will be fixed soon):- variables which occur in the function's formal parameter
- literals and constants ("abc", 42, true, null)
- simple assignment '='
- and, or, not logical operators '&&', '||', '!'
- plus and minus binary operators ('+' and '-'); by default it assumes '+' to be associative, which is not sound in general but is for common case uses (ask me for details)
- return statements

#### What Jeene can't do right now (i.e., what I am working on).

Some of these are easy, others are harder and need careful analysis.- global variables (in general variables in the function's closure)
- 'var' statements (i.e., local variable declaration and initialization)
- incrementing/decrementing assignments ('+=' and '-=')
- ternary if, i.e., "exp ? v1 : v2" operator
- comparison "===", "!==", "<", "<=", ">", ">="
- multiplication, division ('*','/')
- static/dynamic property lookup ('.' and '[')
- function calls ("fn()")
- unary minus ('-1')
- typeof operator ('typeof x')
- function operator ('function(){}')
- expression statements, array and object literals
- expression statements, array and object literals
- 'if', 'break' statements
- 'while' and 'for' statements

### New in latest svn commit

Jeene can now handle simple assignments of the form (x = exp) where x is a variable and exp is an expression. Further, formal parameters which are specialized disappear from the formal parameters in the specialized function, but now appear as local variables of that function (so that one can assign to them). Consider this example:Function.prototype.specialize = net.higherorder.jeene.Jeene.make(); source_fun = function(a,b,c) { c = a; return b+c; }; var env = {a:3, b:2}; res = source_fun.specialize(env);

Result: (function (c) {var a, b;return 5;})

Note that the assignment c=a; can be eliminated and the static value of a is propagated to c so that the expression returned is static. Neat ;-) Check back for more later...