3
votes

I am trying clojurescript and find it takes a long time to compile a very simple clojurescript source file into js. I can't believe this.

time cljsc hello.cljs '{:optimizations :advanced}' > hello.js

real    1m27.324s
user    1m2.412s
sys     0m0.676s

The snippet is from Clojurescript's github quick start page:

(ns hello)
(defn ^:export greet [n]
  (str "Hello " n))

Leaving out the :optimizations option, I still find it takes a long time:

time cljsc hello.cljs > hello.js

real    0m10.867s
user    0m22.301s
sys 0m0.412s

Is that normal ? Or how can I speed up that ?

2

2 Answers

1
votes

By calling cljsc you are firing up a JVM every single time you compile, which has to load tons of code, and then do the actual compiling. The JVM startup time alone is painful.

The general workflow is to not use cljsc, but keep a JVM open and compile with it every time. A common way to do this is to use lein-cljsbuild, which I highly recommend.

0
votes

Taking ten seconds to compile doesn't seem totally crazy to me, because it has to compile all of the standard cljs library to javascript as well as your trivial program. As for the advanced optimizations, that's probably just how long it takes to do anything. It's reading and optimizing thousands of lines of cljs.core javascript, and probably also the google closure libraries that (I think) are used by cljs.core.