With this ClojureScript release, the results of iterate
, repeat
and cycle
are now directly reducible. This brings some great work that Alex Miller did for Clojure a few years ago to ClojureScript. This means that you will get much better performance when reducing over the output of these functions.
Take, for example, a benchmark involving running (transduce (take 64) + (iterate inc 0))
a total of 10,000 times when compiled with :advanced
optimizations. You can try this benchmark on your machine, but we are seeing this run 4.5 times faster under V8 and SpiderMonkey, and 3.3 times faster on JavaScriptCore.
In addition, this provides a way to process large output without involving intermediate sequence generation, thus bypassing the lack of locals-clearing and inevitable head-holding that occurs in CloureScript. This means you can now run programs like
(transduce (comp (map inc) (filter odd?) (take 1e8)) + (iterate inc 0))
and they will consume very little memory. This example completes in around 10 seconds in the Node REPL, using just a few megabytes of RAM, whereas previously it would essentially never terminate, consuming gigabytes of RAM.