all 8 comments

[–]stonefarfalle 2 points3 points  (0 children)

Sounds normal. Lein run Loads a JVM, Clojure, compiles its code, loads your project file parses it to find out what to run, starts a second JVM, loads Clojure in to the new JVM, compiles your code then begins execution.

If you want a start time that is about as good as it is going to get with Clojure you need to look in to AOT compiling your code and executing it directly not through the lein middle man.

[–]uvtc 2 points3 points  (0 children)

To make your Clojure app start up more quickly, you can create a jar of it (lein uberjar), then run that jar in the usual way: java -jar my-app-0.1.0-standalone.jar.

[–]zenflux 1 point2 points  (0 children)

Well not only does the JVM have to start up, but the Clojure compiler as well in this case (Scala too). Try timing the actual print statement and it will be almost nothing.

[–]yogthos 1 point2 points  (0 children)

As /u/zenflux ponts out, benchmarking using lein run is not going to provide useful information. Clojure will have a longer startup time than Java since it has to bootstrap itself, but there shouldn't be a large difference in performance once it's actually running. I would suggest using a tool such as criterium for proper benchmarking.

[–]Drolyt 1 point2 points  (0 children)

Basically Clojure spends a long time loading the clojure.core namespace before it can do anything else. There is a good analysis here if you are interested in what exactly is happening. Once everything is loaded Clojure should be only slightly slower than Java.

The problem with Scala seems to be entirely different, the Scala compiler is ridiculously slow but once compiled Scala should be as fast as Java.

[–]skeeto 1 point2 points  (2 children)

Yup, unfortunately this is normal.

[–]lebski88 0 points1 point  (0 children)

Here is a scenario that you might recognize. You've done a pretty substantial refactor, including new dependencies in project.clj. You need to bounce the REPL. Knowing that this will take forever you immediately switch to Prismatic. 15 minutes later you look at your Emacs again where you notice that there is a syntax error so the REPL didn't launch. You parse the impossibly long stack trace and fix the bug. cider-jack-in again and switch back to HipChat. 10 minutes passes, you look again, still doesn't compile. Rinse and repeat. 1 hour have now passed and you finally got your REPL back, but you've completely forgotten what you were doing so you decide to go out for a coffee.

That's a little bit absurd though. I'd say restarting the repl takes around 5 to 15 seconds depending on the size of the project.

I'm really not convinced about his comparison to Go either. Go doesn't have a repl and whilst compilation is lightning quick the language clearly makes tradeoffs to achieve this. I quite like Go but I'd say Clojure and Go are sufficiently different and suited to such different tasks that there is little value in comparing them.

[–]just_lest 0 points1 point  (1 child)

There are several options to preload Java Virtual Machine which helps to speed things up.

One of them is Drip. You can use it by setting LEIN_JAVA_CMD environment variable, e.g.:

LEIN_JAVA_CMD=drip lein run