You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by "Paul Lindner (JIRA)" <ji...@apache.org> on 2008/09/30 20:41:44 UTC
[jira] Created: (SHINDIG-633) JSON Serialization is very slow
JSON Serialization is very slow
-------------------------------
Key: SHINDIG-633
URL: https://issues.apache.org/jira/browse/SHINDIG-633
Project: Shindig
Issue Type: Improvement
Components: Common Components (Java)
Reporter: Paul Lindner
BeanJsonConverter recalcuates the getters for a given method for a class every single time. This is terribly inefficient and results in regex code running for every serialize.
Patch that caches these follows:
+++ java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java (working copy)
@@ -44,6 +44,7 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Converts pojos to json objects.
@@ -168,9 +169,19 @@
}
}
+
+ private static final ConcurrentHashMap<Class,List<MethodPair>> CLASS_TO_METHODS = new ConcurrentHashMap<Class,List<MethodPair>>();
+
private List<MethodPair> getMatchingMethods(Object pojo, Pattern pattern) {
- List<MethodPair> availableGetters = Lists.newArrayList();
+ List<MethodPair> availableGetters;
+ Class<?> clz = pojo.getClass();
+ availableGetters = CLASS_TO_METHODS.get(clz);
+
+ if (availableGetters != null)
+ return availableGetters;
+
+ availableGetters = Lists.newArrayList();
Method[] methods = pojo.getClass().getMethods();
for (Method method : methods) {
Matcher matcher = pattern.matcher(method.getName());
@@ -185,6 +196,7 @@
}
availableGetters.add(new MethodPair(method, fieldName));
}
+ CLASS_TO_METHODS.put(clz, availableGetters);
return availableGetters;
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (SHINDIG-633) JSON Serialization is very slow
Posted by "Paul Lindner (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SHINDIG-633?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Lindner resolved SHINDIG-633.
----------------------------------
Resolution: Fixed
found an issue with this patch, since this code path is used for getters and setters.
Updated and resolved.
> JSON Serialization is very slow
> -------------------------------
>
> Key: SHINDIG-633
> URL: https://issues.apache.org/jira/browse/SHINDIG-633
> Project: Shindig
> Issue Type: Improvement
> Components: Common Components (Java)
> Reporter: Paul Lindner
> Assignee: Paul Lindner
>
> BeanJsonConverter recalcuates the getters for a given method for a class every single time. This is terribly inefficient and results in regex code running for every serialize.
> Patch that caches these follows:
> +++ java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java (working copy)
> @@ -44,6 +44,7 @@
> import java.util.Set;
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
> +import java.util.concurrent.ConcurrentHashMap;
>
> /**
> * Converts pojos to json objects.
> @@ -168,9 +169,19 @@
> }
> }
>
> +
> + private static final ConcurrentHashMap<Class,List<MethodPair>> CLASS_TO_METHODS = new ConcurrentHashMap<Class,List<MethodPair>>();
> +
> private List<MethodPair> getMatchingMethods(Object pojo, Pattern pattern) {
> - List<MethodPair> availableGetters = Lists.newArrayList();
> + List<MethodPair> availableGetters;
>
> + Class<?> clz = pojo.getClass();
> + availableGetters = CLASS_TO_METHODS.get(clz);
> +
> + if (availableGetters != null)
> + return availableGetters;
> +
> + availableGetters = Lists.newArrayList();
> Method[] methods = pojo.getClass().getMethods();
> for (Method method : methods) {
> Matcher matcher = pattern.matcher(method.getName());
> @@ -185,6 +196,7 @@
> }
> availableGetters.add(new MethodPair(method, fieldName));
> }
> + CLASS_TO_METHODS.put(clz, availableGetters);
> return availableGetters;
> }
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (SHINDIG-633) JSON Serialization is very slow
Posted by "Paul Lindner (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/SHINDIG-633?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul Lindner reassigned SHINDIG-633:
------------------------------------
Assignee: Paul Lindner
> JSON Serialization is very slow
> -------------------------------
>
> Key: SHINDIG-633
> URL: https://issues.apache.org/jira/browse/SHINDIG-633
> Project: Shindig
> Issue Type: Improvement
> Components: Common Components (Java)
> Reporter: Paul Lindner
> Assignee: Paul Lindner
>
> BeanJsonConverter recalcuates the getters for a given method for a class every single time. This is terribly inefficient and results in regex code running for every serialize.
> Patch that caches these follows:
> +++ java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java (working copy)
> @@ -44,6 +44,7 @@
> import java.util.Set;
> import java.util.regex.Matcher;
> import java.util.regex.Pattern;
> +import java.util.concurrent.ConcurrentHashMap;
>
> /**
> * Converts pojos to json objects.
> @@ -168,9 +169,19 @@
> }
> }
>
> +
> + private static final ConcurrentHashMap<Class,List<MethodPair>> CLASS_TO_METHODS = new ConcurrentHashMap<Class,List<MethodPair>>();
> +
> private List<MethodPair> getMatchingMethods(Object pojo, Pattern pattern) {
> - List<MethodPair> availableGetters = Lists.newArrayList();
> + List<MethodPair> availableGetters;
>
> + Class<?> clz = pojo.getClass();
> + availableGetters = CLASS_TO_METHODS.get(clz);
> +
> + if (availableGetters != null)
> + return availableGetters;
> +
> + availableGetters = Lists.newArrayList();
> Method[] methods = pojo.getClass().getMethods();
> for (Method method : methods) {
> Matcher matcher = pattern.matcher(method.getName());
> @@ -185,6 +196,7 @@
> }
> availableGetters.add(new MethodPair(method, fieldName));
> }
> + CLASS_TO_METHODS.put(clz, availableGetters);
> return availableGetters;
> }
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.