Skip to content

Commit d38e001

Browse files
author
dnolen
committed
two microoptimizations
1 parent 81a1ea1 commit d38e001

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@
16001600
(every? constant-value? (ast-children ast)))))
16011601

16021602
(defn const-expr->constant-value [{:keys [op] :as e}]
1603-
(case op
1603+
(case op
16041604
:quote (const-expr->constant-value (:expr e))
16051605
:const (:val e)
16061606
:map (zipmap (map const-expr->constant-value (:keys e))
@@ -1926,7 +1926,7 @@
19261926
{:protocol-impl proto-impl
19271927
:protocol-inline proto-inline})
19281928
methods (map #(disallowing-ns* (analyze-fn-method menv locals % type (nil? name))) meths)
1929-
mfa (apply max (map :fixed-arity methods))
1929+
mfa (transduce (map :fixed-arity) max 0 methods)
19301930
variadic (boolean (some :variadic? methods))
19311931
locals (if named-fn?
19321932
(update-in locals [name] assoc

src/main/clojure/cljs/compiler.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@
205205
#?(:clj (map? x) :cljs (ana/cljs-map? x)) (emit x)
206206
#?(:clj (seq? x) :cljs (ana/cljs-seq? x)) (apply emits x)
207207
#?(:clj (fn? x) :cljs ^boolean (goog/isFunction x)) (x)
208-
:else (let [s (print-str x)]
208+
:else (let [s (cond-> x
209+
(not (string? x)) print-str)]
209210
(when-not (nil? *source-map-data*)
210211
(swap! *source-map-data*
211212
update-in [:gen-col] #(+ % (count s))))

src/test/clojure/cljs/profile.clj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(ns cljs.profile
2+
(:require [clojure.java.io :as io]
3+
[cljs.env :as env]
4+
[cljs.analyzer :as ana]
5+
[cljs.compiler :as comp]))
6+
7+
(comment
8+
9+
;; ~900ms
10+
(dotimes [_ 20]
11+
(time (ana/analyze-file (io/resource "cljs/core.cljs"))))
12+
13+
;; ~2700ms
14+
;; after change ~2500
15+
(dotimes [_ 20]
16+
(time
17+
(env/with-compiler-env (env/default-compiler-env)
18+
(comp/compile-file (.getPath (io/resource "cljs/core.cljs")))
19+
(.delete (io/file "src/main/cljs/cljs/core.js")))))
20+
21+
)

0 commit comments

Comments
 (0)