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

            Bug ID: 68546
           Summary: Performance optimization in
                    PageContextImpl.getELContext()
           Product: Tomcat 9
           Version: 9.0.81
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Jasper
          Assignee: dev@tomcat.apache.org
          Reporter: jeng...@amazon.com
  Target Milestone: -----

Created attachment 39554
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=39554&action=edit
Speed test

A high-volume, latency sensitive application reports that
org.apache.jasper.runtime.PageContextImpl.getELContext() uses 0.11% of cpu, of
which 0.07% is local to the method.  A portion of that comes from iterating
across sparse HashSets (packageImports and classImports), the cost of which
grows linearly with array size (null buckets are scanned).

In the most common case, our JSPs rely on the three auto-generated packages and
1-2 classes.  For example, this generated code block from our busiest JSP:

 static {
    _jspx_imports_packages = new java.util.HashSet<>();
    _jspx_imports_packages.add("javax.servlet");
    _jspx_imports_packages.add("javax.servlet.http");
    _jspx_imports_packages.add("javax.servlet.jsp");
    _jspx_imports_classes = new java.util.HashSet<>();
    _jspx_imports_classes.add("com.<proprietary>ViewModel");
    _jspx_imports_classes.add("com.<proprietary>Helper");
  }

Most JVMs initialize HashMap arrays to length 16, so the code above generates
one array that is 3/16th full and another that is 2/16th full.  Each page
request scans the full 16-slot array.

A few alternatives exist:
1. Right-size the Set allocation.  The entries in the Set are fixed and known
at the time of code generation so should be an easy change.
2. Switch to LinkedHashSet<>.  Iteration becomes trivial.
3. Combine the two: right-size a LinkedHashSet<>.

The attached speed test shows a big improvement with #2 (right-sizing) but a
greater improvement from either #1 or #3.

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