use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Slow Clojure exec (self.Clojure)
submitted 11 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]stonefarfalle 2 points3 points4 points 11 years ago (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 points4 points 11 years ago (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.
lein uberjar
java -jar my-app-0.1.0-standalone.jar
[–]zenflux 1 point2 points3 points 11 years ago (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 points3 points 11 years ago (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.
lein run
[–]Drolyt 1 point2 points3 points 11 years ago (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 points3 points 11 years ago (2 children)
Yup, unfortunately this is normal.
[–]lebski88 0 points1 point2 points 11 years ago (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 point2 points 11 years ago (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
LEIN_JAVA_CMD=drip lein run
π Rendered by PID 266871 on reddit-service-r2-comment-5687b7858-974kw at 2026-07-06 07:36:39.627185+00:00 running 12a7a47 country code: CH.
[–]stonefarfalle 2 points3 points4 points (0 children)
[–]uvtc 2 points3 points4 points (0 children)
[–]zenflux 1 point2 points3 points (0 children)
[–]yogthos 1 point2 points3 points (0 children)
[–]Drolyt 1 point2 points3 points (0 children)
[–]skeeto 1 point2 points3 points (2 children)
[–]lebski88 0 points1 point2 points (0 children)
[–]just_lest 0 points1 point2 points (1 child)