Improve clojure.core/distinct perf by using transient set

Description

Current implementation of clojure.core/distinct uses persistent set. This patch improves performance of lazy arity by ~25%-30% and transducer by ~40%-50% by using transient set instead.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 10 elements (doall (distinct coll)) 5.773439 µs => 4.179092 µs (-27%) (into [] (distinct) coll) 3.238236 µs => 1.943254 µs (-39%) 100 elements (doall (distinct coll)) 67.725764 µs => 42.129993 µs (-37%) (into [] (distinct) coll) 35.702741 µs => 16.495947 µs (-53%) 1000 elements (doall (distinct coll)) 540.652739 µs => 399.053873 µs (-26%) (into [] (distinct) coll) 301.423077 µs => 164.025500 µs (-45%) 10000 elements (doall (distinct coll)) 3.439137 ms => 3.058872 ms (-11%) (into [] (distinct) coll) 1.437390 ms => 848.277178 µs (-40%)

Benchmarking code: https://gist.github.com/tonsky/97dfe1f9c48eccafc983a49c7042fb21

Environment

None

Status

Assignee

Unassigned

Reporter

Nikita Prokopov

Approval

Triaged

Patch

Code

Priority

Major
Configure