You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Philippe Renon (JIRA)" <ji...@apache.org> on 2014/07/10 17:37:05 UTC
[jira] [Commented] (BEANUTILS-459) Adding and removing properties
to LazyDynaClass is expensive
[ https://issues.apache.org/jira/browse/BEANUTILS-459?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14057595#comment-14057595 ]
Philippe Renon commented on BEANUTILS-459:
------------------------------------------
As a workaround we tried to write our own LazyDynaClass.
This ended up difficult to because there is one place LazyDynaBean where there is an explicit type check against LazyDynaClass.
{code}
protected boolean isDynaProperty(String name) {
if (name == null) {
throw new IllegalArgumentException("No property name specified");
}
// Handle LazyDynaClasses
if (dynaClass instanceof LazyDynaClass) {
return ((LazyDynaClass)dynaClass).isDynaProperty(name);
}
// Handle other MutableDynaClass
return dynaClass.getDynaProperty(name) == null ? false : true;
}
{code}
This makes it impossible/very difficult to implement an alternative dyna class.
Solution would be to move the isDynaProperty method to the DynaClass interface.
> Adding and removing properties to LazyDynaClass is expensive
> ------------------------------------------------------------
>
> Key: BEANUTILS-459
> URL: https://issues.apache.org/jira/browse/BEANUTILS-459
> Project: Commons BeanUtils
> Issue Type: Improvement
> Components: DynaBean
> Affects Versions: 1.8.3
> Reporter: Philippe Renon
>
> Adding and removing properties from a LazyDynaClass involves array copying and map rebuilding and gets quite expensive if done often.
> Main issue is that it generates quite a lot of garbage.
> {code}
> protected void add(DynaProperty property) {
> <snip>
> // Create a new property array with the specified property
> DynaProperty[] oldProperties = getDynaProperties();
> DynaProperty[] newProperties = new DynaProperty[oldProperties.length+1];
> System.arraycopy(oldProperties, 0, newProperties, 0, oldProperties.length);
> newProperties[oldProperties.length] = property;
> // Update the properties
> setProperties(newProperties);
> }
> {code}
> {code}
> protected void setProperties(DynaProperty[] properties) {
> this.properties = properties;
> propertiesMap.clear();
> for (int i = 0; i < properties.length; i++) {
> propertiesMap.put(properties[i].getName(), properties[i]);
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)