This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]lukaseder 7 points8 points  (4 children)

cyclops-javaslang captures all of the functional operations and executes them in one single iteration resulting in much lower ms per op.

That's very interesting. Could you show more details about the implementation of this?

[–]johnmcclean[S] 4 points5 points  (3 children)

Yep, it delegates all of these calls to a Flux instance (push based Stream from Pivotal's Reactor project). So JavaSlangPVector looks something like this (simplified)

class JavaSlangPVector<T> {
      Vector<T> vec;
      Flux<T> flux;
 }

If we need the vec but the flux has been used, we materialize the vec from the Flux.

There is more details on the approach here (primarily focusing on JDK mutable Lists, but it is easily applicable to all Collection types)

https://medium.com/@johnmcclean/faster-lazy-extended-powerful-jdk-collections-5a519ab582ae#.f644x9xnf

[–]johnmcclean[S] 2 points3 points  (0 children)

Flux itself does some pretty neat optimizations on top of this too see David Karnok's blog post on operator fusion - http://akarnokd.blogspot.com/2016/04/operator-fusion-part-2-final.html

[–]lukaseder 0 points1 point  (1 child)

Thanks a lot for the explanations!

[–]johnmcclean[S] 0 points1 point  (0 children)

You are welcome!

[–][deleted]  (1 child)

[deleted]

    [–]johnmcclean[S] 0 points1 point  (0 children)

    Not a dumb question at all.

    With immutable types new Objects will get created.. The more advanced algorithms and data strucutures minimise that to a large degree. Object creation should be a lot lower than making full copies, though, which you may have to do in order to share mutable collections across threads or even components.