Skip to content

Instantly share code, notes, and snippets.

@mfikes
Last active December 22, 2017 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/f775e56c2566e8ac6c7f159badb2c95d to your computer and use it in GitHub Desktop.
Save mfikes/f775e56c2566e8ac6c7f159badb2c95d to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment