Fork me on GitHub
#malli
<
2023-06-15
>
fabrao15:06:51

Hello all, if you have a nested schema, are you able to access the nested keys from the parent?

ikitommi15:06:39

yes, there are utilities for this in malli.util, e.g. get, get-in , …

fabrao17:06:13

So, how the :fn of [:and [:....][:fn ...][:fn ...][:fn ...]] runs? In sequence?

escherize18:06:03

Well, let’s see:

(m/validate [:and keyword?
             [:fn (fn [_] (println 1) true)]
             [:fn (fn [_] (println 2) true)]
             [:fn (fn [_] (println 3) true)]
             [:fn (fn [_] (println 4) true)]]
            :k)
;; =stout=>
;; 1
;; 2
;; 3
;; 4
;; => true

fabrao03:06:06

Sorry, I mean serialized? Is it can be run in parallel / thread?

souenzzo21:06:39

yes, serialized why do you think it would be better to run in parallel?

fabrao15:06:05

well, performance?

souenzzo15:06:48

Does Parallel have more performance than serialized? Imagine the situation: You have a schema with 10 and elements Your app receives 10 requests, that your http server will process inside a thread pool of 10. Each request calls the validation. If it was parallelized, you will have 100 parallel threads at this point. It may cause performance issues in your 8 cores machine. Now imagine that inside the and, it usually fails in the 2-3 element. All left 7-8 functions will be evaluated, as they are all spawned at the same time

fabrao15:06:42

hummm, that's a good point, thank you for your scenario vision

souenzzo15:06:25

Maybe in your scenario it makes sense to have it parallelized, but it is not a generic "better" thing Do benchmarks, have metrics, before move into this approach. If that is the case, I think that a good start point is copy (defn -and-schema ... from malli.core into your code and define your :custom.parallel/and schema.

souenzzo15:06:53

My problematic scenario can be "solved" by using a thread pool for validation, then you will have a constant number of threads (http thread pool size + validation thread pool size).

fabrao15:06:51

"My problematic scenario can be "solved" by using a thread pool for validation" that I was thinking to have

👍 2
souenzzo15:06:09

It is doable inside :your-custom/and