Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8134424

BlockDataInputStream.readUTFBody: size local StringBuffer with the given length

XMLWordPrintable

        Low hanging fruit to improve performance? readUTF knows the string size ahead of the read
        and can avoid expandCapacity() by constructing StringBuilder with the expected size.

        private String readUTFBody(long utflen) throws IOException {
        - StringBuilder sbuf = new StringBuilder();
        ---
        + StringBuilder sbuf = new StringBuilder((int)utflen);

        Sample profile output:
        Stack Trace Sample Count Percentage(%)
        java.io.ObjectInputStream$BlockDataInputStream.readUTFSpan(StringBuilder, long) 640 22.253
        java.util.Arrays.copyOf(char[], int) 146 5.076
           java.lang.AbstractStringBuilder.expandCapacity(int) 146 5.076

              chegar Chris Hegarty
              chegar Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: