当前{{clojure.core/distinct}}的实现使用持久集合。此补丁通过使用transient集合改善懒惰语法的性能约25%-30%,以及化简器(TRANSUCER)性能约40%-50%。
10个元素
(doall (distinct coll)) 与 5.773439 µs比较 => 4.179092 µs (-27%)
(into [] (distinct) coll) 与 3.238236 µs比较 => 1.943254 µs (-39%)
100个元素
(doall (distinct coll)) 与 67.725764 µs比较 => 42.129993 µs (-37%)
(into [] (distinct) coll) 与 35.702741 µs比较 => 16.495947 µs (-53%)
1000个元素
(doall (distinct coll)) 与 540.652739 µs比较 => 399.053873 µs (-26%)
(into [] (distinct) coll) 与 301.423077 µs比较 => 164.025500 µs (-45%)
10000个元素
(doall (distinct coll)) 与 3.439137 ms比较 => 3.058872 ms (-11%)
(into [] (distinct) coll) 与 1.437390 ms比较 => 848.277178 µs (-40%)
基准测试代码:
https://gist.github.com/tonsky/97dfe1f9c48eccafc983a49c7042fb21