Liran Zelkha has uploaded a new change for review.

Change subject: core: Long response time when using list API
......................................................................

core: Long response time when using list API

Cache some reflection work so that list API serialization will be faster.
According to the profiler, this should save ~33% of serialization time.

Change-Id: I1801e5589d8cec1474e32e495b35b6c150e101ca
Bug-Url: https://bugzilla.redhat.com/1216023
Signed-off-by: [email protected] <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
1 file changed, 39 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/09/40809/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
index 0cb7f33..41e8767 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
@@ -22,6 +22,8 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import javax.ws.rs.Path;
 import javax.ws.rs.core.UriBuilder;
@@ -310,6 +312,7 @@
      * A map describing every possible collection
      */
     private static ModelToCollectionsMap TYPES = new ModelToCollectionsMap();
+    private static ConcurrentMap<Class<?>, List<Method>> methodCache = new 
ConcurrentHashMap<>();
 
     static {
         ParentToCollectionMap map;
@@ -679,26 +682,21 @@
     private static List<BaseResource> getInlineResources(Object obj) {
         ArrayList<BaseResource> ret = new ArrayList<BaseResource>();
 
-        for (Method method : obj.getClass().getMethods()) {
-            if (method.getName().startsWith("get")) {
-                // We need to recursively scan everything that is in the model 
package, as there may be references
-                // to resources deeply nested:
-                if (method.getReturnType().getPackage() == 
BaseResource.class.getPackage()) {
-                    Object inline = null;
-                    try {
-                        inline = method.invoke(obj);
-                    }
-                    catch (Exception e) {
-                        // invocation target exception should not occur on 
simple getter
-                    }
-                    if (inline != null) {
-                        if (inline instanceof BaseResource) {
-                            ret.add((BaseResource) inline);
-                        }
-                        else {
-                            ret.addAll(getInlineResources(inline));
-                        }
-                    }
+        for (Method method : getRelevantMethods(obj.getClass())) {
+            // We need to recursively scan everything that is in the model 
package, as there may be references
+            // to resources deeply nested:
+            Object inline = null;
+            try {
+                inline = method.invoke(obj);
+            } catch (Exception e) {
+                // invocation target exception should not occur on simple 
getter
+            }
+            if (inline != null) {
+                if (inline instanceof BaseResource) {
+                    ret.add((BaseResource) inline);
+                }
+                else {
+                    ret.addAll(getInlineResources(inline));
                 }
             }
         }
@@ -707,6 +705,27 @@
     }
 
     /**
+     * Gets all the relevant possible inline resources methods of a class. 
Data is cached for future use.
+     * @param clz
+     * @return The list of relevant methods.
+     */
+    private static List<Method> getRelevantMethods(Class<?> clz) {
+        List<Method> methods = new ArrayList<>();
+        if (methodCache.containsKey(clz)) {
+            return methodCache.get(clz);
+        }
+        for (Method method : clz.getMethods()) {
+            if (method.getName().startsWith("get")) {
+                if (method.getReturnType().getPackage() == 
BaseResource.class.getPackage()) {
+                    methods.add(method);
+                }
+            }
+        }
+        methodCache.put(clz, methods);
+
+        return methods;
+    }
+    /**
      * Unset the property on @model of type @type
      *
      * @param model the object with the property to unset


-- 
To view, visit https://gerrit.ovirt.org/40809
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1801e5589d8cec1474e32e495b35b6c150e101ca
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Liran Zelkha <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to