Skip to content

Evaluate instanceof overhead related to internal typing #3309

@OlegDokuka

Description

@OlegDokuka

Motivation - Wide internal type-system

instanceof overhead

At the current moment inside the Project Reactor we have a design flaw caused by too broad internal typing causing significant overhead during the construction:

  • assembly time and related Fuseable, Callable, and other type checks (mostly related to Macro-optimizations e.g zipWith, then, similar mutation-related operations) which cause an overhead if the type check fails (a reference benchmark of type check via instanceof vs bitwise check for characteristics).
  • subscription time does check for instance type (instanceof Conditional vs Normal) + in fuseable operators does check for QueueSubscrtiption type (with extra requestFusion overhead)

Code Duplicatio

as the result of having wide internal types we are mandated to support identical code for separate implementations (e.g. MapSubscriber vs MapConditionalSubscriber vs MapFuseableSubscriber vs MapFuseableSubscriber)

Context Propagation

TBD

Resource Lifecycle

TBD

Solution

To solve the problem we need to have a generic, unified internal Subscriber type which can resolve all the problems:

public interface InternalCoreSubscriber<T> extends CoreSubscriber<T> {

    @Override
    default void onSubscribe(Subscription s) {

    }

    @Override
    default void onNext(T value) {
        onNext(value, Context.empty());
    }

    long onSubscribe(CoreSubscription cs, int supportedFusionMode);

    long onNext(T value, ContextView context);

    void onComplete();

    void onError();

    /**
     * Handles upstream resource termination. Must be called by upstream after their 
     * emission of onComplete/onError or upon reception of cancel signals. 
     * 
     * Intermediate operators MUSt delegate the call of this method to its upstream source
     */
    void onClosed();
}

interface CoreSubscription extends Subscription {
    @Nullable
    <T> Queue<T> requestFusion(int fusion);
}

Alternatives

#3310

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions