https://bz.apache.org/bugzilla/show_bug.cgi?id=69381

            Bug ID: 69381
           Summary: Excess object copying while evaluating reflective
                    method calls
           Product: Tomcat 9
           Version: 9.0.x
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: EL
          Assignee: dev@tomcat.apache.org
          Reporter: jeng...@amazon.com
  Target Milestone: -----

Evaluating JSP EL expressions with reflective operations ("${beanA.getBean()}")
is slow because the reflective objects are copied on each execution. 
Specifically, javax.el.Util.findMethod() calls java.lang.Class.getMethods(). 
In OpenJDK, getMethods() makes a call to duplicate the source-of-truth array. 
>From OpenJDK source:

return copyMethods(privateGetPublicMethods());

An easy optimization would be to store the array in a ConcurrentHashMap for
later reuse; I'm not certain whether there are ways to use Class.getMethod() to
more specifically retrieve the targeted Method.

A local benchmark based on TestELParserPerformance shows that a
ConcurrentHashMap accelerates this expression 50% (from 1070ns to 500ns) and
reduces memory allocation by 75% (from 248MB to 64MB).

Static ConcurrentHashMaps have disadvantages, but this is a large impact,
especially on objects with many methods.  The benchmark numbers above featured
8 Methods but tests with larger objects confirm a linear increase in memory
allocation and a sub-linear increase in runtime.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to