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

            Bug ID: 68089
           Summary: ApplicationHttpRequest.getSpecial() and
                    removeSpecial() use linear scans
           Product: Tomcat 9
           Version: 9.0.x
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: jeng...@amazon.com
  Target Milestone: -----

A high-volume, latency-sensitive application shows a large amount of
String.equals() calls buried inside tomcat processing.  Detailed examination
shows that much of it comes from ApplicationHttpRequest.getSpecial() and
removeSpecial(), which are called once per call to request.setAttribute() or
request.removeAttribute().  In our application these calls are from certain
Filters or, more commonly, AstExpressions, especially those which are not
otherwise resolved.

The relevant code is:
    protected static final String specials[] =
            { ... };
    protected int getSpecial(String name) {
        for (int i = 0; i < specials.length; i++) {
            if (specials[i].equals(name)) {
                return i;
            }
        }
        return -1;
    }

The array contains 12 specials, so each call to request.getAttribute(), etc.
performs 12 String comparisons.  The occasional search of an actual special
will reduce that, but very few of our calls match.

Suggestion: use a HashMap<String, Integer> or enums to achieve a similar
purpose.  Comparable performance data may be found at
https://bz.apache.org/bugzilla/show_bug.cgi?id=67080.

These scans are largely inlined into calling methods so I cannot reliably
estimate the cpu or clock impact, however the sheer number of calls is
impressive.

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