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

            Bug ID: 69348
           Summary: Optimizable memory allocation in ELContext
           Product: Tomcat 9
           Version: 9.0.x
          Hardware: All
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: EL
          Assignee: dev@tomcat.apache.org
          Reporter: jeng...@amazon.com
  Target Milestone: -----

Heap dumps of the recently-added
org.apache.el.parser.TestELParserPerformance.testAstNotEmpty() and testAstAnd()
show extremely high memory usage, which I tracked down to the allocation of
ELContext.lambdaArguments.  Specifically, this field is eagerly initialized via
"new ArrayDeque()".  The default size calculation changes across JVM version so
details may vary - however it looks like 16 is the most probable.

In this particular test, lambdaArguments is never used.  Lazy-initializing this
field such as:

    private Deque<Map<String, Object>> getLambdaArguments() {
        if (lambdaArguments == null) {
            lambdaArguments = new ArrayDeque<>(2);
        }

        return lambdaArguments;
    }

cuts the memory allocated during these tests by over 50%.

In addition to lazy loads, a more conservative size will reduce allocation even
when the object is used.  For example, the sample above uses 2, although that
is probably not the right value for the real world.

Expected impact is a huge reduction in memory allocation while processing EL
expressions.  The rare few Ast* nodes that require the lambdaArguments field
will also improve based on a more conservative allocation size.

-- 
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