I’ve started switching out Spec for Malli to improve performance in hot code. it works great except when using recursive schemas. I’ve created a gist to illustrate https://gist.github.com/stevebuik/e4f3475e46dd5ebb1de7707438fa073f
anyone seen this before? Or am I making a mistake somehow?
@steveb8n you are using :and
, which composes the two maps - in validation it runs two validations, one for each map. If you use malli.util/merge
, the end result is one schema, and validation runs it just once. tested the first example, it’s 90ns vs 97ns, which is the cost of iterating over 2 MapEntrys instead of just one.
(require '[malli.util :as mu])
(def simple-tree-node
(mu/merge
simple-node
[:map {:registry {::child simple-node}}
[:children {:optional true} [:vector [:ref ::child]]]]))
one note about merge: both the properties and children are merged (no deep merge atm), so the last :registry
property wins. hadn’t thought of that :thinking_face:
but, here, it’s:
simple-tree-node
;[:map
; {:registry #:recursive-malli-perf{:child [:map [:name string?]]}}
; [:name string?]
; [:children {:optional true} [:vector [:ref :recursive-malli-perf/child]]]]
Now that's a Xmas gift! I'll try it tomorrow. Thanks