This is an automated email from the ASF dual-hosted git repository. victory pushed a commit to branch 2.7.2-release in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.7.2-release by this push: new bfc6202 performance tuning: avoid reflection on the critical path (#4190) bfc6202 is described below commit bfc6202e0dac80e8cb073e1a30791c6c9139cdee Author: ken.lj <ken.lj...@gmail.com> AuthorDate: Wed May 29 10:38:25 2019 +0800 performance tuning: avoid reflection on the critical path (#4190) --- .../java/com/alibaba/dubbo/rpc/support/RpcUtils.java | 5 ----- .../src/main/java/org/apache/dubbo/rpc/Constants.java | 4 ---- .../main/java/org/apache/dubbo/rpc/RpcInvocation.java | 2 +- .../apache/dubbo/rpc/proxy/AbstractProxyInvoker.java | 6 +----- .../java/org/apache/dubbo/rpc/support/RpcUtils.java | 18 ++++++------------ .../apache/dubbo/rpc/protocol/dubbo/DubboCodec.java | 5 ++--- 6 files changed, 10 insertions(+), 30 deletions(-) diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java index d7db04f..378f14a 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/support/RpcUtils.java @@ -21,7 +21,6 @@ import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import java.lang.reflect.Type; -import java.util.Map; /** * 2019-04-18 @@ -76,8 +75,4 @@ public class RpcUtils extends org.apache.dubbo.rpc.support.RpcUtils { public static boolean isOneway(URL url, Invocation inv) { return org.apache.dubbo.rpc.support.RpcUtils.isOneway(url.getOriginalURL(), inv); } - - public static Map<String, String> getNecessaryAttachments(Invocation inv) { - return org.apache.dubbo.rpc.support.RpcUtils.getNecessaryAttachments(inv); - } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java index 5085887..f515960 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Constants.java @@ -84,10 +84,6 @@ public interface Constants { String ASYNC_KEY = "async"; - String FUTURE_GENERATED_KEY = "future_generated"; - - String FUTURE_RETURNTYPE_KEY = "future_returntype"; - String RETURN_KEY = "return"; String TOKEN_KEY = "token"; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index e422bef..ceb3c18 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -93,7 +93,7 @@ public class RpcInvocation implements Invocation, Serializable { } public RpcInvocation(Method method, Object[] arguments) { - this(method.getName(), method.getParameterTypes(), arguments, null, null); + this(method, arguments, null); } public RpcInvocation(Method method, Object[] arguments, Map<String, String> attachment) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java index fe42fb2..4008c44 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/AbstractProxyInvoker.java @@ -27,7 +27,6 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.CompletableFuture; @@ -112,10 +111,7 @@ public abstract class AbstractProxyInvoker<T> implements Invoker<T> { private CompletableFuture<Object> wrapWithFuture (Object value, Invocation invocation) { if (RpcContext.getContext().isAsyncStarted()) { return ((AsyncContextImpl)(RpcContext.getContext().getAsyncContext())).getInternalFuture(); - } else if (RpcUtils.isReturnTypeFuture(invocation)) { - if (value == null) { - return CompletableFuture.completedFuture(null); - } + } else if (value instanceof CompletableFuture) { return (CompletableFuture<Object>) value; } return CompletableFuture.completedFuture(value); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java index 955cb31..2d70a9e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/RpcUtils.java @@ -27,8 +27,6 @@ import org.apache.dubbo.rpc.RpcInvocation; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicLong; @@ -36,7 +34,6 @@ import static org.apache.dubbo.rpc.Constants.$INVOKE; import static org.apache.dubbo.rpc.Constants.$INVOKE_ASYNC; import static org.apache.dubbo.rpc.Constants.ASYNC_KEY; import static org.apache.dubbo.rpc.Constants.AUTO_ATTACH_INVOCATIONID_KEY; -import static org.apache.dubbo.rpc.Constants.FUTURE_GENERATED_KEY; import static org.apache.dubbo.rpc.Constants.ID_KEY; import static org.apache.dubbo.rpc.Constants.RETURN_KEY; /** @@ -171,7 +168,12 @@ public class RpcUtils { } public static boolean isReturnTypeFuture(Invocation inv) { - Class<?> clazz = getReturnType(inv); + Class<?> clazz; + if (inv instanceof RpcInvocation) { + clazz = ((RpcInvocation) inv).getReturnType(); + } else { + clazz = getReturnType(inv); + } return (clazz != null && CompletableFuture.class.isAssignableFrom(clazz)) || isGenericAsync(inv); } @@ -198,12 +200,4 @@ public class RpcUtils { } return isOneway; } - - public static Map<String, String> getNecessaryAttachments(Invocation inv) { - Map<String, String> attachments = new HashMap<>(inv.getAttachments()); - attachments.remove(ASYNC_KEY); - attachments.remove(FUTURE_GENERATED_KEY); - return attachments; - } - } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java index dd3e847..3b8fe66 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboCodec.java @@ -33,17 +33,16 @@ import org.apache.dubbo.remoting.transport.CodecSupport; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.rpc.support.RpcUtils; import java.io.IOException; import java.io.InputStream; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DECODE_IN_IO_THREAD_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_DECODE_IN_IO_THREAD; -import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; /** * Dubbo codec. @@ -186,7 +185,7 @@ public class DubboCodec extends ExchangeCodec { out.writeObject(encodeInvocationArgument(channel, inv, i)); } } - out.writeObject(RpcUtils.getNecessaryAttachments(inv)); + out.writeObject(inv.getAttachments()); } @Override