当前 {{clojure.core/distinct}} 的实现使用了持久集合。这个补丁通过使用动态集合将惰性参数的性能提高了约 25%-30%,并提高了约 40%-50% 的 transducer。
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