This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 55ff302cfb Performance tweaks for filter chain 55ff302cfb is described below commit 55ff302cfb6e9b2694ebcdbd554fdf60d180dc51 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 998799f4ab..321be19258 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 jakarta.servlet.Filter; @@ -160,7 +161,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) { @@ -249,16 +250,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; @@ -317,7 +316,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 3a208964e0..b742d5c19c 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 0d11f722ed..42637e78b7 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 10.1.20 (schultz)" 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