On Fri, 15 Jul 2011, Joel Dice wrote:
On Fri, 15 Jul 2011, George Jahad wrote:
very cool Joel! I'd also be interested in start up time of avian vs.
hotspot, i.e. does avian make it viable to use clojure for short,
quick scripts?
Possibly. By default, Avian is noticeably slower to start up than Hotspot,
at least when using OpenJDK's class library. The boot process for that
library touches a lot of code in a lot of classes, and Hotspot has several
performance advantages to make quick work of it. On the other hand, Avian
can also be built to use its own class library, which allows much faster
startup. Unfortunately, it doesn't currently have all the classes needed to
support Clojure, and I haven't checked to see how much would need to be added
to make it work.
Avian also supports ahead-of-time compilation from Java bytecode to native
machine code, so it would be possible to create an executable with all the
OpenJDK and Clojure classes precompiled, thereby bypassing the need for JIT
compilation at runtime except for dynamically-loaded classes. That would be
faster, but I'm not sure by how much.
The ideal approach in terms of startup time would be to add whatever classes
needed to Avian's class library to support Clojure, use ProGuard to shrink
and optimize the combination of clojure.jar and the system class library, and
precompile the result into native code. I might take a stab at that if I
have time.
I went ahead and pursued this. The upshot is that I can get Avian to run
a minimal Clojure script (containing just (println "hello, world!")) over
twice as fast as Hotspot by precompiling clojure.jar to native code.
These are the results on my 2.2GHz Xeon:
$ time java -jar ~/p/clojure-1.2.1/clojure.jar hello.clj
hello, world!
real 0m0.858s
user 0m1.004s
sys 0m0.040s
$ time ./build/clojure hello.clj
hello, world!
real 0m0.303s
user 0m0.264s
sys 0m0.036s
It turned out using OpenJDK's class library was not really the bottleneck,
which is good because Avian's built-in library would need to be augmented
significantly to run Clojure itself.
The main challenge is that Clojure touches a lot of code on startup, which
works the JIT compiler hard. Hotspot is better at this because it uses a
high-performance interpreter by default and doesn't JIT compile methods
until/unless it's deemed a win. Avian's not so smart; it has to compile
each method before it can be run. This makes Clojure a good test case for
profiling Avian's compiler, though, and I was able to cut startup time for
the JIT build by about 60% with a few judicious optimizations. Then I
moved on to an ahead-of-time (AOT) compiled build, which further reduced
startup time to to result above.
Ultimately, though, I don't think this is enough of an improvement to make
Clojure viable for short, quick scripts. 300ms is a long time for
printing "hello, world". I wonder how feasible it would be to make
Clojure rely more heavily on lazy initialization so there isn't as much
code to be run at startup for simple scripts. That's what I suspect needs
to be done to improve startup time on any VM.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en