-
Notifications
You must be signed in to change notification settings - Fork 210
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
Faster registry #517
Faster registry #517
Conversation
(def regs
{:nil nil
:map {}
:simple (mr/simple-registry {})
:composite (mr/composite-registry (mr/simple-registry {}))
:mutable (mr/mutable-registry (atom {}))})
(doseq [[name r] regs]
(let [mean (first (:mean (cc/quick-benchmark (mr/registry r) {})))
[scale unit] (cc/scale-time mean)]
(println name (* mean scale) unit)))
;;; Before
;; :nil 11.314252099384198 ns
;; :map 11.553363773721745 µs
;; :simple 5.894620337443649 ns
;; :composite 5.851375239599097 ns
;; :mutable 5.893465716928456 ns
;;; After
;; :nil 3.259309437187958 ns
;; :map 22.65670884744675 ns
;; :simple 3.267212075708806 ns
;; :composite 3.287585829320794 ns
;; :mutable 3.289205443217265 ns |
Also think I found a mistake in one of the tests |
thanks! |
(defn registry [?registry] | ||
(cond (satisfies? Registry ?registry) ?registry | ||
(map? ?registry) (simple-registry ?registry))) | ||
(defn registry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simplified this into:
(defn registry [?registry]
(cond (nil? ?registry) nil
#?@(:clj [(instance? malli.registry.Registry ?registry) ?registry])
(map? ?registry) (simple-registry ?registry)
(satisfies? Registry ?registry) ?registry))
instance?
-check works with reified classes? woot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do. I dug into why satisfies?
is fast for reified classes, and voila!
I also found that nil?
checks are slightly slower than raw if
Speed up registry creation and usage
Part of #513