Two performance enhancements on clojure.set/map-invert:
1) Use reduce-kv to avoid realizing mapentry's from input map
2) Use transients to create the output map
*Perf:*
(use 'criterium.core)
(require '[clojure.set :as set])
(def m1 (zipmap (range 1) (range 1)))
(def m10 (zipmap (range 10) (range 10)))
(def m100 (zipmap (range 100) (range 100)))
(def m1000 (zipmap (range 1000) (range 1000)))
(quick-bench (set/map-invert m1000))
(quick-bench (set/map-invert m100))
(quick-bench (set/map-invert m10))
(quick-bench (set/map-invert m1))
;; means before: 138 ns 1.8 µs 20.6 µs 304 µs
;; means after: 151 ns 1.3 µs 9.0 µs 126 µs
*Patch:* clj-1808-map-invert-should-use-reduce-kv-and-transient.patch
*Screened by:* Alex Miller