-
Notifications
You must be signed in to change notification settings - Fork 126
Optimizations
Roman Liutikov edited this page Jul 15, 2020
·
3 revisions
NOTE: This optimization is enabled by default since v0.11.5
The following is very advanced, so don't do this unless you're very familiar with rum:
When you have many components (and especially if you target mobile) you may notice that creating the components (ie, the browser evaluating those defc
's and calling rum.core/build-class
can take some time). Though, you don't need those component spec's initialized right away unless you actually use that component. The solutions is to write your own defc
or constructor and initialize the component lazily:
(defn component
[spec]
(let [c (delay (create-component spec))]
(fn [& args]
(apply @c args))))
This can improve startup time (for me by 400ms on mobile, for ~100 components).
Further avoiding the (costly) apply
and variable argument function:
;; [goog.functions :as gf]
(let [c (gf/cacheReturnValue #(create-component spec))]
(fn []
(let [ctr (c)]
(.apply ctr ctr (js-arguments)))))