Closed
Description
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.
The reasons are the following:
- In projects that don't depend on
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
. - 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 someScheduler
that could be passed toObservableRefCount
whenObservableRefCount
needs it.