Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-459

Adding and removing properties to LazyDynaClass is expensive

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.8.3
    • None
    • DynaBean
    • None

    Description

      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.

          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);
      
          }
      
          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]);
              }
      
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            prenon Philippe Renon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: