functionaljava icon indicating copy to clipboard operation
functionaljava copied to clipboard

Improve Stream efficency

Open jbgi opened this issue 10 years ago • 8 comments

Stream is rather slow, we should probably switch to an implementation based on a fold algebra with fusion whenever possible.

jbgi avatar Sep 08 '15 19:09 jbgi

https://www.cs.ox.ac.uk/ralf.hinze/publications/IFL10.pdf looks like a good read on the subject. also https://github.com/scala/slip/pull/17/ may be of interest.

jbgi avatar Sep 08 '15 19:09 jbgi

Does anyone have a good benchmark for Streams? Stream fusion looks very much like coroutines, but I'm guessing there is more to it.

clinuxrulz avatar Feb 01 '16 09:02 clinuxrulz

A easy first step to improve perf would be to implement this change: https://github.com/scalaz/scalaz/pull/1104

jbgi avatar Feb 15 '16 16:02 jbgi

food for thought: http://jyp.github.io/posts/controlled-fusion.html

jbgi avatar Mar 10 '16 20:03 jbgi

initial experiment show good results based on Mu/Nu lists from above. If no objection I will try to put something together. @clinuxrulz did you work on a design for stream fusion?

jbgi avatar Mar 13 '16 20:03 jbgi

No. I've been too busy at work unfortunately. I have nothing to contribute, you go ahead with your implementation.

clinuxrulz avatar Mar 13 '16 22:03 clinuxrulz

I haven't worked out how to do stream fusion in Java yet.

However I've got an implementation based on a stackless Coroutine with re-associated binds that emits values.

which is more or less like this in haskell

data StepF a next
  = Emit a next
  | Bind (forall b r. (Stream b -> (b -> Stream a) -> r) -> r)

newtype Stream2 a = Stream2 (Free (StepF a) Unit)

Heres the code:

https://github.com/clinuxrulz/functionaljava/blob/stream/core/src/main/java/fj/data/Stream2.java

I just need benchmarks to see if I've helped or hindered the situation.

clinuxrulz avatar Apr 03 '16 07:04 clinuxrulz

I think quite some work was done in RxJava2 on operator fusion, it might be interesting to whoever takes on this issue. https://www.google.bg/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=rxjava%20operator%20fusion

dimitarg avatar Jan 09 '17 13:01 dimitarg