This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new c86ab5e882 Further performance improvements for BZ 68089 c86ab5e882 is described below commit c86ab5e882eeeda1a94ff7e0e311c2a8b60e026e Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Feb 12 14:05:38 2024 +0000 Further performance improvements for BZ 68089 https://bz.apache.org/bugzilla/show_bug.cgi?id=68089 --- java/org/apache/catalina/core/ApplicationHttpRequest.java | 15 +++++++++++++++ java/org/apache/catalina/core/ApplicationRequest.java | 15 +++++++++++++-- webapps/docs/changelog.xml | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationHttpRequest.java b/java/org/apache/catalina/core/ApplicationHttpRequest.java index b518dbe454..814ee277e8 100644 --- a/java/org/apache/catalina/core/ApplicationHttpRequest.java +++ b/java/org/apache/catalina/core/ApplicationHttpRequest.java @@ -88,6 +88,9 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { } } + private static final int shortestSpecialNameLength = + specialsMap.keySet().stream().mapToInt(s -> s.length()).min().getAsInt(); + private static final int SPECIALS_FIRST_FORWARD_INDEX = 6; @@ -742,6 +745,10 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { * @param name Attribute name to be tested */ protected boolean isSpecial(String name) { + // Performance - see BZ 68089 + if (name.length() < shortestSpecialNameLength) { + return false; + } return specialsMap.containsKey(name); } @@ -752,6 +759,10 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { * @return the special attribute pos, or -1 if it is not a special attribute */ protected int getSpecial(String name) { + // Performance - see BZ 68089 + if (name.length() < shortestSpecialNameLength) { + return -1; + } Integer index = specialsMap.get(name); if (index == null) { return -1; @@ -766,6 +777,10 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { * @return true if the attribute was a special attribute, false otherwise */ protected boolean setSpecial(String name, Object value) { + // Performance - see BZ 68089 + if (name.length() < shortestSpecialNameLength) { + return false; + } Integer index = specialsMap.get(name); if (index == null) { return false; diff --git a/java/org/apache/catalina/core/ApplicationRequest.java b/java/org/apache/catalina/core/ApplicationRequest.java index 330e3da575..add391aa67 100644 --- a/java/org/apache/catalina/core/ApplicationRequest.java +++ b/java/org/apache/catalina/core/ApplicationRequest.java @@ -49,6 +49,9 @@ class ApplicationRequest extends ServletRequestWrapper { RequestDispatcher.FORWARD_SERVLET_PATH, RequestDispatcher.FORWARD_PATH_INFO, RequestDispatcher.FORWARD_QUERY_STRING, RequestDispatcher.FORWARD_MAPPING)); + private static final int shortestSpecialNameLength = + specialsSet.stream().mapToInt(s -> s.length()).min().getAsInt(); + /** * The request attributes for this request. This is initialized from the wrapped request, but updates are allowed. @@ -101,7 +104,7 @@ class ApplicationRequest extends ServletRequestWrapper { public void removeAttribute(String name) { synchronized (attributes) { attributes.remove(name); - if (!specialsSet.contains(name)) { + if (!isSpecial(name)) { getRequest().removeAttribute(name); } } @@ -118,13 +121,21 @@ class ApplicationRequest extends ServletRequestWrapper { public void setAttribute(String name, Object value) { synchronized (attributes) { attributes.put(name, value); - if (!specialsSet.contains(name)) { + if (!isSpecial(name)) { getRequest().setAttribute(name, value); } } } + private boolean isSpecial(String name) { + // Performance - see BZ 68089 + if (name.length() < shortestSpecialNameLength) { + return false; + } + return specialsSet.contains(name); + } + // ------------------------------------------ ServletRequestWrapper Methods /** diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 61c67f700d..1d8f6317a8 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -133,6 +133,11 @@ Review usage of debug logging and downgrade trace or data dumping operations from debug level to trace. (remm) </fix> + <fix> + <bug>68089</bug>: Further improve the performance of request attribute + access for <code>ApplicationHttpRequest</code> and + <code>ApplicationRequest</code>. (markt) + </fix> <fix> <bug>68559</bug>: Allow asynchronous error handling to write to the response after an error during asynchronous processing. (markt) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org