-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Remove dependency of Schedulers from ObservableRefCount #6452
Merged
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
In the constructor of `ObservableRefCount` that takes `ConnectableObservable<T> source` as the argument, we set `timeout` to `0L`. In that specific use case of `ObservableRefCount`, `scheduler` is never needed. It's only referenced in `cancel()` 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 on `Schedulers.trampoline()` and instead passes null to be scheduler when the ref count is not time-based. The reasons for this change are the following: 1. In projects that don't depend on `Schedulers` class, if there is no reference to `Schedulers`, the whole `Schedulers` can be stripped out of the library after optimizations (e.g., proguard). With constructor that references `Schedulers`, 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 to `Schedulers` in `ObservableRefCount`. 2. In terms of modularity, `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 some `Scheduler` that could be passed to `ObservableRefCount` when `ObservableRefCount` needs it.
Codecov Report
@@ Coverage Diff @@
## 2.x #6452 +/- ##
============================================
+ Coverage 98.27% 98.31% +0.03%
- Complexity 6296 6298 +2
============================================
Files 675 675
Lines 45173 45173
Branches 6246 6246
============================================
+ Hits 44393 44410 +17
+ Misses 241 238 -3
+ Partials 539 525 -14
Continue to review full report at Codecov.
|
akarnokd
approved these changes
Apr 3, 2019
Thanks for the review and the approval! |
davidmoten
approved these changes
Apr 4, 2019
vanniktech
approved these changes
Apr 4, 2019
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.
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.