myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stevan Malesevic (JIRA)" <...@myfaces.apache.org>
Subject [jira] Created: (TRINIDAD-1247) org.apache.myfaces.trinidadinternal.skin.RequestSkinWrapper.getStyleSheetDocumentId has very poor performance
Date Fri, 03 Oct 2008 16:08:44 GMT
org.apache.myfaces.trinidadinternal.skin.RequestSkinWrapper.getStyleSheetDocumentId has very
poor performance
-------------------------------------------------------------------------------------------------------------

                 Key: TRINIDAD-1247
                 URL: https://issues.apache.org/jira/browse/TRINIDAD-1247
             Project: MyFaces Trinidad
          Issue Type: Bug
            Reporter: Stevan Malesevic


Application we use makes a calls to org.apache.myfaces.trinidadinternal.skin.RequestSkinWrapper.getStyleSheetDocumentId
for each instance of particular component. So there is a couple of calls per request.
While looking at CPU and memory usage we noticed that a significant amount is spent in this
call. In terms of memory for 45 invocations of this method 5802KB of memory is allocated ,
which means about 129K per method invocation

Most of this memory is spent creating Version objects in org.apache.myfaces.trinidadinternal.style.xml.parse.StyleSheetNode.compareVariants.


To fix this issue we should change StyleSheetNode._compareBrowserAndVersion method to have
signature like
private int _compareBrowserAndVersion(int browser, TrinidadAgent agent)
and create Version object inside the method just before it is needed.   This will greatly
reduce the number of Version objects. 

The method looks like this:


  private int _compareBrowserAndVersion(int browser, TrinidadAgent agent)
  {
    // If we don't have a browser specified, we match anything
    if (_agentVersions.isEmpty())
      return _BROWSER_UNKNOWN_MATCH;

    // On the other hand, if we do have a browser specified, but
    // the client browser is not known, we don't have a match
    if (browser == TrinidadAgent.APPLICATION_UNKNOWN)
      return 0;
    
    //If we have browser exact match, compare versions
    Integer browserNum = Integer.valueOf(browser);
    if (_agentVersions.containsKey(browserNum))
    {
      Set<Version> versions = _agentVersions.get(browserNum);
      if (versions.isEmpty())
        return _BROWSER_EXACT_MATCH | _VERSION_UNKNOWN_MATCH;
      
      Version version = new Version(agent.getAgentVersion());
        
      for (Version av : versions)
      {
        if (av.compareTo(version) == 0)
        {
          return _BROWSER_EXACT_MATCH | _VERSION_EXACT_MATCH;
        }
      }
      
      return 0;
    }

    return 0;
  }

In my test case memory went down to 214K

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


Mime
View raw message