You are doing it wrong…

SimpleLisp is an interpreter, written in Java, for a limited dialect of LISP. I have been using it as an example Java program to evaluate my compiler optimisations. I just tried running a simple Lisp program (to calculate the Fibonacci sequence) in SimpleLisp to see the affect of my optimisations on the run time. Here are some results.

SimpleLisp compiled with jkit, without my optimisation stage:

$ time java org/simplelisp/interpreter/Interpreter examples/Fibonacci.sl
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393

real 0m3.380s
user 0m3.294s
sys 0m0.031s

SimpleLisp compiled with jkit, with my LICM optimisation stage:

$ time java org/simplelisp/interpreter/Interpreter examples/Fibonacci.sl
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393

real 0m4.289s
user 0m4.136s
sys 0m0.051s

Something is not quite right here…

Advertisements

Tags: , , , ,

3 Responses to “You are doing it wrong…”

  1. qwandor Says:

    Okay, by reducing the amount of ‘optimisation’ I do (only moving expressions out of loops if they actually contain method calls or field dereferences), I can get more reasonable times, but still not any faster than the unoptimised build:

    real 0m3.441s
    user 0m3.282s
    sys 0m0.051s

    real 0m3.442s
    user 0m3.295s
    sys 0m0.040s

  2. Dmitry Says:

    You should first profile the application to identify the bottlenecks, then optimize those bottlenecks, then repeat. This is much more effective than mechanically applying a trivial optimization throughout the entire code base.

    Two good Java profilers are JProfiler and Yourkit.

  3. qwandor Says:

    If I were trying to optimise a particular program, then I would agree with you Dmitry. However, the aim of this project is to prototype a new compiler optimisation based on using knowledge of pure methods (and other properties of classes and methods) to do loop invariant code movement that would not otherwise be possible. As such I am trying at the moment to find cases where the existing optimisations in HotSpot’s JIT (for example) cannot be applied as it does not know enough about the structure of the program, but my optimisations can safely be applied and improve performance.

    It seems that such cases are not as common as I had hoped. However, I have just this evening been looking at other JVMs that do not do so much optimisation at runtime, and in these cases my compile-time optimisations do seem to be worthwhile. I will post some more about this shortly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: