This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-26
Channels
- # announcements (6)
- # aws (5)
- # beginners (42)
- # cider (24)
- # clojure (81)
- # clojure-canada (1)
- # clojure-europe (122)
- # clojured (5)
- # cursive (6)
- # data-science (5)
- # datahike (9)
- # emacs (6)
- # events (2)
- # fulcro (12)
- # helix (4)
- # honeysql (1)
- # jobs-discuss (1)
- # lsp (28)
- # mid-cities-meetup (1)
- # off-topic (31)
- # polylith (13)
- # shadow-cljs (22)
- # spacemacs (8)
- # tools-deps (33)
- # vim (10)
@lilactown I'm not sure if you're interested in making the analyser more sophisticated (to ignore quoted forms, allowing the simpler key I hinted at before) but this is also 3x faster in my testing:
(defn find-hooks3
[body]
(let [f (fn f [matches form]
(if (and (seqable? form)
(not
(and
(list? form)
(= 'quote (first form)))))
(cond-> (reduce
(fn [acc x]
(f acc x))
matches
form)
(hook-expr? form)
(conj form))
matches))]
(f
[]
body)))
I benchmarked with:
(c/quick-bench
(find-hooks3
'((let [foo {:bar 10
:baz (use-state 10)}
bish (quote (use-state 20))
bash '(use-state 60)]
(use-state 50))))
)
Largely it's from reducing allocations by avoiding the postwalk, but the approach gives the required control over descent to avoid the issues with quoted forms & the hooks detection. Faster compile times are always nice 🙂The slowest part of the defnc macro is by far the invalid hooks usage checking. (~50µs of the 105µs). I think it would benefit from a similar change (at a guess).
EDIT: I have a 61µs->14µs change which works slightly differently. Instead of the innermost :state
it uses the outermost state. Mostly for convenience tbh 🙂