# Tricks to make Clojure(startup time) faster?

**URL:** https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176
**Category:** Beginners
**Created:** [December 12, 2017, 5:44am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176 "2017-12-12T05:44:34Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![zerg000000](https://clojureverse.org/user_avatar/clojureverse.org/zerg000000/32/698_2.png) [@zerg000000](https://clojureverse.org/u/zerg000000)
#### Post date: [December 14, 2017, 4:46am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/21 "2017-12-14T04:46:52Z")

</div>

let try~

```auto
{
 "dependencies": {
  "left-pad": "1.2.0"
 }
}

```

`npm install`

`lumo`

```auto
cljs.user=> (require '[left-pad :as lp])
nil
cljs.user=> (lp "foo" 5)
" foo"

```

seems nice!

---

<div class="post-metadata">

### Author: ![jiyinyiyong](https://clojureverse.org/user_avatar/clojureverse.org/jiyinyiyong/32/85_2.png) [@jiyinyiyong](https://clojureverse.org/u/jiyinyiyong)
#### Post date: [December 14, 2017, 6:29am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/22 "2017-12-14T06:29:46Z")

</div>

Good~

```clojure
=>> lumo
Lumo 1.7.0
ClojureScript 1.9.908
Node.js v8.4.0
 Docs: (doc function-name-here)
       (find-doc "part-of-name-here")
 Source: (source function-name-here)
 Exit: Control+D or :cljs/quit or exit

cljs.user=> (require '["md5" :as md5])
nil
cljs.user=> md5
#object[Function]

```

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [December 14, 2017, 7:14am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/23 "2017-12-14T07:14:55Z")

</div>

Yup, that syntax is standard Clojurescript now, it should be supported no matter which tool you’re using.

---

<div class="post-metadata">

### Author: ![jiyinyiyong](https://clojureverse.org/user_avatar/clojureverse.org/jiyinyiyong/32/85_2.png) [@jiyinyiyong](https://clojureverse.org/u/jiyinyiyong)
#### Post date: [December 14, 2017, 8:51am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/24 "2017-12-14T08:51:08Z")

</div>

Where did that happen? Last time I saw it, it was still in debate?

---

<div class="post-metadata">

### Author: ![zerg000000](https://clojureverse.org/user_avatar/clojureverse.org/zerg000000/32/698_2.png) [@zerg000000](https://clojureverse.org/u/zerg000000)
#### Post date: [December 14, 2017, 8:55am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/25 "2017-12-14T08:55:35Z")

</div>

seems like 1.9.854

> <https://github.com/clojure/clojurescript/blob/master/changes.md#19854>

---

<div class="post-metadata">

### Author: ![plexus](https://clojureverse.org/user_avatar/clojureverse.org/plexus/32/6_2.png) [@plexus](https://clojureverse.org/u/plexus)
#### Post date: [December 14, 2017, 10:12am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/26 "2017-12-14T10:12:25Z")

</div>

Here’s the blog post that introduced that

[https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules](https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules)

---

<div class="post-metadata">

### Author: ![jwr](https://clojureverse.org/user_avatar/clojureverse.org/jwr/32/685_2.png) [@jwr](https://clojureverse.org/u/jwr)
#### Post date: [December 18, 2017, 12:57pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/27 "2017-12-18T12:57:27Z")

</div>

> [@plexus](#):
>
> It bothers me to celebrate this kind of negativity. It also bothers me that this talks about “Clojure being slow” when it’s really “Clojure startup time being slow”.

FWIW, I didn’t take this as negativity, but rather pointing out an issue (the elephant in the room). I think we should pay attention to this issue. I use Clojure for lots of things and while I’m very happy with server code performance, developing could definitely use speed improvements. `cider-jack-in` takes so long that I often go and get coffee, and if ClojureScript compilation were faster, I’d be much happier, too.

I understand there are good reasons for why it is slow, but this doesn’t mean we shouldn’t pretend it isn’t. Progress is being made and things are getting faster.

---

<div class="post-metadata">

### Author: ![bdesham](https://clojureverse.org/user_avatar/clojureverse.org/bdesham/32/720_2.png) [@bdesham](https://clojureverse.org/u/bdesham)
#### Post date: [December 18, 2017, 6:31pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/28 "2017-12-18T18:31:00Z")

</div>

The startup time is especially painful for me when I’m doing something like formatting code with cljfmt. I’m using [these Boot tasks](https://gist.github.com/bartojs/83a096ecb1221885ddd1) to integrate cljfmt with Boot and running `boot fmt` takes over 24 seconds to run on one one-line file. Am I “doing it wrong”? Should I be running this workflow from a REPL somehow instead?

---

<div class="post-metadata">

### Author: ![martinklepsch](https://clojureverse.org/user_avatar/clojureverse.org/martinklepsch/32/80_2.png) [@martinklepsch](https://clojureverse.org/u/martinklepsch)
#### Post date: [December 18, 2017, 8:16pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/29 "2017-12-18T20:16:44Z")

</div>

FWIW there’s a [nodejs version of `cljfmt`](https://github.com/snoe/node-cljfmt) on npm that starts up much faster. 🙂

---

<div class="post-metadata">

### Author: ![bdesham](https://clojureverse.org/user_avatar/clojureverse.org/bdesham/32/720_2.png) [@bdesham](https://clojureverse.org/u/bdesham)
#### Post date: [December 18, 2017, 9:57pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/30 "2017-12-18T21:57:05Z")

</div>

I came across that before but I guess I wrote it off because there had been an “update dependencies” PR open for six months. But thank you for the link 🙂

In general, though, is “find a ClojureScript version” the go-to advice for any kind of tooling where a 20-second startup time is unacceptable?

---

<div class="post-metadata">

### Author: ![jackrusher](https://clojureverse.org/user_avatar/clojureverse.org/jackrusher/32/457_2.png) [@jackrusher](https://clojureverse.org/u/jackrusher)
#### Post date: [December 19, 2017, 9:19am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/31 "2017-12-19T09:19:18Z")

</div>

I tend to do most things using a long-lived JVM process controlled from within `emacs`.

---

<div class="post-metadata">

### Author: ![martinklepsch](https://clojureverse.org/user_avatar/clojureverse.org/martinklepsch/32/80_2.png) [@martinklepsch](https://clojureverse.org/u/martinklepsch)
#### Post date: [December 19, 2017, 11:20am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/32 "2017-12-19T11:20:20Z")

</div>

> [@bdesham](#):
>
> In general, though, is “find a ClojureScript version” the go-to advice for any kind of tooling where a 20-second startup time is unacceptable?

I wish I had a better answer but yeah I think at this point in time that’s often the most feasible approach.

---

<div class="post-metadata">

### Author: ![shakdwipeea](https://clojureverse.org/user_avatar/clojureverse.org/shakdwipeea/32/518_2.png) [@shakdwipeea](https://clojureverse.org/u/shakdwipeea)
#### Post date: [December 20, 2017, 12:38pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/33 "2017-12-20T12:38:54Z")

</div>

Can you share some more details about this workflow ?

I’m a bit confused.  
Is this the jvm started by the build tools eg. boot repl and reloading deps or controlling another jvm process?

---

<div class="post-metadata">

### Author: ![jackrusher](https://clojureverse.org/user_avatar/clojureverse.org/jackrusher/32/457_2.png) [@jackrusher](https://clojureverse.org/u/jackrusher)
#### Post date: [December 20, 2017, 4:29pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/34 "2017-12-20T16:29:48Z")

</div>

`lein repl` in a project, connect to it from `emacs` using `cider-connect`. One of things that makes this work well is having something like [alembic](https://github.com/pallet/alembic) in your main `lein` config so that you can pull in any deps you need without restarting.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [December 23, 2017, 8:37am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/35 "2017-12-23T08:37:54Z")

</div>

What I still ask myself is why ClojureScript doesn’t suffer from having to load, compile and init all namespaces in start-up?

If the culprit is Clojure and not the JVM, does ClojureScript bootstraps in a different way which solves exponentially the slow start-up times?

Or is it indirectly the JVM’s fault, in that load, compile and init are exponentially slower on the JVM then they are on V8?

One thought I had is, what if Clojure fns shared a class per namespace? Would this be doable? Would it speed up start-up and lower overall memory footprint?

---

<div class="post-metadata">

### Author: ![danielo515](https://clojureverse.org/user_avatar/clojureverse.org/danielo515/32/1495_2.png) [@danielo515](https://clojureverse.org/u/danielo515)
#### Post date: [April 10, 2018, 6:37am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/36 "2018-04-10T06:37:51Z")

</div>

Just to be clear, is Clojure startup time allways high or just for big projects or during development? I mean, a compiled small program will take that long to startup too?

---

<div class="post-metadata">

### Author: ![jackrusher](https://clojureverse.org/user_avatar/clojureverse.org/jackrusher/32/457_2.png) [@jackrusher](https://clojureverse.org/u/jackrusher)
#### Post date: [April 10, 2018, 8:38am UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/37 "2018-04-10T08:38:39Z")

</div>

JVM Clojure programs typically take a long time to start, though by “a long time” we mean a few seconds. Compiled ClojureScript programs running in Node start much faster (~100ms).

---

<div class="post-metadata">

### Author: ![danielo515](https://clojureverse.org/user_avatar/clojureverse.org/danielo515/32/1495_2.png) [@danielo515](https://clojureverse.org/u/danielo515)
#### Post date: [April 10, 2018, 12:20pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/38 "2018-04-10T12:20:34Z")

</div>

> [@jackrusher](#):
>
> Compiled ClojureScript programs running in Node start much faster (~100ms).

And that is the reason why I chose cljs for scripting, but I wanted to know how much does it take on clojure, because if it is one second vs 100ms I can live with it.

---

<div class="post-metadata">

### Author: ![dnolen](https://clojureverse.org/user_avatar/clojureverse.org/dnolen/32/504_2.png) [@dnolen](https://clojureverse.org/u/dnolen)
#### Post date: [April 10, 2018, 1:55pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/39 "2018-04-10T13:55:54Z")

</div>

> [@danielo515](#):
>
> And that is the reason why I chose cljs for scripting, but I wanted to know how much does it take on clojure, because if it is one second vs 100ms I can live with it.

Clojure doesn’t take longer than a second to start. If it takes longer than a second to run a simple script that almost always means you’re using some other thing that’s adding significant overhead - lein, boot, etc.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [April 10, 2018, 3:52pm UTC](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176/40 "2018-04-10T15:52:11Z")

</div>

Small scripts should start in around 1 second. There are cases where Clojure starts faster then ClojureScript. And if your script does a lot of CPU work, the speedup in execution time you get from Clojure can supersede the startup overhead, meaning the total execution time could still be faster in Clojure.

Take a look at this comparison: [https://github.com/kkinnear/zprint/blob/master/doc/filter.md#performance-results](https://github.com/kkinnear/zprint/blob/master/doc/filter.md#performance-results)

This is for a command line tool, and Clojure ends up being faster.

[Previous page](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176.md?page=1)

[Next page](https://clojureverse.org/t/tricks-to-make-clojure-startup-time-faster/1176.md?page=3)
