This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 6c55aab511 Performance tweaks for filter chain 6c55aab511 is described below commit 6c55aab51121280a66866e387ddfbd46ee0e42e0 Author: remm <r...@apache.org> AuthorDate: Wed Feb 28 16:11:17 2024 +0100 Performance tweaks for filter chain Actually, the check to see if the filter is present was quite inefficient due to the increment size and the lack of loop exit. Investigating using a LinkedHashMap is a possibility. --- java/org/apache/catalina/core/ApplicationFilterChain.java | 13 ++++++------- java/org/apache/tomcat/util/descriptor/web/FilterDef.java | 6 ++++++ webapps/docs/changelog.xml | 8 ++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationFilterChain.java b/java/org/apache/catalina/core/ApplicationFilterChain.java index c038a36709..e6a45a05dc 100644 --- a/java/org/apache/catalina/core/ApplicationFilterChain.java +++ b/java/org/apache/catalina/core/ApplicationFilterChain.java @@ -19,6 +19,7 @@ package org.apache.catalina.core; import java.io.IOException; import java.security.Principal; import java.security.PrivilegedActionException; +import java.util.Arrays; import java.util.Set; import javax.servlet.Filter; @@ -164,7 +165,7 @@ public final class ApplicationFilterChain implements FilterChain { Filter filter = filterConfig.getFilter(); if (request.isAsyncSupported() && - "false".equalsIgnoreCase(filterConfig.getFilterDef().getAsyncSupported())) { + !(filterConfig.getFilterDef().getAsyncSupportedBoolean())) { request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, Boolean.FALSE); } if (Globals.IS_SECURITY_ENABLED) { @@ -253,16 +254,14 @@ public final class ApplicationFilterChain implements FilterChain { void addFilter(ApplicationFilterConfig filterConfig) { // Prevent the same filter being added multiple times - for (ApplicationFilterConfig filter : filters) { - if (filter == filterConfig) { + for (int i = 0; i < n; i++) { + if (filters[i] == filterConfig) { return; } } if (n == filters.length) { - ApplicationFilterConfig[] newFilters = new ApplicationFilterConfig[n + INCREMENT]; - System.arraycopy(filters, 0, newFilters, 0, n); - filters = newFilters; + filters = Arrays.copyOf(filters, n + INCREMENT); } filters[n++] = filterConfig; @@ -315,7 +314,7 @@ public final class ApplicationFilterChain implements FilterChain { public void findNonAsyncFilters(Set<String> result) { for (int i = 0; i < n; i++) { ApplicationFilterConfig filter = filters[i]; - if ("false".equalsIgnoreCase(filter.getFilterDef().getAsyncSupported())) { + if (!(filter.getFilterDef().getAsyncSupportedBoolean())) { result.add(filter.getFilterClass()); } } diff --git a/java/org/apache/tomcat/util/descriptor/web/FilterDef.java b/java/org/apache/tomcat/util/descriptor/web/FilterDef.java index dcee3005a0..83b03e2730 100644 --- a/java/org/apache/tomcat/util/descriptor/web/FilterDef.java +++ b/java/org/apache/tomcat/util/descriptor/web/FilterDef.java @@ -162,8 +162,14 @@ public class FilterDef implements Serializable { public void setAsyncSupported(String asyncSupported) { this.asyncSupported = asyncSupported; + asyncSupportedBoolean = !("false".equalsIgnoreCase(asyncSupported)); } + private boolean asyncSupportedBoolean = true; + + public boolean getAsyncSupportedBoolean() { + return asyncSupportedBoolean; + } // --------------------------------------------------------- Public Methods diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 83799fc7a3..83db5b068a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,14 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 9.0.87 (remm)" rtext="in development"> + <subsection name="Catalina"> + <changelog> + <fix> + Minor performance improvement for building filter chains. Based on + ideas from <pr>702</pr> by Luke Miao. (remm) + </fix> + </changelog> + </subsection> <subsection name="Jasper"> <changelog> <add> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org