Why is leiningen so slow when it starts?
Asked Answered
R

4

14

I'm using lein repl to execute clojure repl in console. When I run it, it takes over 15 seconds. When I run java -cp clojure-1.6.0.jar clojure.main, it takes just a few seconds.

Why is lein repl so slow? Are there anyways to make it faster?

My env:

  • H/W: MacBookAir
  • O/S: Mac OS 10.9 Mavericks
  • CPU: i7
  • MEM: 8GB
Riggle answered 31/7, 2014 at 6:32 Comment(5)
It starts a JVM. Probably it's just JVM startup time.Akron
@Akron As I stated in the question, when I run repl by java -cp clojure-1.6.0.jar clojure.main, it starts relatively fast. So it's not due to the JVM startup time.Riggle
I tried it on my system which is exactly the same macbook air as yours. You are correct lein repl takes about twice as long to start.Akron
@Mars Your comment should be an answer.Riggle
I knew that it was kind of an answer, but I usually like to have a more knowledge of what I'm talking about, and to provide more detail when I post something as an answer. But I've gone ahead and posted it as an answer, as you suggested.Pascual
P
10

Leiningen starts two JVMs, and hooks them together. It's got to load extra stuff to do that. The prompt you type into is a different process from the Clojure process that evaluates your code. Leiningen also has to parse your project file and make sure that everything is set up as it requires, or go and get what's needed from the web if there's anything missing in your maven configuration directory. In the Leiningen sample project file there are some options that can speed up things a little bit, if you read through it carefully. I think that Leiningen having slow startup is just one of the facts of life right now.

More relevant information:

Improving startup time of Clojure REPL with Leiningen on the Raspberry Pi

Faster

Pascual answered 1/8, 2014 at 3:41 Comment(2)
I've tried many different things, yet lein repl's startup time is still significantly slower than running it directly through java. I'm wondering would it be wrong to run it via alias for java -cp ~/.m2/repository/org/clojure/clojure/1.7.0/clojure-1.7.0.jar clojure.main. This won't solve it for cider, yet for smaller experiments in term would work, no? Maybe I could even use drip to make it even more faster?Prudie
I don't know, @Agzam. Some of the other answers might be relevant.Pascual
B
4

If you run lein repl from within a project directory, it will load your project's source files in addition to starting a repl. Even for a small project, this can add significant time if your source files reference external dependencies.

java -cp clojure-1.6.0.jar clojure.main won't load any project source files or dependencies.

Bellaude answered 31/7, 2014 at 14:30 Comment(1)
With project dependencies: lein uberjar; java -cp target/*standalone.jar clojure.mainVorticella
P
2

Your first question has been answered, so regarding the second one I guess what you want is to decrease the booting time cause you usually load some namespaces that are being changed as you code. It's possible to reload code from a modified namespace without exiting the REPL with (use 'your.namespace :reload). This way you might boot just once and reload the updated namespaces

user=> (doc require)

...

  :reload forces loading of all the identified libs even if they are already loaded
  :reload-all implies :reload and also forces loading of all libs that the identified libs directly or indirectly load via require or use

...

In the other hand if you read the output of lein help repl you will see how setup a REPL server and client that might reduce your booting time

Phenosafranine answered 1/8, 2014 at 0:33 Comment(0)
A
1

In my case it was the cider-nrepl plug-in that significantly contributed to the load time.

Quick unscientifical research with jvisualvm showed that good deal of time goes into loading & evaluating the files (0.10-snapshot is not AOT-ed) and there was also init logic that scans the classpath.

Using fast trampolines halved the start-up time.

The jvm plays no bigger role than the OS or the file system in my opinion. It's all about the code being loaded.

Aerograph answered 15/9, 2015 at 21:17 Comment(1)
So overall did you get a reasonable experience with a development setup on the Pi?Poolroom

© 2022 - 2024 — McMap. All rights reserved.