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

1.x: optimize concatMapIterable/flatMapIterable #3864

Merged
merged 2 commits into from
May 3, 2016

Conversation

akarnokd
Copy link
Member

This PR reduces the overhead of concatMapIterable/flatMapIterable by not wrapping them into Observable.from sources but handling the generated Iterables directly.

Since Iterables are inherently synchronous, there is no difference between the two operators that now use the common underlying operator (i.e., flatMap can't chose a different source because it can't tell if an Iterable source is not ready or not; hasNext() is for indicating completion, not temporary lack of data).

Benchmark (i7 4790, Window 7 x64, Java 8u77):

image

Iterable-M is the current master, Plain is using concatMap(Observable::from) as a reference.

The count=1 cases are bit slower because there is no good way of detecting if an Iterable holds only a single element, unlike with just(), and have to instantiate the full infrastructure even for a single element.

The same table using the master as baseline:

image

BackpressureUtils.getAndAddRequest(requested, n);
drain();
} else
if (n < 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you move the if on the same line as the else, it makes me uncomfortable to see a line ending with else

@stevegury
Copy link
Member

Other that my previous comment, 👍.

@akarnokd akarnokd merged commit f2ed079 into ReactiveX:1.x May 3, 2016
@akarnokd akarnokd deleted the FlattenIterable1x branch May 3, 2016 20:18
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.

2 participants