Skip to content

Instantly share code, notes, and snippets.

@ikitommi
Created January 23, 2022 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikitommi/fbb8bb7ffedcd43d923d62b8b362f946 to your computer and use it in GitHub Desktop.
Save ikitommi/fbb8bb7ffedcd43d923d62b8b362f946 to your computer and use it in GitHub Desktop.
Malli initialization speed

Create a new project:

~ mkdir demo
➜  ~ cd demo
➜  demo echo '{:deps {metosin/malli {:mvn/version "0.8.0-20220123.082237-3"}} :aliases {:dev {:extra-paths ["classes"]}}}' > deps.edn

Loading takes ages:

➜  demo clj -A:dev
Clojure 1.10.3
user=> (time (require '[malli.dev.pretty :as pretty]))
"Elapsed time: 6972.434167 msecs"
nil
user=>

Compiling malli stuff once one client-side:

➜  demo mkdir classes
➜  demo clj -A:dev -M -e "(binding [*compile-files* true] (require 'malli.dev))"
➜  demo clj -A:dev
Clojure 1.10.3
user=> (time (require '[malli.dev.pretty :as pretty]))
"Elapsed time: 487.331166 msecs"
nil

In action:

user=> (pretty/explain [:map [:age [:int {:min 18}]]] {:age 17})
-- Validation Error -------------------- NO_SOURCE_FILE:1 --

Value:

  {:age 17}

Errors:

  {:age ["should be at least 18"]}

Schema:

  [:map [:age [:int {:min 18}]]]

More information:

  https://cljdoc.org/d/metosin/malli/CURRENT

------------------------------------------------------------
{:schema [:map [:age [:int {:min 18}]]]
 :value {:age 17}
 :errors ({:path [:age]
           :in [:age]
           :schema [:int {:min 18}]
           :value 17
           :message "should be at least 18"})}
user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment