Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup, Entry parser protocol, worker caches and fast inferring #550

Merged
merged 25 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions perf/malli/perf/creation_perf_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
;; 3.0µs (map childs)
;; 3.2µs (mapv childs)
;; 2.5µs (...)
;; 2.1µs (non-distinct)
;; 1.4µs (-vmap)
(p/bench (m/validate [:or :int :string] 42))
(p/profile (m/validate [:or :int :string] 42))

;; 15ns
(let [schema (m/schema [:or :int :string])]
(p/bench (m/validate schema 42)))

;; 3.0µs
;; 500ns (delayed mapv childs)
Expand All @@ -27,7 +32,6 @@
;; 1.1µs (mapv childs)
;; 750ns (...)
(p/bench (m/schema [:or :int :string]))
(p/profile (m/schema [:or :int :string]))

;; 1.7µs
;; 470ns (map childs)
Expand All @@ -37,18 +41,20 @@
;; 1.1µs (mapv childs)
;; 750ns (...)
(p/bench (m/schema [:and :int :string]))
(p/profile (m/schema [:and :int :string]))

;; 1.7µs
;; 1.5µs (fast parse)
;; 13ns (-cache)
(let [schema (m/schema [:or :int :string])]
(p/bench (m/validator schema))
#_(p/profile (m/validator schema)))
(p/bench (m/validator schema)))

;; 4ns
;; 16ns
(let [schema (m/schema [:or :int :string])]
(p/bench (m/validate schema 42)))

;; 3ns
(let [validate (m/validator [:or :int :string])]
(p/bench (validate 42))
#_(p/profile (validate 42))))
(p/bench (validate 42))))

(def ?schema
[:map
Expand All @@ -70,28 +76,28 @@

;; 480ns -> 400ns -> 340ns -> 280ns -> 240ns -> 170ns (registry) -> 160ns (recur)
(p/bench (m/schema :int))
(p/profile (m/schema :int))

;; 44µs -> 31µs -> 18µs -> 11µs -> 9.4µs -> 9.0µs -> 8.5µs -> 7.0µs -> 6.4µs (registry) -> 5.7µs -> 3.4µs
;; 44µs -> 31µs -> 18µs -> 11µs -> 9.4µs -> 9.0µs -> 8.5µs -> 7.0µs -> 6.4µs (registry) -> 5.7µs
;; 3.4µs
;; 2.9µs (-entry-parser)
(p/bench (m/schema ?schema))
(p/profile (m/schema ?schema))

;; 240ns
(p/bench (m/schema ?schema {::m/lazy-entries true}))

;; does not work with direct linking
(with-redefs [m/-check-children? (constantly false)]
(p/bench (m/schema ?schema))
(p/profile (m/schema ?schema))))
(p/bench (m/schema ?schema))))

(def ref-schema (m/schema [:schema :int]))

(comment

;; 14ns -> 5ns
(p/bench (m/deref ref-schema))
(p/profile (m/deref ref-schema))

;; 5µs -> 28ns
(p/bench (m/deref-all ref-schema))
(p/profile (m/deref-all ref-schema)))
(p/bench (m/deref-all ref-schema)))

(comment

Expand All @@ -101,14 +107,13 @@

;; 271ns
;; 14ns (-set-children, -set-properties)
;; 12ns (-entry-parser)
(p/bench (m/walk leaf-schema (m/schema-walker identity)))
(p/profile (m/walk leaf-schema (m/schema-walker identity)))

;; 26µs
;; 1.3µs (-set-children, -set-properties)
;; 1.2µs (protocols, registry, recur)
(p/bench (m/walk schema (m/schema-walker identity)))
(p/profile (m/walk schema (m/schema-walker identity)))

;; 51µs
;; 44µs (-set-children, -set-properties)
Expand All @@ -119,26 +124,25 @@
;; 6.5µs (schema)
;; 5.8µs (protocols, registry, recur, parsed)
;; 3.9µs (-parsed)
;; 3.6µs (-entry-parser)
(p/bench (mu/closed-schema schema))
(p/profile (mu/closed-schema schema))

;; 3.8µs
;; 3.4µs (satisfies?)
;; 2.2µs (-set-entries)
;; 830ns (-update-parsed)
;; 560ns (-entry-parser)
(p/bench (mu/assoc schema :y :string))
(p/profile (mu/assoc schema :y :string))

;; 4.2µs
;; 3.8µs (satisfies?)
;; 820ns (-update-parsed)
;; 580ns (-entry-parser)
(p/bench (mu/assoc schema :w :string))
(p/profile (mu/assoc schema :w :string))

;; 205ns
;; 195ns
(p/bench (mu/get schema :y))
(p/profile (mu/get schema :y))

;; 13µs
;; 2.4µs (satisfies?)
Expand All @@ -162,8 +166,7 @@
;; 341ns (-create-form)
;; 150ns (delayed form)
;; 30ns (don't -check-children)
(p/bench (m/-val-schema s nil))
(p/profile (m/-val-schema s nil))))
(p/bench (m/-val-schema s nil))))

(comment
"clojurescript perf tests"
Expand Down
Loading