Skip to content

Commit f0f57f6

Browse files
committed
Avoid the event bus delivery context machinery when the interceptor chain is empty.
Motivation: When the event-bus interceptor chain is empty we can skip the delivery context machinery that is not necessary as it involves creating garbage and atomics. This is possible due to a recent refactoring change. Changes: When the interceptor chain is obtained, bypass the delivery context machinery when the chain is empty.
1 parent 8ff222b commit f0f57f6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

vertx-core/src/main/java/io/vertx/core/eventbus/impl/HandlerRegistration.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package io.vertx.core.eventbus.impl;
1212

1313
import io.vertx.core.*;
14+
import io.vertx.core.eventbus.DeliveryContext;
1415
import io.vertx.core.eventbus.Message;
1516
import io.vertx.core.eventbus.ReplyException;
1617
import io.vertx.core.eventbus.ReplyFailure;
@@ -90,10 +91,15 @@ public Future<Void> unregister() {
9091
return promise.future();
9192
}
9293

93-
void dispatchMessage(Handler<Message<T>> theHandler, MessageImpl<?, T> message, ContextInternal context) {
94-
Runnable dispatch = () -> dispatch(context, message, theHandler);
95-
DeliveryContextImpl<T> deliveryCtx = new DeliveryContextImpl<>(message, message.bus.inboundInterceptors(), context, message.receivedBody, dispatch);
96-
deliveryCtx.next();
94+
void dispatchMessage(Handler<Message<T>> handler, MessageImpl<?, T> message, ContextInternal context) {
95+
Handler<DeliveryContext<?>>[] interceptors = message.bus.inboundInterceptors();
96+
if (interceptors.length > 0) {
97+
Runnable dispatch = () -> dispatch(context, message, handler);
98+
DeliveryContextImpl<T> deliveryCtx = new DeliveryContextImpl<>(message, interceptors, context, message.receivedBody, dispatch);
99+
deliveryCtx.next();
100+
} else {
101+
dispatch(context, message, handler);
102+
}
97103
}
98104

99105
private void dispatch(ContextInternal ctx, MessageImpl<?, T> message, Handler<Message<T>> handler) {

vertx-core/src/main/java/io/vertx/core/eventbus/impl/SendContext.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ public class SendContext<T> implements Promise<Void> {
4646
this.writePromise = ctx.promise();
4747
}
4848

49-
public void send() {
49+
void send() {
5050
Handler<DeliveryContext<?>>[] interceptors = message.bus.outboundInterceptors();
51-
DeliveryContextImpl<T> deliveryContext = new DeliveryContextImpl<>(message, interceptors, ctx, message.sentBody, this::execute);
52-
deliveryContext.next();
51+
if (interceptors.length > 0) {
52+
DeliveryContextImpl<T> deliveryContext = new DeliveryContextImpl<>(message, interceptors, ctx, message.sentBody, this::sendOrPub);
53+
deliveryContext.next();
54+
} else {
55+
sendOrPub();
56+
}
5357
}
5458

5559
@Override
@@ -109,7 +113,7 @@ private void written(Throwable failure) {
109113
}
110114
}
111115

112-
protected void execute() {
116+
private void sendOrPub() {
113117
VertxTracer tracer = ctx.tracer();
114118
if (tracer != null) {
115119
if (message.trace == null) {

0 commit comments

Comments
 (0)