Fork me on GitHub
#specter
<
2017-09-05
>
dadair21:09:16

How does Spectre compare in performance for recursively (and exhaustively) walking large trees (e.g., against clojure.walk/prewalk)? Looked at posted benchmarks but didn't see any for walking trees

nathanmarz22:09:32

@dadair specter destroys the performance of anything in vanilla clojure for anything involving compound or recursive data structures

nathanmarz22:09:59

clojure.walk is a very brute force approach forcing you to traverse parts of data structures you don't care about (like map keys, key/value pairs)

nathanmarz22:09:29

with specter you can make traversals that perform dramatically better

nathanmarz22:09:53

even just in replicating clojure.walk/postwalk semantics specter is 40% better

Benchmark: walker vs. clojure.walk version (150000 iterations)

Avg(ms)		vs best		Code
959.39 		 1.00 		 (transform (walker number?) inc data)
1347.1 		 1.40 		 (transform (walker-old number?) inc data)

nathanmarz22:09:17

the implementation of walker is instructive for making your own recursive paths

(def
  ^{:doc "Navigate the data structure until reaching
          a value for which `afn` returns truthy. Has
          same semantics as clojure.walk."}
  walker
  (recursive-path [afn] p
    (cond-path (pred afn) STAY
               coll? [ALL p]
               )))

dadair22:09:37

awesome, I'll take a look at spectre. I have a prewalk running in ~28ms that I need to cut down as much as possible