Fork me on GitHub

Analysis about Malli Schema creation performance:

👍 8
👀 10
Ben Sless08:08:33

woohoo, more performance

Ben Sless08:08:49

can you uplooad the raw svgs?


cleared them up already, sorry.

Ben Sless08:08:32

no biggy, I can repro

Ben Sless08:08:07

Btw, regarding the memoization idea I floated

   (defn memoize!
     (doseq [v
       (alter-var-root v memoize))))

#?(:clj (defonce _memoized (memoize!)))
Is this sufficient?


unbounded cache? as Schemas don’t have custom equality defined, all instances are different. That would leak memory, a lot. But, interesting idea. Could use that in to swap top-level functions into version that pretty print exceptions.


Safe thing might be to put the cache into options, so the user can control it. For schema instances, could be bolted into a registry?


e.g. a registry that returns cached Schemas instead of IntoSchemas in cases it would benefit from caching, e.g. all immutable schmas like leaves without properties and children: :int could be cached, [:int {:title "wadawoksei, kuvavideo"}] is a bad candidate.

Ben Sless15:08:06

What is the largest number of schemas you've seen defined? I wonder if an unbounded cache will be good enough in most cases


infinite. sending [:re #".*"] over the wire will always result in a new schema. Regexs don’t implement equality.

(= #".*" #".*") ; => false

Ben Sless18:08:02

Would it be worth implementing equality semantics for schemas?


maybe, there is malli.util/equals already, but it doesn’t take into account the possible different local registry bindings.


I recall there is an issue about pushing the local schema binding into “full”-form…


I think any option could effect how the schema works, so the equality might be heavy to calculate, might be wrong.


btw, thanks again for you efforts on perf, really appreciate it 🙇

🙂 3
clojure-spin 3
Ben Sless18:08:39

I'm just having lots of fun with it

Ben Sless18:08:59

And it's all your fault for giving the perf talk at ClojureTRE 2019

👍 3
Ben Sless17:08:53

Is it possible to use regex schema to say something like "I don't know what these two consecutive elements are but they should be identical"?, i.e. [1 1 1] would be valid but [1 2 1] would not?


So all elements should be identical?