JDK-8134424 : BlockDataInputStream.readUTFBody: size local StringBuffer with the given length
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io:serialization
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-08-25
  • Updated: 2020-02-21
  • Resolved: 2016-02-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9 Other
8u231Fixed 9 b106Fixed openjdk8u242Fixed
Description
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

Comments
Fix request (8u) Requesting for parity. Simple patch applies cleanly
05-12-2019

RFR thread https://mail.openjdk.java.net/pipermail/core-libs-dev/2016-February/038684.html
19-11-2019