This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-07
Channels
- # beginners (73)
- # boot (20)
- # chestnut (8)
- # cider (36)
- # clara (37)
- # cljs-dev (21)
- # cljs-experience (1)
- # cljsrn (2)
- # clojure (163)
- # clojure-austin (3)
- # clojure-dusseldorf (6)
- # clojure-finland (1)
- # clojure-ireland (4)
- # clojure-italy (45)
- # clojure-russia (9)
- # clojure-spec (47)
- # clojure-uk (20)
- # clojurescript (107)
- # cursive (24)
- # data-science (4)
- # datomic (4)
- # defnpodcast (1)
- # fulcro (1)
- # heroku (3)
- # jobs-discuss (4)
- # juxt (52)
- # lein-figwheel (1)
- # leiningen (4)
- # lumo (37)
- # midje (5)
- # off-topic (16)
- # onyx (15)
- # portkey (11)
- # re-frame (112)
- # reagent (12)
- # rum (1)
- # specter (35)
- # uncomplicate (6)
Would compiling recursive paths give any benefit? I've tried a compiled-transform
with comp-paths
for the above path vector and don't see any performance benefits (using criterium to get means)
@dadair no that's not necessary anymore
since 0.11.0 specter does inline compilation/caching
feel free to paste your path if you'd like tips on performance
it's the exact path you provided in the code block above. It's improved my app performance quite substantially already, I was just curious of compilation would make it faster as I know the path beforehand
yea that path's performance could be improved
or rather that transform
(def terminal2
(richnav [afn]
(select* [this vals structure next-fn]
(i/throw-illegal "'terminal2' should only be used in multi-transform"))
(transform* [this vals structure next-fn]
(afn vals structure))))
(multi-transform [(putval :root) :root nodes-with-path :ref (terminal2 (fn [vals _] vals))] data)
try that
avoids the apply
on the transform-fn and the butlast
call
I should probably add something like that into a future version
that's a variant of terminal
which is in specter
yeah that improved it quite a bit again: prewalk: 27ms, transform: 5.4ms, multi-transform: 1.3ms
very nice
that's probably close to optimal
I've also replaced a tree-seq > group-by > get
pipeline with:
(def nodes-without-path
(sp/recursive-path [] p
(sp/continue-then-stay
(sp/must :children)
sp/ALL
sp/LAST
p)))
(defn find-vals [root type]
(sp/select [:root nodes-without-path (fn [x] (= type (-> x :descriptor :type)))] root))
any performance tips there?no, that seems good
also, when the predicate matches, that node will be a leaf, if that adds some performance considerations
oh, you can replace ALL LAST
with MAP-VALS
that will be a big performance boost
as for the last property you said, you should be able to change the path to reflect that
basically to only navigate to leaves, not to every intermediate node
depends on how you detect a leaf
non-existence of :children
key, or just :children
key with empty map?
I was going to say :children
with empty map but that's not necessarily true actually, it's more that certain nodes have types
(-> node :descriptor :type)
that reflect leaf "value" nodes, but internally they may have :children
for sub-values
it would look like:
(def leaf-nodes
(recursive-path [] p
(if-path leaf-node?
STAY
[:children MAP-VALS p]
)))
just fill in leaf-node?