memoize sqlable?
In simple benchmarks, calls to sql/format spend the majority of their time in satisfies. Make the simple cases simpler with caching.
This commit is contained in:
parent
0c3f3d0403
commit
f8127e3aac
1 changed files with 10 additions and 2 deletions
|
|
@ -260,11 +260,19 @@
|
||||||
nil
|
nil
|
||||||
(-to-sql [x] "NULL"))
|
(-to-sql [x] "NULL"))
|
||||||
|
|
||||||
|
(def class-cache (atom nil))
|
||||||
|
|
||||||
(defn sqlable? [x]
|
(defn sqlable? [x]
|
||||||
(satisfies? ToSql x))
|
(let [c (class x)
|
||||||
|
cache @class-cache]
|
||||||
|
(if (contains? cache c)
|
||||||
|
(cache c)
|
||||||
|
(let [result (satisfies? ToSql x)]
|
||||||
|
(swap! class-cache assoc c result)
|
||||||
|
result))))
|
||||||
|
|
||||||
(defn to-sql [x]
|
(defn to-sql [x]
|
||||||
(if (satisfies? ToSql x)
|
(if (sqlable? x)
|
||||||
(-to-sql x)
|
(-to-sql x)
|
||||||
(let [[x pname] (if (instance? SqlParam x)
|
(let [[x pname] (if (instance? SqlParam x)
|
||||||
(let [pname (param-name x)]
|
(let [pname (param-name x)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue