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

Conversation

ikitommi
Copy link
Member

@ikitommi ikitommi commented Oct 22, 2021

  • Cached protocol for effective caching of schema results
    • -form, -validator, -explainer, -parser, -unparser
  • BREAKING: EntrySchema replaces MapSchema
    • new -entry-parser method needs to be implemented
  • BREAKING: -parse-entries is removed, use -entry-parser instead
  • EntryParser, supporting lazy parsing
  • 30x faster inferring with mp/provider
  • BREAKING: malli.provider/schema is moved into extender API: malli.provider/-schema
(def schema
  (m/schema
   [:map
    [:x boolean?]
    [:y {:optional true} int?]
    [:z [:map
         [:x boolean?]
         [:y {:optional true} int?]]]]))

;; 1.5µs -> 11ns (130x)
(p/bench
 (m/validator schema)

;; 1.7µs -> 64ns (25x)
(p/bench
 (m/validate schema {:x true, :z {:x true}}))
  ;; 3.4µs -> 2.9µs (15%)
  (p/bench (m/schema ?schema))

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

alternative impl

  • store the cache into meta. more transparent, much slower - also, would introduce a hard-to-find performance trap as many conversion tools create schemas using internal functions, which do not initialize the cache. having a expicit protocol for Cache keeps the implementor in control of things, still yielding leverage (and perf) compared to fullu manual caching (using delays)

Schema Inferring

;; 3.6ms -> 2.2ms (1.7x)
(p/bench (mp/provide [1 2 3]))

;; 2.5ms -> 82µs (30x)
(let [provider (mp/provider)]
  (p/bench (provider [1 2 3])))

src/malli/core.cljc Outdated Show resolved Hide resolved
@ikitommi ikitommi marked this pull request as ready for review October 23, 2021 11:00
@ikitommi ikitommi changed the title Entry parser protocol & worker caches Entry parser protocol, worker caches and fast inferring Oct 23, 2021
@ikitommi ikitommi changed the title Entry parser protocol, worker caches and fast inferring Cleanup, Entry parser protocol, worker caches and fast inferring Oct 23, 2021
@ikitommi ikitommi merged commit 163839c into master Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants