Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: dedicated reduce() op implementations #4885

Merged
merged 3 commits into from
Nov 28, 2016
Merged

Conversation

akarnokd
Copy link
Member

This PR adds dedicated operator implementations to

  • Flowable.reduce(seed, reducer) (returns Single),
  • Flowable.reduceWith(seedSupplier, reducer) (returns Single),
  • Observable.reduce(reducer) (returns Maybe),
  • Observable.reduce(seed, reducer) (returns Single) and
  • Observable.reduceWith(seedSupplier, reducer) (returns Single)

instead of using scan().takeLast(1) (Flowable.reduce(reducer) already had a dedicated operator).

Comparison (Celeron 1005M, 4GB RAM, Windows 7 x64, Java 8u112, JMH 1.16):

image

The new ReducePerf benchmark does a simple sum over a list of integer values. Unfortunately, this creates a lot of garbage for longer sequences (plus the CPU/RAM is not really suited for such benchmarks; the flowMaybe lines should be roughly the same since the code didn't change but there is a significant run-to-run variance).

@akarnokd akarnokd added this to the 2.0 backlog milestone Nov 26, 2016
@codecov-io
Copy link

codecov-io commented Nov 26, 2016

Current coverage is 95.58% (diff: 83.13%)

Merging #4885 into 2.x will decrease coverage by 0.13%

@@                2.x      #4885   diff @@
==========================================
  Files           581        586     +5   
  Lines         37212      37373   +161   
  Methods           0          0          
  Messages          0          0          
  Branches       5601       5616    +15   
==========================================
+ Hits          35619      35722   +103   
- Misses          654        683    +29   
- Partials        939        968    +29   

Powered by Codecov. Last update baa00f7...78ed0b4

this.actual = actual;
this.value = value;
this.reducer = reducer;
this.value = value;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2x this.value = value? L64 & L66.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixing...

RxJavaPlugins.onError(e);
return;
}
value = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs done=true


@Override
public void onComplete() {
T v = value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the real problem here is you don't have those done related unit tests that I said I'd provide! I'll have a look at them soon.


@Override
public void onNext(T value) {
R v = this.value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done checks in this class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for separate done flag as this.value can't be initially null and becomes null if onError is called. Updated the PR with more checks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

@davidmoten
Copy link
Collaborator

👍 with the qualifier that I'm not up on RxJava2/ReactiveStreams lifecycle in terms of subscription and disposal yet (that's for another day sorry!).

@akarnokd akarnokd merged commit f294938 into ReactiveX:2.x Nov 28, 2016
@akarnokd akarnokd deleted the ReducePerf branch November 28, 2016 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants