Why is leiningen so slow when it starts?

前端 未结 5 1270
余生分开走
余生分开走 2021-02-13 14:34

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 clo

相关标签:
5条回答
  • 2021-02-13 15:02

    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

    0 讨论(0)
  • 2021-02-13 15:02

    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.

    0 讨论(0)
  • 2021-02-13 15:10

    There are multiple ways to improve the startup time off lein. Documented here:

    https://github.com/technomancy/leiningen/wiki/Faster

    0 讨论(0)
  • 2021-02-13 15:26

    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

    0 讨论(0)
  • 2021-02-13 15:27

    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.

    0 讨论(0)
提交回复
热议问题