You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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. I am wondering if we could avoid referencing Schedulers.trampoline() in that specific use case of ObservableRefCount to keep the dependency clear.
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.
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.
The text was updated successfully, but these errors were encountered:
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 iftimeout
is 0, it won't be triggered at all because there is early return. I am wondering if we could avoid referencingSchedulers.trampoline()
in that specific use case ofObservableRefCount
to keep the dependency clear.RxJava/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java
Lines 48 to 50 in 4a78cfc
RxJava/src/main/java/io/reactivex/internal/operators/observable/ObservableRefCount.java
Lines 92 to 112 in 4a78cfc
The reasons 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.The text was updated successfully, but these errors were encountered: