Skip to content

Conversation

@philomates
Copy link
Collaborator

looking for some performance wins for in-any-order (see #106)

With memoization I'm seeing a 2x speed up for code like this:

(require '[matcher-combinators.standalone :refer [match]])

(defn rand-set [size]
  (into #{} (repeatedly size #(rand-int Integer/MAX_VALUE))))

(time
 (run!
  (fn [_]
    (match
      (set [(rand-set 8) (rand-set 8) (rand-set 8)])
      (set [(rand-set 8) (rand-set 8) (rand-set 8)])))
  (range 5)))

but then a 2x slowdown for code like this:

 (run! (fn [i]
        (println (str "set size: " i))
        (time
         (run!
          (fn [_] (match (rand-set (inc i)) (rand-set i)))
          (range 5))))
      (range 9))

I think this is because in the first case, the nesting of sets means that the duplication of match calls compounds, so memoization helps a lot. In the second case, the flatness of the sets being matched means that duplicate match calls don't cause a cascade of nested match calls. In this case the memoization overhead of storing and looking up args probably bits us.

I think I'll continue to look into this but see if I can pass state around in the code to reduce duplicate invocations to match instead of using memoization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants