perf: USE CORRECTLY SIZED STRINGBUILDERS IN GETCLIENTID
-------------------------------------------------------

                 Key: TRINIDAD-887
                 URL: https://issues.apache.org/jira/browse/TRINIDAD-887
             Project: MyFaces Trinidad
          Issue Type: Bug
          Components: Components
            Reporter: Gabrielle Crawford
            Assignee: Gabrielle Crawford
            Priority: Minor


Explicitly create properly sized stringbuilder in getClientId for perf reasons. 
Here's an analysis from a colleague at Oracle:

The Jdev memory profiler reported that after warming up the JVM, each request
of the page from a new browser resulted in about 2.3MB of memory allocated.

About 12% (270K out of total 2324K) of the memory allocated came from the
call org.apache.myfaces.trinidad.component.UIXComponentBase.getClientId.

The code currently does String concatenation, which resulted in an internal 
StringBuilder with default length being created:

        clientId = (containerComponent.getContainerClientId(context) +
                    NamingContainer.SEPARATOR_CHAR +
                    clientId);

The default length is not large enough, so the StringBuilder has to expand, 
causing additional memory allocation.

This could be avoided by using a properly-sized StringBuilder:

        String cont = containerComponent.getContainerClientId(context);
        StringBuilder bld = new StringBuilder(cont.length() + 1 +
clientId.length());
        clientId =
bld.append(cont).append(NamingContainer.SEPARATOR_CHAR).append(clientId).toStr
ing();

The code in
org.apache.myfaces.trindad.component.UIXCollection.getContainerClientId has a
similar problem:

    if (key != null)
    {
      id += NamingContainer.SEPARATOR_CHAR + key;
    }

A better way to do this would be:

    if (key != null)
    {
      StringBuilder bld = new StringBuilder(id.length() + 1 + key.length());    
   id =
bld.append(id).append(NamingContainer.SEPARATOR_CHAR).append(key).toString();
    }

I tested with the about fix and memory allocated for these two methods
reduced from 270K to 173K, a saving of about 4.2% of total. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to