Improving Clojure startup time with -Xbootclasspath

Skip to first unread message

Alex Osborne

Nov 22, 2009, 9:07:20 PM11/22/09
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(
at clojure.lang.RT.load(

Which is this line from
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:

I don't get much of a benefit out of -XShare on my system but it might
be worth trying as well.

Dmitry Ulanov

Nov 23, 2009, 3:57:25 AM11/23/09
Very interesting tip! Also, like vimclojure, you can run nailgun ( locally or on your server via ssh.

You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
For more options, visit this group at

Meikel Brandmeyer

Nov 23, 2009, 4:06:55 AM11/23/09
to Clojure

On Nov 23, 9:57 am, Dmitry Ulanov <> wrote:

> Very interesting tip! Also, like vimclojure, you can run nailgun ( locally or on your
> server via ssh.

I'd also like to mention clj-server:


Armando Blancas

Nov 23, 2009, 10:16:43 AM11/23/09
to Clojure
I added the contrib lib expecting it to fail but it worked, and loaded
(in half the usual time) some code from the user.clj as well:

>java -Xbootclasspath/a:clojure\clojure.jar;clojure-contrib\clojure-contrib.jar clojure.main
Clojure 1.1.0-alpha-SNAPSHOT

I had been reading in this paper:
about the case below and how that could explain the NPE, but when I
added the lib to see it, the thing worked.

public class NewObjectLoader {
public static void main (String args[]) {
NewObject no = new NewObject();
no.getClass().getName() + " was loaded by " +
Sure enough, the NewObject class is not only found at compile-time and
runtime, but it prints
"NewObject was loaded by null", indicating it owes its existence to
the bootstrap ClassLoader.

Running on Vista
>java -version
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
Reply all
Reply to author
0 new messages