Skip to content

Eager ConcatMap #3357

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

Merged
merged 1 commit into from
Oct 8, 2015
Merged

Eager ConcatMap #3357

merged 1 commit into from
Oct 8, 2015

Conversation

akarnokd
Copy link
Member

Related discussion in #3017.

@davidmoten
Copy link
Collaborator

Thanks a lot for contributing this one @akarnokd. I've had one look through and no problems jump out at me but I will review further. This will be useful.

drain();
}

void drain() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For readability I'd suggest longer names for variables like d, a, r, e, p.

@akarnokd akarnokd force-pushed the EagerConcatMap branch 2 times, most recently from 2d88119 to 51eb7a8 Compare September 24, 2015 07:02
@akarnokd
Copy link
Member Author

Thanks for the review @davidmoten . Usually I use one letter variables because I find it easier to parse the code and instead of long variable names, I use newlines to separate logical blocks. This way, I don't have to type that many letters and I don't have to wait while Eclipse returns with the content assist (which is blocking by the way and may take hundreds of milliseconds, even on my i7 + SSD).

I took the time and renamed variables as you asked for and added some more unit tests that check the code paths. That being said, I don't plan to do such renames in my contributions very often in the future and encourage anybody to post their PRs with their proposed cleanups/renames.

* @return
*/
@SuppressWarnings("unchecked")
public static <T> Observable<T> eagerConcatMap(

Choose a reason for hiding this comment

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

Should we name these eagerConcat instead of eagerConcatMap? These overloads do not take a FuncN so they aren't really mapping.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto that @stealthcode and for discoverability call it concatEager?

@akarnokd
Copy link
Member Author

Thanks for the feedback. I've updated the method names to concatMapEager and concatEager, added the @Experimental tags, some javadoc and a missing test for a 2-parameter concatEager overload.

@akarnokd
Copy link
Member Author

Updated with a capacity fix for the SpscLinkedArrayQueue.

@stevegury
Copy link
Member

I reviewed in details in the code and I believe it is correct.

But I wonder if subscribing to the sources in a "unbounded mode" is the right thing to do.
At the expense of complexifying the code, I believe it could be possible to split the request(n) between the sources. Maybe requesting 1 to all the m sources expect the first one, which we request n - m + 1 ... and so on.

The devil is in the details, and I believe this would significantly complexify the code, but I would like to know what you are thinking about this?

@akarnokd
Copy link
Member Author

@stevegury This operator consumes source observables in order and doesn't make sense to split any request from downstream. If the downstream requests n and the first is requested n / count, that would hang the sequence because only the first is allowed to emit and it won't emit enough to trigger a new request.

It is possible to use a bounded buffer per source so while they are not consumed, they don't grow indefinitely. However, it means that each of them can produce only RxRingBuffer.SIZE elements before stopping and thus the operator wouldn't be eager anymore.

@stevegury
Copy link
Member

@akarnokd sorry I wasn't very clear but what I proposed was roughly what you described (replacing RxRingBuffer.SIZE by 1).

My main concern here is the use of unbounded buffer, which, I think, could be avoided.

@akarnokd
Copy link
Member Author

@davidmoten What do you think about the bounded buffering and the fact that such sources would act more like a delayed source?

@davidmoten
Copy link
Collaborator

I'd be happy to see bounded buffering (RxRingBuffer.SIZE sounds a better default size than 1 to me and would be consistent with the request eagerness of other operators like merge for instance). Could we add an overload to allow the specification of buffer size as well?

If this is significant rework I'm content to see this unbounded version documented with its buffering characteristics merged and we can defer the bounding work to another PR.

@akarnokd
Copy link
Member Author

akarnokd commented Oct 3, 2015

Done.

@davidmoten
Copy link
Collaborator

Great, thanks @akarnokd ! Lightning quick as always.

@stevegury
Copy link
Member

LGTM 👍

@abersnaze
Copy link
Contributor

The three of you seem happy with it so I'm merging it.

abersnaze added a commit that referenced this pull request Oct 8, 2015
@abersnaze abersnaze merged commit 125b10d into ReactiveX:1.x Oct 8, 2015
@akarnokd akarnokd deleted the EagerConcatMap branch October 8, 2015 13:20
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.

5 participants