You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/01/16 17:49:58 UTC

[tomcat] branch 9.0.x updated (0220c6d577 -> 65a8fab1df)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


    from 0220c6d577 Branch name update
     new 386051424c Refactor to avoid issues if JVM optimises conversion to ASCII
     new 65a8fab1df Disable test for Java 16 onwards since performance is comparable

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/tomcat/util/buf/TestMessageBytes.java   | 86 ++++++++++++++--------
 1 file changed, 57 insertions(+), 29 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/02: Disable test for Java 16 onwards since performance is comparable

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 65a8fab1df7a37042819a24d04dad600d213ceda
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Nov 14 11:42:53 2022 +0000

    Disable test for Java 16 onwards since performance is comparable
---
 test/org/apache/tomcat/util/buf/TestMessageBytes.java | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/test/org/apache/tomcat/util/buf/TestMessageBytes.java b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
index 3311996394..4abc1b6374 100644
--- a/test/org/apache/tomcat/util/buf/TestMessageBytes.java
+++ b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
@@ -23,8 +23,11 @@ import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Test;
 
+import org.apache.tomcat.util.compat.JreCompat;
+
 public class TestMessageBytes {
 
     private static final String CONVERSION_STRING =
@@ -100,6 +103,10 @@ public class TestMessageBytes {
      */
     @Test
     public void testConversionPerformance() {
+
+        // ISO_8859_1 conversion appears to be optimised in Java 16 onwards
+        Assume.assumeFalse(JreCompat.isJre16Available());
+
         long optimized = -1;
         long nonOptimized = -1;
 
@@ -110,7 +117,7 @@ public class TestMessageBytes {
          * once to run the test and once more in case of unexpected CI /GC
          * slowness. The test will exit early if possible.
          *
-         * MeesageBytes only optimises conversion for ISO_8859_1
+         * MessageBytes only optimises conversion for ISO_8859_1
          */
         for (int i = 0; i < 3; i++) {
             optimized = doTestOptimisedConversionPerformance();


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/02: Refactor to avoid issues if JVM optimises conversion to ASCII

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 386051424c076577b388070d335ce7357fad681b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Nov 14 11:38:38 2022 +0000

    Refactor to avoid issues if JVM optimises conversion to ASCII
---
 .../apache/tomcat/util/buf/TestMessageBytes.java   | 79 ++++++++++++++--------
 1 file changed, 50 insertions(+), 29 deletions(-)

diff --git a/test/org/apache/tomcat/util/buf/TestMessageBytes.java b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
index f2016f478d..3311996394 100644
--- a/test/org/apache/tomcat/util/buf/TestMessageBytes.java
+++ b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
@@ -16,7 +16,10 @@
  */
 package org.apache.tomcat.util.buf;
 
-import java.nio.charset.Charset;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
 
 import org.junit.Assert;
@@ -24,6 +27,26 @@ import org.junit.Test;
 
 public class TestMessageBytes {
 
+    private static final String CONVERSION_STRING =
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
+
+    private static final int CONVERSION_LOOPS = 1000000;
+
     @Test
     public void testToStringFromNull() {
         MessageBytes mb = MessageBytes.newInstance();
@@ -73,8 +96,7 @@ public class TestMessageBytes {
 
 
     /*
-     * Checks the the optimized code is at least twice as fast as the
-     * non-optimized code.
+     * Checks the the optimized code is faster than the non-optimized code.
      */
     @Test
     public void testConversionPerformance() {
@@ -87,12 +109,12 @@ public class TestMessageBytes {
          * non-optimised code. Loop three times allows once to warn up the JVM
          * once to run the test and once more in case of unexpected CI /GC
          * slowness. The test will exit early if possible.
+         *
+         * MeesageBytes only optimises conversion for ISO_8859_1
          */
         for (int i = 0; i < 3; i++) {
-            optimized = doTestConversionPerformance(StandardCharsets.ISO_8859_1);
-            // US_ASCII chosen as the conversion is the same and it is another
-            // Charset available on all platforms.
-            nonOptimized = doTestConversionPerformance(StandardCharsets.US_ASCII);
+            optimized = doTestOptimisedConversionPerformance();
+            nonOptimized = doTestConversionPerformance();
 
             System.out.println(optimized + " " + nonOptimized);
             if (optimized * 2 < nonOptimized) {
@@ -100,37 +122,36 @@ public class TestMessageBytes {
             }
         }
 
-        Assert.assertTrue("Non-optimised code was faster (" + nonOptimized + "ns) compared to optimized (" + optimized + "ns)", optimized < nonOptimized);
+        Assert.assertTrue("Non-optimised code was faster (" + nonOptimized + "ns) compared to optimized (" +
+                optimized + "ns)", optimized < nonOptimized);
     }
 
 
-    private long doTestConversionPerformance(Charset charset) {
+    private long doTestOptimisedConversionPerformance() {
         MessageBytes mb = MessageBytes.newInstance();
 
-        int loops = 1000000;
-
         long start = System.nanoTime();
-        for (int i = 0; i < loops; i++) {
+        for (int i = 0; i < CONVERSION_LOOPS; i++) {
             mb.recycle();
-            mb.setCharset(charset);
-            mb.setString("0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF");
+            mb.setCharset(StandardCharsets.ISO_8859_1);
+            mb.setString(CONVERSION_STRING);
             mb.toBytes();
         }
         return System.nanoTime() - start;
     }
+
+
+    private long doTestConversionPerformance() {
+        long start = System.nanoTime();
+        for (int i = 0; i < CONVERSION_LOOPS; i++) {
+            CharsetEncoder encoder = StandardCharsets.ISO_8859_1.newEncoder().onMalformedInput(
+                    CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
+            try {
+                encoder.encode(CharBuffer.wrap(CONVERSION_STRING));
+            } catch (CharacterCodingException cce) {
+                Assert.fail();
+            }
+        }
+        return System.nanoTime() - start;
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org