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

Lazier Monos: act on first request rather than onSubscribe #2913

Closed
1 task
simonbasle opened this issue Feb 3, 2022 · 0 comments · Fixed by #3081
Closed
1 task

Lazier Monos: act on first request rather than onSubscribe #2913

simonbasle opened this issue Feb 3, 2022 · 0 comments · Fixed by #3081
Labels
type/enhancement A general enhancement warn/behavior-change Breaking change of publicly advertised behavior wide-change
Milestone

Comments

@simonbasle
Copy link
Member

simonbasle commented Feb 3, 2022

Most Monos currently consider that onSubscribe equates request.
They're still lazy, in the sense that not subscribing to a Mono doesn't trigger its processing, but not always exactly adhering to backpressure when no initial request is made downstream.

This issue turns vanilla core Monos into truly lazy ones by moving processing from onSubscribe to first request.

Some particular Mono operators might need to retain their current behavior, in which case they should be listed below:

  • ...
@simonbasle simonbasle added type/enhancement A general enhancement wide-change warn/behavior-change Breaking change of publicly advertised behavior labels Feb 3, 2022
@simonbasle simonbasle added this to the 3.5.0 planning milestone Feb 3, 2022
@simonbasle simonbasle modified the milestones: 3.5.0 planning, 3.5.0-M2 Mar 31, 2022
@simonbasle simonbasle modified the milestones: 3.5.0-M2, 3.5.0-M3 Apr 15, 2022
@violetagg violetagg modified the milestones: 3.5.0-M3, 3.5.0-M4 Jun 21, 2022
@simonbasle simonbasle modified the milestones: 3.5.0-M4, 3.5.0-M5 Jul 7, 2022
@simonbasle simonbasle linked a pull request Aug 3, 2022 that will close this issue
OlegDokuka added a commit that referenced this issue Aug 3, 2022
This commit changes 4 broad categories of Mono operators to be lazier
and only start requesting from their upstream once they've been
themselves requested.

Previously, the request to upstream would happen immediately upon
receiving the Subscription (in `onSubscribe`).

The first category of Monos is the one where the upstream is a Flux
that gets aggregated into a Mono, such as `MonoCollectList`, `MonoCount`
but also `MonoAll` or `MonoElementAt`...
These Mono now all inherit a common `BaseFluxToMonoOperator` which track
two states as bits in a single volatile: request status (true/false) and
completed status (true/false). It uses a non-volatile boolean hasRequest
as a shortcut to ignore any request past the first one.

Note that for now these implementations do declare a `Fuseable` trait,
but they always negotiate fusion `NONE`. It is kept as a future possible
improvement that they would all support SYNC fusion.

The second category is Monos that combine multiple sources, like
`MonoZip` or `MonoWhen`.
A single volatile long-based state machine is used to coordinate the
multiple inners and track which inner has made the first request.

The third category is ParallelFlux-to-Mono operators, mixing the above
two aspects: aggregating values and combining multiple sources (rails).
Some of these can benefit from the `BaseFluxToMonoOperator` approach.

The last category is sources like `MonoSupplier` or `MonoCallable`.
Often the functional interface representing the logic would be run in
`onSubscribe` directly, but making it lazier implies the creation of
dedicated `Subscription` implementations now.

Fixes #2913.

Signed-off-by: Oleh Dokuka <odokuka@vmware.com>
Co-authored-by: Simon Baslé <sbasle@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A general enhancement warn/behavior-change Breaking change of publicly advertised behavior wide-change
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants