Description
The current architecture of 1.x uses lift
and Operator
to implement most operators instead of create
and OnSubscribe
. This requires an extra object allocation when operators are assembled and could be amplified if those operators are part of the inner input to flatMap
for example.
Due to public API compatibility, we can't change the base types to facilitate direct extensions (unlike 2.x) but the operators can be trivially rewritten to all extend their respective OnSubscribe
interfaces.
The second inefficiency is around Single
: the design wanted to reuse Observable
operators at the cost of serveral entry- and exit type conversion which all involve allocating wrapper objects.
My main proposition is as follows:
- change all
Observable
operators to beOnSubscribe
- trivial changes - replace all
Single
operators with factored out versions, implementingSingle.OnSubscribe
- introduces aroun 50 new classes
My secondary proposition is that since Single
is @Beta
and Completable
is @Experimental
, I believe their architecture could be changed before they are promoted to final so that their operators extend the base type instead of implementing some OnSubscribe
, saving an additional allocation.
From API use perspective, they would remain the same. However, the change is definitely binary-incompatible. I'm up for feedback if such change is acceptable on such non-release types.