Skip to content

1.x: proposal for allocation reduction in the base types #4098

Closed
@akarnokd

Description

@akarnokd

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 be OnSubscribe - trivial changes
  • replace all Single operators with factored out versions, implementing Single.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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions