This is an automated email from the ASF dual-hosted git repository.
markt 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 2454294840 Further performance improvements for BZ 68089
2454294840 is described below
commit 2454294840b1f4e0ec69477c4cab326c63aa38be
Author: Mark Thomas <[email protected]>
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
---
.../catalina/core/ApplicationHttpRequest.java | 15 ++++++++++
.../apache/catalina/core/ApplicationRequest.java | 35 ++++++++++++----------
webapps/docs/changelog.xml | 5 ++++
3 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/java/org/apache/catalina/core/ApplicationHttpRequest.java
b/java/org/apache/catalina/core/ApplicationHttpRequest.java
index 3eba826b3f..12534bada5 100644
--- a/java/org/apache/catalina/core/ApplicationHttpRequest.java
+++ b/java/org/apache/catalina/core/ApplicationHttpRequest.java
@@ -92,6 +92,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;
@@ -738,6 +741,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);
}
@@ -748,6 +755,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;
@@ -762,6 +773,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 8e0ec4576d..cdbb845a1d 100644
--- a/java/org/apache/catalina/core/ApplicationRequest.java
+++ b/java/org/apache/catalina/core/ApplicationRequest.java
@@ -59,6 +59,9 @@ class ApplicationRequest extends ServletRequestWrapper {
*/
private static final Set<String> specialsSet = new
HashSet<>(Arrays.asList(specials));
+ 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.
@@ -135,6 +138,23 @@ class ApplicationRequest extends ServletRequestWrapper {
}
+ /**
+ * Is this attribute name one of the special ones that is added only for
included servlets?
+ *
+ * @param name Attribute name to be tested
+ *
+ * @deprecated Will be made private in Tomcat 11 onwards.
+ */
+ @Deprecated
+ protected boolean isSpecial(String name) {
+ // Performance - see BZ 68089
+ if (name.length() < shortestSpecialNameLength) {
+ return false;
+ }
+ return specialsSet.contains(name);
+ }
+
+
// ------------------------------------------ ServletRequestWrapper Methods
/**
@@ -157,19 +177,4 @@ class ApplicationRequest extends ServletRequestWrapper {
}
}
}
-
-
- // ------------------------------------------------------ Protected Methods
-
- /**
- * Is this attribute name one of the special ones that is added only for
included servlets?
- *
- * @param name Attribute name to be tested
- *
- * @deprecated Will be removed without replacement in Tomcat 11 onwards.
- */
- @Deprecated
- protected boolean isSpecial(String name) {
- return specialsSet.contains(name);
- }
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 01a21ef39a..2a9316ad75 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -126,6 +126,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: [email protected]
For additional commands, e-mail: [email protected]