Skip to content

1.x: enable operator/source fusion by named operator lifter #3506

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

Closed
wants to merge 1 commit into from

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Nov 9, 2015

This change factors out the body of lift() into a named class that gives access to the operator and source parameters. By using this information, other operators can perform what I call operator macro-fusion.

One such example with this PR is the repeated use of the operator mergeWith which when done in the classical way creates a long linked-list of sources merged in pairs, often leading to stack overflows
and degraded performance. However, if mergeWith can see that it is applied to an existing mergeWith, the two operators can use a common list of sources and then turn into a one-level merge() with n + 1
sources (the previous graph will then be GC'd). Don't worry, this doesn't destroy the original assembled sequence. For example, given c = a.mergeWith(b); d = c.mergeWith(e); both c and d can be freely subscribed to and still do the same thing.

Note also that this PR conflicts with PR #3477 since the array-based merge(from(os)) has a different type.

I didn't officially benchmarked this due to the stackoverflow with head. Given the 10002 values merged in the unit test in 34ms (i7 4790, Windows 7 x64, Java 8u66) which yields ~294 kOps/s.

This change factors out the body of lift() into a named class that gives
access to the operator and source parameters. By using this information,
other operators can perform what I call **operator macro-fusion**.

One such example with this PR is the repeated use of the operator
`mergeWith` which when done in the classical way creates a long
linked-list of sources merged in pairs, often leading to stack overflows
and degraded performance. However, if `mergeWith` can see that it is
applied to an existing mergeWith, the two operators can use a common
list of sources and then turn into a one-level merge() with n + 1
sources (the previous graph will then be GC'd). Don't worry, this
doesn't destroy the original assembled sequence. For example, given `c =
a.mergeWith(b); d = c.mergeWith(e);` both c and d can be freely
subscribed to and still do the same thing.

Note also that this PR conflicts with PR ReactiveX#3477 since the array-based
`merge(from(os))` has a different type.
@akarnokd akarnokd added this to the 1.0.x milestone Nov 9, 2015
@akarnokd akarnokd closed this Feb 8, 2016
@akarnokd akarnokd deleted the OnSubscribeLift branch June 28, 2016 09:45
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.

1 participant