Remove dependency of Schedulers from ObservableRefCount #6452
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.
Resolves #6451.
In the constructor of
ObservableRefCount
that takesConnectableObservable<T> source
as the argument, we settimeout
to0L
. In that specific use case ofObservableRefCount
,scheduler
is never needed. It's only referenced incancel()
method but if timeout is 0, it won't be triggered at all because there is early return. This commit removes the need to depend onSchedulers.trampoline()
and instead passes null to be scheduler when the ref count is not time-based. Similarly, applies the same change toFlowableRefCount
.The reasons for this change are the following:
Schedulers
class, if there is no reference toSchedulers
, the wholeSchedulers
can be stripped out of the library after optimizations (e.g., proguard). With constructor that referencesSchedulers
, the optimizer can't properly strip it out. In our quick test of our Android app, we were able to reduce the RxJava library size dependency from 51KB to 37KB (after optimization but before compression) by simply avoiding access toSchedulers
inObservableRefCount
.ObservableRefCount
is just an operator so it by itself should probably not have dependency on what available pool of schedulers (Schedulers
) there are. It should just know that there is someScheduler
that could be passed toObservableRefCount
whenObservableRefCount
needs it.