reactor-core icon indicating copy to clipboard operation
reactor-core copied to clipboard

MonoSubscriber.discard Performance issues ?

Open zhou-hao opened this issue 3 years ago • 5 comments

image image

do not call Operators.onDiscard when the v is null ?

zhou-hao avatar Oct 11 '22 03:10 zhou-hao

probably it can be onDiscard optimization since now it is

Consumer<Object> hook = context.getOrDefault(Hooks.KEY_ON_DISCARD, null);
		if (element != null && hook != null) {
			try {
				hook.accept(element);
			}
			catch (Throwable t) {
				log.warn("Error in discard hook", t);
			}
		}

but could be

		if (element != null) {
		     Consumer<Object> hook = context.getOrDefault(Hooks.KEY_ON_DISCARD, null);
             if (hook != null) {
   			   try {
				  hook.accept(element);
			   }
			   catch (Throwable t) {
				  log.warn("Error in discard hook", t);
			  }
		   }	   
		}

OlegDokuka avatar Oct 11 '22 06:10 OlegDokuka

emmm, I think actual.currentContext() is the cause of the problem ?

zhou-hao avatar Oct 11 '22 07:10 zhou-hao

@zhou-hao that call is inevitable but we can avoid it if we check for null. Alternatively we can cache context within every operator

OlegDokuka avatar Oct 11 '22 09:10 OlegDokuka

the method Operators.MonoSubscriber#discard should check for null ?

protected void discard(@Nullable O v) {
	Operators.onDiscard(v, actual.currentContext());
}

zhou-hao avatar Oct 11 '22 09:10 zhou-hao

This issue is a bit dated. I wonder if we should come back to it. @zhou-hao are you still interested in this issue? If so, a reproducible example with a pipeline where this is a problem could serve as a basis for diagnosing and aiming for a better result. Are you able to provide something? Thanks in advance.

chemicL avatar Mar 18 '24 12:03 chemicL