Fork me on GitHub
#malli
<
2021-08-17
>
ikitommi06:08:03

Analysis about Malli Schema creation performance: https://github.com/metosin/malli/issues/513

👍 8
👀 10
Ben Sless08:08:33

woohoo, more performance

Ben Sless08:08:49

can you uplooad the raw svgs?

ikitommi08:08:37

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

#?(:clj
   (defn memoize!
     []
     (doseq [v
             [#'-validator
              #'-explainer
              #'-parser
              #'-unparser
              #'-transformer
              #'-walk
              #'-into-schema
              #'-safe-pred]]
       (alter-var-root v memoize))))

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

ikitommi14:08:21

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 malli.dev to swap top-level functions into version that pretty print exceptions.

ikitommi14:08:04

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?

ikitommi14:08:55

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

ikitommi17:08:10

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?

ikitommi18:08:03

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

ikitommi18:08:43

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

ikitommi18:08:50

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

ikitommi18:08:11

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?

lsenjov23:08:26

So all elements should be identical?