对 clojure.set/map-invert 的两个性能改进
1) 使用 reduce-kv 来避免从输入映射中实例化 mapentry
2) 使用 transients 来创建输出映射
*性能:*
(使用 'criterium.core)
("require" '[clojure.set :as set])
("def" m1 (zipmap (范围 1) (范围 1)))
("def" m10 (zipmap (范围 10) (范围 10)))
("def" m100 (zipmap (范围 100) (范围 100)))
("def" m1000 (zipmap (范围 1000) (范围 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))
;; 意味着之前: 138 ns 1.8 µs 20.6 µs 304 µs
;; 意味着之后: 151 ns 1.3 µs 9.0 µs 126 µs
*补丁:* clj-1808-map-invert-should-use-reduce-kv-and-transient.patch
*审核人:* Alex Miller