Skip to content

Commit 181e1d6

Browse files
committed
Use transducers in ioc-macros where applicable for performance
1 parent 68d2186 commit 181e1d6

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Distributed under the Eclipse Public License, the same as Clojure.
6363

6464
## Changelog
6565

66+
* next
67+
* Perf improvements in go macro compilation
6668
* Release 1.5.648 on 2021.12.14
6769
* Update dep for tools.analyzer.jvm to 1.2.2
6870
* Release 1.5.644 on 2021.12.06

src/main/clojure/cljs/core/async/impl/ioc_macros.clj

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -861,17 +861,17 @@
861861

862862
(defn count-persistent-values
863863
[index]
864-
(->> (keys index)
865-
(filter instruction?)
866-
(filter (partial persistent-value? index))
867-
count))
864+
(transduce
865+
(comp (filter instruction?) (filter (partial persistent-value? index)))
866+
(completing (fn [acc _] (inc acc))) 0 (keys index)))
868867

869868
(defn- build-block-preamble [local-map idx state-sym blk]
870-
(let [args (->> (mapcat reads-from blk)
871-
(filter instruction?)
872-
(filter (partial persistent-value? idx))
873-
set
874-
vec)]
869+
(let [args (into [] (comp
870+
(mapcat reads-from)
871+
(filter instruction?)
872+
(filter (partial persistent-value? idx))
873+
(distinct))
874+
blk)]
875875
(if (empty? args)
876876
[]
877877
(mapcat (fn [sym]
@@ -884,12 +884,12 @@
884884
(butlast blk)))
885885

886886
(defn- build-new-state [local-map idx state-sym blk]
887-
(let [results (->> blk
888-
(mapcat writes-to)
889-
(filter instruction?)
890-
(filter (partial persistent-value? idx))
891-
set
892-
vec)
887+
(let [results (into [] (comp
888+
(mapcat writes-to)
889+
(filter instruction?)
890+
(filter (partial persistent-value? idx))
891+
(distinct))
892+
blk)
893893
results (interleave (map (partial id-for-inst local-map) results) results)]
894894
(if-not (empty? results)
895895
`(aset-all! ~state-sym ~@results)

src/main/clojure/clojure/core/async/impl/ioc_macros.clj

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,16 @@
234234
IEmittableInstruction
235235
(emit-instruction [this state-sym]
236236
(if (not-empty (reads-from this))
237-
`[~@(->> (-> ast :env :locals vals)
238-
(map #(select-keys % [:op :name :form]))
239-
(filter (fn [local]
240-
(contains? locals (:name local))))
241-
set
242-
(mapcat
237+
`[~@(into []
238+
(comp
239+
(map #(select-keys % [:op :name :form]))
240+
(filter (fn [local]
241+
(contains? locals (:name local))))
242+
(distinct)
243+
(mapcat
243244
(fn [local]
244-
`[~(:form local) ~(get locals (:name local))])))
245+
`[~(:form local) ~(get locals (:name local))])))
246+
(-> ast :env :locals vals))
245247
~(:id this) ~(:form ast)]
246248
`[~(:id this) ~(:form ast)])))
247249

@@ -880,17 +882,17 @@
880882

881883
(defn count-persistent-values
882884
[index]
883-
(->> (keys index)
884-
(filter instruction?)
885-
(filter (partial persistent-value? index))
886-
count))
885+
(transduce
886+
(comp (filter instruction?) (filter (partial persistent-value? index)))
887+
(completing (fn [acc _] (inc acc))) 0 (keys index)))
887888

888889
(defn- build-block-preamble [local-map idx state-sym blk]
889-
(let [args (->> (mapcat reads-from blk)
890-
(filter instruction?)
891-
(filter (partial persistent-value? idx))
892-
set
893-
vec)]
890+
(let [args (into [] (comp
891+
(mapcat reads-from)
892+
(filter instruction?)
893+
(filter (partial persistent-value? idx))
894+
(distinct))
895+
blk)]
894896
(if (empty? args)
895897
[]
896898
(mapcat (fn [sym]
@@ -903,12 +905,12 @@
903905
(butlast blk)))
904906

905907
(defn- build-new-state [local-map idx state-sym blk]
906-
(let [results (->> blk
907-
(mapcat writes-to)
908-
(filter instruction?)
909-
(filter (partial persistent-value? idx))
910-
set
911-
vec)
908+
(let [results (into [] (comp
909+
(mapcat writes-to)
910+
(filter instruction?)
911+
(filter (partial persistent-value? idx))
912+
(distinct))
913+
blk)
912914
results (interleave (map (partial id-for-inst local-map) results) results)]
913915
(if-not (empty? results)
914916
[state-sym `(aset-all! ~state-sym ~@results)]

0 commit comments

Comments
 (0)