This is an automated email from the ASF dual-hosted git repository. remm 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 835e1be32a Performance tweaks for filter chain 835e1be32a is described below commit 835e1be32a936fe5b40b340e9b83a3036cd28bbf 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 de4144ad68..fd7a892d1a 100644 --- a/java/org/apache/catalina/core/ApplicationFilterChain.java +++ b/java/org/apache/catalina/core/ApplicationFilterChain.java @@ -17,6 +17,7 @@ package org.apache.catalina.core; import java.io.IOException; +import java.util.Arrays; import java.util.Set; import jakarta.servlet.Filter; @@ -113,7 +114,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); } filter.doFilter(request, response, this); @@ -182,16 +183,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; @@ -250,7 +249,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 89e5be6a97..c7fcb3e46d 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -112,6 +112,14 @@ </update> </changelog> </subsection> + <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="Coyote"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org