merge
is implemented as
(defn merge
;; stuff removed
[& maps]
(when (some identity maps)
(reduce1 #(conj (or %1 {}) %2) maps)))
This is somewhat suboptimal from a couple of reasons. reduce1
is slower than reduce
(might not matter when the number of maps is small, but perhaps more importantly, in the case where you just want to merge two maps, it does a lot of unnecessary work, since merging two maps is basically
(when (or m1 m2) (conj (or m1 {}) m2))
Would it be reasonable to have a multi arity version of merge
which optimized for this case?
A quick benchmark shows a potential for a 4 times speed up in this case.
I've looked through Jira, but surprisingly, I wasn't able to find a ticket for this?