commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernd Eckenfels (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BEANUTILS-459) Adding and removing properties to LazyDynaClass is expensive
Date Sat, 08 Mar 2014 15:27:43 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-459?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13924893#comment-13924893
] 

Bernd Eckenfels commented on BEANUTILS-459:
-------------------------------------------

Is it actually required to use setProperties() for some extension/inheritance reason?

If not you can simply removing the new newproperties/copy/insert/set with a propertiesMap.put
loop over the old array and the one new entry. Even more optimized would be to get rid of
the getDynaProperties() if it only returns the map with no further processing.

It does not look threadsafe when using the getter.


> 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)

Mime
View raw message