[11u] RFR (XS) 8229022: BufferedReader performance can be improved by using StringBuilder

Aleksey Shipilev shade at redhat.com
Fri Oct 4 14:15:13 UTC 2019


RFE:
  https://bugs.openjdk.java.net/browse/JDK-8229022
  https://hg.openjdk.java.net/jdk/jdk/rev/ed0058d06107

This is a tiny RFE that does substantial performance improvement. The patch does not apply cleanly,
because the context is a bit different. (Mostly because JDK-823042 LineNumberReader fixes, which I
have questions about, so it is not really backportable at the moment).

11u patch:

--- old/src/java.base/share/classes/java/io/BufferedReader.java	2019-10-04 16:09:45.826490807 +0200
+++ new/src/java.base/share/classes/java/io/BufferedReader.java	2019-10-04 16:09:45.674492392 +0200
@@ -312,7 +312,7 @@
      * @exception  IOException  If an I/O error occurs
      */
     String readLine(boolean ignoreLF) throws IOException {
-        StringBuffer s = null;
+        StringBuilder s = null;
         int startChar;

         synchronized (lock) {
@@ -368,7 +368,7 @@
                 }

                 if (s == null)
-                    s = new StringBuffer(defaultExpectedLineLength);
+                    s = new StringBuilder(defaultExpectedLineLength);
                 s.append(cb, startChar, i - startChar);
             }
         }

Testing: tier1, tier2

-- 
Thanks,
-Aleksey



More information about the jdk-updates-dev mailing list