helix

https://github.com/Lokeh/helix
dominicm 2021-06-26T08:37:24.146800Z

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

dominicm 2021-06-26T09:03:55.147700Z

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 🙂

lilactown 2021-06-26T16:42:31.148100Z

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

lilactown 2021-06-26T16:42:41.148400Z

before this gets lost in the slack void 😂