commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe Renon (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (BEANUTILS-459) Adding and removing properties to LazyDynaClass is expensive
Date Thu, 10 Jul 2014 15:54:04 GMT

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

Philippe Renon edited comment on BEANUTILS-459 at 7/10/14 3:53 PM:
-------------------------------------------------------------------

As a workaround we tried to write our own LazyDynaClass. 
This ended up difficult to do because there is one place in 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.


was (Author: prenon):
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)

Mime
View raw message