-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refactor: Reduce memory consumption and simplify inner and outer subscription #5610
Merged
benlesh
merged 4 commits into
ReactiveX:master
from
benlesh:refactor/reduce-memory-pressure
Jul 30, 2020
Merged
refactor: Reduce memory consumption and simplify inner and outer subscription #5610
benlesh
merged 4 commits into
ReactiveX:master
from
benlesh:refactor/reduce-memory-pressure
Jul 30, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Reduces memory pressure by no longer capturing outer values where they are not needed. For example, every inner subscription in mergeMap was retaining the outer value, if the outer value was a large array, that could add up - Makes subscribeToResult less ridiculous, I am not sure what I was thinking there - Leaves a few operators with more complex inner subscriptions, to be refactored later. - Removes some redundant code that removed inner subscriptions manually, this was necessary in the early days of RxJS 5, but has not been necessary in a long time
benlesh
force-pushed
the
refactor/reduce-memory-pressure
branch
from
July 30, 2020 02:19
d115113
to
242e87c
Compare
benlesh
changed the title
refactor: simplify inner and outer subscription
refactor: Reduce memory consumption and simplify inner and outer subscription
Jul 30, 2020
cartant
reviewed
Jul 30, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, opinions and nits.
niklas-wortmann
approved these changes
Jul 30, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
benlesh
added a commit
to benlesh/rxjs
that referenced
this pull request
Jul 30, 2020
this is the duplicate of ReactiveX#5610, it is refactoring to ensure outer values are not retained when they do not have to be. It needs to be done in a separate PR because the branches diverge just enough to require it. This PR also has some mild, internal type fixes.
benlesh
added a commit
that referenced
this pull request
Jul 31, 2020
this is the duplicate of #5610, it is refactoring to ensure outer values are not retained when they do not have to be. It needs to be done in a separate PR because the branches diverge just enough to require it. This PR also has some mild, internal type fixes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explainer
So the old
OuterSubscription
is now calledComplexOuterSubscription
, andInnerSubscription
isComplexInnerSubscription
.Basically, back when we had all sorts of additional "resultSelectors" (pre v6), those result selectors relied on data that we captured with the
InnerSubscription
. After removing resultSelectors, that was no longer needed in the majority of cases, BUT it was still there to keep this "one inner subscription process to rule them all" sort of thing we had going.Unfortunately, those trapped outer values can be costly. Imagine this scenario:
In the above scenario, the subscription to
of(data)
, as a source begins and ends synchronously. BUT!!! even though we don't even use that huge array in the inner observable we return in themergeMap
, that array is retained in theInnerSubscriber
'souterValue
property, which is created by the merge map... and held, in this case, for 1,000 seconds! Not great.This PR solves that by no longer retaining the
outerValue
unless necessary.There's a long tail of one-offs that we'll need to address. But they are commented on the
ComplexOuterSubscriber
implementation and its methods.