We were discussing Clojure startup time (in the context of Leiningen)
and Phil Hagelberg asked some JRuby people about startup time. They
suggested using -Xbootclasspath.
Check this out:
% time (echo | java -client -cp clojure.jar clojure.main)
0.84s user 0.04s system 96% cpu 0.908 total
% time (echo | java -client -Xbootclasspath/a:clojure.jar clojure.main)
0.42s user 0.04s system 106% cpu 0.431 total
For the server VM:
% time (echo | java -server -cp clojure.jar clojure.main)
1.07s user 0.06s system 113% cpu 0.995 total
% time (echo | java -server -Xbootclasspath/a:clojure.jar clojure.main)
0.56s user 0.06s system 109% cpu 0.562 total
For reference:
% java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode)
Apparently on Dan Larkin's PC startup time went from a terrible 5.5s to
a more bearable 1.9s.
Looks like it's problematic to put Clojure libs in the bootclasspath
though. I get an NPE:
Caused by: java.lang.NullPointerException
at clojure.lang.RT.load(RT.java:377)
at clojure.lang.RT.load(RT.java:371)
Which is this line from RT.java:
URL classURL = baseLoader().getResource(classfile);
(clojure.lang.RT/baseLoader) isn't null, so I'm not sure what the deal
is with that unless the class loading runs in a different thread where
it is null or something. But if you just put the Clojure jar itself in
-Xbootclasspath and the rest of your libs as normal -cp you still get a
nice fast start. :-)
Charles Nutter has a nice list of JVM flags here:
http://blog.headius.com/2009/01/my-favorite-hotspot-jvm-flags.html
I don't get much of a benefit out of -XShare on my system but it might
be worth trying as well.