Fork me on GitHub
#helix
<
2021-06-26
>
dominicm08:06:24

@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 🙂

dominicm09:06:55

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 🙂

lilactown16:06:31

please, open a PR! I'll take a look for sure

lilactown16:06:41

before this gets lost in the slack void 😂