From 172f47ed9d24dccba4695b56105d56c27b83145e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Penttil=C3=A4?= Date: Fri, 23 Oct 2026 11:09:36 +0000 Subject: [PATCH] Speed up reflike? on the JVM Integrant calls reflike? on every value in a configuration, several times per init. On the JVM, satisfies? is slow for values that do not implement the protocol, which can be nearly all of them, so init time can grow noticeably with the size of the configuration. Check for the protocol interface instead, which the Ref and RefSet records implement. --- src/integrant/core.cljc | 4 +++- test/integrant/core_test.cljc | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/integrant/core.cljc b/src/integrant/core.cljc index d45dd3a..928964b 100644 --- a/src/integrant/core.cljc +++ b/src/integrant/core.cljc @@ -115,7 +115,9 @@ (defn reflike? "Return true if its argument is a ref or a refset." [x] - (satisfies? RefLike x)) + ;; satisfies? is slow on the JVM for values that do not implement the protocol + #?(:clj (instance? integrant.core.RefLike x) + :cljs (satisfies? RefLike x))) (defrecord Profile []) diff --git a/test/integrant/core_test.cljc b/test/integrant/core_test.cljc index dfdbe92..8a3be4b 100644 --- a/test/integrant/core_test.cljc +++ b/test/integrant/core_test.cljc @@ -88,6 +88,16 @@ (is (ig/reflike? (ig/refset ::foo))) (is (ig/reflike? (ig/refset [::foo ::bar])))) +(deftest reflike-test + (are [x] (not (ig/reflike? x)) + nil + ::foo + "foo" + {:key ::foo} + [(ig/ref ::foo)] + (ig/profile :dev 1) + (ig/var 'foo))) + (deftest composite-keyword-test (let [k (ig/composite-keyword [::a ::b])] (is (isa? k ::a))