This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-02
Channels
- # announcements (9)
- # asami (5)
- # babashka (16)
- # beginners (134)
- # chlorine-clover (3)
- # cider (15)
- # clojure (75)
- # clojure-australia (3)
- # clojure-europe (29)
- # clojure-nl (2)
- # clojure-uk (15)
- # clojured (4)
- # clojurescript (34)
- # cursive (9)
- # datomic (16)
- # duct (7)
- # events (4)
- # fulcro (2)
- # helix (5)
- # honeysql (4)
- # jobs (9)
- # lsp (55)
- # malli (31)
- # music (3)
- # re-frame (3)
- # reitit (1)
- # remote-jobs (1)
- # ring (3)
- # sci (5)
- # shadow-cljs (46)
- # specter (3)
- # tools-deps (60)
- # vim (5)
- # xtdb (15)
How do I provide sci options in malli decode? Trying to use java class with no luck.
(m/decode [:int {:decode/string '(fn [_] (.toEpochMilli (java.time.Instant/now)))}]
"whatever"
{:classes {'java.time.Instant java.time.Instant}}
mt/string-transformer)
looking at the code, it’s :malli.core/sci-options
key in options, see https://github.com/metosin/malli/blob/master/src/malli/core.cljc#L1792-L1813
tried this
(m/decode [:int {:decode/string '(fn [_] (.toEpochMilli (java.time.Instant/now)))}]
"whatever"
(merge
(m/-default-sci-options)
{:malli.core/sci-options {:classes {'java.time.Instant java.time.Instant}}})
mt/string-transformer)
but can’t see it in https://github.com/metosin/malli/blob/eea10aa8c668a16f88d9fc66fce0616a7f9137b4/src/malli/sci.cljc#L10
@ben.sless merged the loop unrolling perf PR, great for common cases and as it’s just clj, doesn’t make the cljs bundle size any bigger, big thanks!
;; 164ns -> 36ns
(let [valid? (m/validator [:and [:> 0] [:> 1] [:> 2] [:> 3] [:> 4]])]
(cc/quick-bench (valid? 5)))
merged the other perf PR too:
;; 150ns -> 39ns
(let [valid? (m/validator [:map [:a :any] [:b :any] [:c :any] [:d :any] [:e :any]])
value {:a 1, :b 2, :c 3, :d 4, :e 5}]
(cc/with-progress-reporting
(cc/quick-bench (valid? value))))
@U055NJ5CC I've created https://github.com/metosin/malli/issues/472 with a test case which demonstrates the issue.
@U026F3GM8NA I profiled you example, it looks like CPU mostly goes towards parsing the schema. If you wrap every def-ed schema with a schema constructor it seems to be way more efficient, would you mind trying?
D'you mean just wrapping it in a function which returns the structure? (I'm not sure what you mean by "schema constructor")
like so;
(def A1
(m/schema
[:map
{:encode/test {:leave encode} :decode/test decode}
[:type [:= "A1"]]
[:value float?]
]))
thanks, I'll try
thank you
yeah, that's pretty much instant now, I'll try it on our production code
Perfect. Thanks Ben! What shall I do with the github issue? Do I close it, or are you planning on making changes to parsing?
I closed the issue, no plans on making the parser faster or caching at the moment. Thanks for @ben.sless for digging into this 🙇
I think it is worth to leave a comment on the issue and perhaps a note in the readme regarding references to uncompiled schemas
And you're welcome 🙂
Turns out I was completely wrong regarding the transformers and satisfies?
I see you left a comment with a link to the gist, so that would leave only the readme
@ben.sless, great work. Saw the thread on Clojureverse about compiler optimizations. Would be great if things got automatically or magically faster. While waiting, writing performant code inside the libraries (on the hot perf path) is just being smart.