metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

Improve map gen construction and usage performance #949

Closed bsless closed 10 months ago

bsless commented 10 months ago

Round 2 :) See detailed commit message Benchmark results:

(require '[malli.generator :as mg])

(dotimes [_ 10]
  (time
   (dotimes [_ 1e5]
     (mg/generator [:map [:a :int] [:b :int]]))))

"Elapsed time: 377.558951 msecs" ;; before
"Elapsed time: 359.188257 msecs" ;; after

(def g (mg/generator [:map [:a :int] [:b :int]]))

(dotimes [_ 10]
  (time
   (dotimes [_ 1e5]
     (mg/generate g))))

"Elapsed time: 511.243682 msecs" ;; before
"Elapsed time: 370.793034 msecs" ;; after
ikitommi commented 10 months ago

code looks much cleaner, thanks!

bsless commented 10 months ago

Cheers I still wonder if generation could be faster Three options:

But I'm pretty happy with how much I've been able to trim this down, too

bsless commented 10 months ago

For the record, this brings the malli example to (only?) 2x slower than the pure gen composition https://github.com/bsless/fsm-test-check/blob/master/examples/add_delete_tx_malli.clj