Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-7899

Various memory usage improvements

    XMLWordPrintableJSON

Details

    Description

      Some optimisations can be applied to the code to reduce the use of temporary objects.

      Typical improvements identified are:

      • reduce scope of temporary objects creation to avoid creating when not needed. Example :
      public String toString() {        
          StringBuilder sb = new StringBuilder(512);        
          if (isEmpty()) {            
              return "empty";        
          }        
          for (MetadataGraphVertex v : vertices) {
          .....

      can be replaced by 

      public String toString() {        
          if (isEmpty()) {            
              return "empty";
          }        
          StringBuilder sb = new StringBuilder(512);
          for (MetadataGraphVertex v : vertices) {
          .....
      • Reuse StringBuilder objects in loops by setting its length to zero
      • Use the StringBuilder.append() with index to avoid String.substring(). Example:

       

      int idx = resourceName.lastIndexOf('/');
      buffer.append(idx < 0 ? resourceName : resourceName.substring(idx + 1)); 

      can be replaced by 

       

      int idx = resourceName.lastIndexOf('/');
      if (idx < 0) {
          buffer.append(resourceName);
      } else {
          buffer.append(resourceName, idx + 1, resourceName.length());                    } 

       

       

      • Replace dynamic string creation static constants when possible
      • Avoid creating temporary strings with + operator when the final destination can be used instead, like PrintStream.print() method
      • Avoir using StringBuilder.append() method and util method MessageUtils.a() when the final destination can be used instead, like PrintStream.print() method
         

      Attachments

        Activity

          People

            Unassigned Unassigned
            sebastiend sebastien
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: