Jeene update: Performance, features and backlog

September 21, 2008 – 6:19 pm

Don’t know what Jeene is? It will make your JavaScript code run faster ;-) read the intro first,
then come back to this!

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)
    1. Without specialization: 1430ms;
    2. With specialization: 635ms;
    3. Specialization reduces time by approx. 56%.
  • Firefox 3: (Mac)
    1. Without specialization: 386ms;
    2. With specialization: 230ms;
    3. Specialization reduces time by approx. 40%.
  • Opera 9.52: (Mac)
    1. Without specialization: 502ms;
    2. With specialization: 251ms;
    3. Specialization reduces time by approx. 50%.
  • Firefox 3.1 – TraceMonkey (Mac)
    1. Without specialization: 302;
    2. With specialization: 152ms;
    3. Specialization reduces time by approx. 50%.
  • Chrome – V8: (Windows Vista)
    1. Without specialization: 227ms;
    2. With specialization: 83ms;
    3. Specialization reduces time by approx. 63%.
  • IE6/7 (approx. the same numbers) (Windows Vista)
    1. Without specialization: 2672ms;
    2. With specialization: 1485ms;
    3. Specialization reduces time by approx. 44%.
  • Safari 3.1.2 (Mac)
    1. Without specialization: 378ms;
    2. With specialization: 157ms;
    3. Specialization reduces time by approx. 58%.
  • WebKit nightly — SquirrelFish Extreme (Mac)
    1. Without specialization: 247ms;
    2. With specialization: 94ms;
    3. 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…

  1. 2 Responses to “Jeene update: Performance, features and backlog”

  2. Hi,

    First off, great job!

    I’m writing a little soon-to-be-released reactive animation library based on Flapjax (flapjax-lang.org).

    Incidentally, functions that need specializing are pure and referentially transparent, but they do have local variables (constants, really) and ternary ifs…

    > to be associative, which is not sound in general but is for common case uses (ask me for details)

    Can you elaborate on this point?

    Do you mean that (1 + (2 + “foo”)) and ((1 + 2) + “foo”) give different results? Anything else? (problems with floating-point precision, perhaps?)

    Thanks for your work!

    By artyom on Apr 9, 2009

  3. It is a long time since I wrote that comment ;-) But I believe that I meant the

    (1 + (2 + “foo”)) != ((1 + 2) + “foo”)

    example.

    I haven’t been working on Jeene for a while, since a couple of people got me down about using toString/toSource on functions and then re-parsing them.

    Good to hear from you. Let me know if you are more interested in Jeene.

    - Karl

    By admin on Apr 9, 2009

You must be logged in to post a comment.