bsless / clj-fast

Unpredictably faster Clojure
Eclipse Public License 2.0
234 stars 1 forks source link

faster mapv and others (reference) using iterators #20

Open joinr opened 3 years ago

joinr commented 3 years ago

https://hackernoon.com/faster-clojure-reduce-57a104448ea4

via andre rauh

bsless commented 3 years ago

Interesting. I wonder if it could be generalized to reduce?

joinr commented 3 years ago

You can, and it's basically what the CollReduce protocol ends up doing (there's an iter-reduce function that reduces over iterators). I haven't thought through any limitations as of yet (I think seqs implement iterable, so it should be general enough while specializing nicely if the collection provides a fast iterator). It's kind of like the bypass for reduce-kv on maps that provides a faster reduction path than using plain reduce.