Tricky, we can NOT:
var fxy = gen_dispatcher(fxy)
var fxy.IFn ....
Since otherwise we loose (to be tested) GCC's DCE.
Thoug this should work:
(defn create-multi-arity-fn
[]
(fn dispatcher []
#js[(.-cljs$lang$maxFixedArity dispatcher)
(.-cljs$lang$fixedArities dispatcher)]))
(def foo (create-multi-arity-fn))
(set! foo -cljs$lang$maxFixedArity 2)
(set! foo -cljs$lang$fixedArities #js[0 2])
(foo)
Need to check DCE...
(defn set-arg-len [f]
(set! js/yyyyyyy (.. f -cljs$core$IFn$_invoke$arity$variadic -length)))
(defn set-mfa [f]
(set! js/xxxxxx (.. f -cljs$lang$maxFixedArity)))
(let [sims 4000000
fns #js[map comp some-fn str partial vary-meta not= disj! conj assoc assoc!]
len (alength fns)]
(dotimes [_ 3]
(simple-benchmark []
(set-arg-len (aget fns (rand-int len))) sims)
(simple-benchmark []
(set-mfa (aget fns (rand-int len))) sims)))
Slower in Chrome by like 2x :(
Optimize for inline caches - avoid hidden classes
We could maybe get the same object layout and achieve much higher performance if we set "a few" IFn
to nil
on the dispatcher. To be tested!