Improve BindingDOMRpcImplementationAdapter performance 82/22082/3
authorRobert Varga <rovarga@cisco.com>
Thu, 28 May 2015 11:20:30 +0000 (13:20 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 8 Jun 2015 11:29:36 +0000 (11:29 +0000)
BindingReflections return a non-shared QNameModule instance, which means
that we may end up using suboptimal lookups when comparing QNames.
Furthermore it is not the QNameModule which we need in the fastpath, but
rather QName of the input statement, hence create a cached reference of
that -- leading to minimal object allocation in the fast path.

Change-Id: I97ceb43d80c50d53d21cc66a31bfaae6ff0193e9
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit c4ee9b293370b81b76cc0e06accf3cde31ac1722)

opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMRpcImplementationAdapter.java

index 2023840e97d4d0df50185602994ef7aeed16ada2..175b0f3f63b9c35aae4ccd614bd22e2546a251fd 100644 (file)
@@ -29,7 +29,6 @@ import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.binding.util.RpcServiceInvoker;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -42,7 +41,7 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
     private final BindingNormalizedNodeCodecRegistry codec;
     private final RpcServiceInvoker invoker;
     private final RpcService delegate;
-    private final QNameModule module;
+    private final QName inputQname;
 
     public <T extends RpcService> BindingDOMRpcImplementationAdapter(final BindingNormalizedNodeCodecRegistry codec, final Class<T> type, final Map<SchemaPath, Method> localNameToMethod, final T delegate) {
         try {
@@ -63,11 +62,7 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
 
         this.codec = Preconditions.checkNotNull(codec);
         this.delegate = Preconditions.checkNotNull(delegate);
-        module = BindingReflections.getQNameModule(type);
-    }
-
-    public QNameModule getQNameModule() {
-        return module;
+        inputQname = QName.cachedReference(QName.create(BindingReflections.getQNameModule(type), "input"));
     }
 
     @Override
@@ -82,11 +77,10 @@ public class BindingDOMRpcImplementationAdapter implements DOMRpcImplementation
         if (input instanceof LazySerializedContainerNode) {
             return ((LazySerializedContainerNode) input).bindingData();
         }
-        final SchemaPath inputSchemaPath = rpcPath.createChild(QName.create(module,"input"));
+        final SchemaPath inputSchemaPath = rpcPath.createChild(inputQname);
         return codec.fromNormalizedNodeRpcData(inputSchemaPath, (ContainerNode) input);
     }
 
-
     private ListenableFuture<RpcResult<?>> invoke(final SchemaPath schemaPath, final DataObject input) {
         return JdkFutureAdapters.listenInPoolThread(invoker.invokeRpc(delegate, schemaPath.getLastComponent(), input));
     }