Skip to content

Commit fc66a5a

Browse files
committed
CLJS-2896: Allow parallel analysis and compilation
1 parent 0598b93 commit fc66a5a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: src/main/clojure/cljs/closure.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@
10471047
(module-graph/validate-inputs inputs)
10481048
(let [deque (LinkedBlockingDeque. inputs)
10491049
input-set (atom (into #{} (comp (remove nil?) (map :ns)) inputs))
1050-
cnt (+ 2 (.. Runtime getRuntime availableProcessors))
1050+
cnt (+ 2 (int (* 0.6 (.. Runtime getRuntime availableProcessors))))
10511051
latch (CountDownLatch. cnt)
10521052
es (Executors/newFixedThreadPool cnt)
10531053
compiled (atom [])

Diff for: src/main/clojure/cljs/compiler.cljc

+11-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
[cljs.source-map :as sm]))
3232
#?(:clj (:import java.lang.StringBuilder
3333
[java.io File Writer]
34+
[java.util.concurrent Executors ExecutorService TimeUnit]
3435
[java.util.concurrent.atomic AtomicLong]
3536
[cljs.tagged_literals JSValue])
3637
:cljs (:import [goog.string StringBuffer])))
@@ -1508,7 +1509,12 @@
15081509
find-ns-starts-with (memoize find-ns-starts-with)]
15091510
(emitln (compiled-by-string opts))
15101511
(with-open [rdr (io/reader src)]
1511-
(let [env (ana/empty-env)]
1512+
(let [env (ana/empty-env)
1513+
emitter (when (:parallel-build opts)
1514+
(Executors/newSingleThreadExecutor))
1515+
emit (if emitter
1516+
#(.execute emitter ^Runnable (bound-fn [] (emit %)))
1517+
emit)]
15121518
(loop [forms (ana/forms-seq* rdr (util/path src))
15131519
ns-name nil
15141520
deps nil]
@@ -1543,7 +1549,10 @@
15431549
:name ns-name}))
15441550
(emit ast)
15451551
(recur (rest forms) ns-name deps))))
1546-
(let [sm-data (when *source-map-data* (assoc @*source-map-data*
1552+
(let [_ (when emitter
1553+
(.shutdown emitter)
1554+
(.awaitTermination emitter 1000 TimeUnit/HOURS))
1555+
sm-data (when *source-map-data* (assoc @*source-map-data*
15471556
:gen-col (.get ^AtomicLong *source-map-data-gen-col*)))
15481557
ret (merge
15491558
{:ns (or ns-name 'cljs.user)

0 commit comments

Comments
 (0)