Reducible sequence generators

Description

Have iterate, cycle, and repeat return custom types that are directly reducible.

Background and inspiration are and http://insideclojure.org/2015/01/18/reducible-generators/

While (satisfies? IReduce (iterate inc 0)) returns true this is via LazySeq, as opposed to, for example (satisfies? IReduce (range)) which involves a custom type.

One motivation would be the ability to transduce over large generated collections without consuming memory (which otherwise occurs due to lack of locals clearing).

For example, the following uses very little memory:

where this semantically equivalent form consumes gigabytes:

It is expected that, to implement this ticket, three new types would be introduced, akin to the existing Range class, porting as much as possible from the existing types implemented in Clojure for iterate, cycle, and repeat.

Environment

None

Attachments

2

Activity

Show:

Mike Fikes December 22, 2017 at 2:23 PM

Note that, CLJS-2445.patch additionally includes changes that were made in Clojure shortly after CLJ-1603.

In particular, the laziness and realized? changes

Mike Fikes December 22, 2017 at 1:46 PM

The revisions in aim to faithfully port CLJ-1603, including the perf-related revisions to nthrest and doall.

Benchmarks are attached in benchmarks.txt. In summary, you can see that things are much improved across engines, apart from Nashorn, which regresses.

Not included in the tests is the ability to avoid locals clearing that this patch affords. You can see this manually by evaluating forms like these in a REPL and observing memory and CPU perf:

Completed

Details

Assignee

Reporter

Approval

Patch

Affects versions

Priority

Created December 18, 2017 at 3:35 PM
Updated December 22, 2017 at 4:56 PM
Resolved December 22, 2017 at 4:56 PM