RFR: 8215412: Optimize PrintStream.println methods
Claes Redestad
claes.redestad at oracle.com
Fri Dec 14 17:12:58 UTC 2018
Hi,
the various PrintStream.println methods are inefficient: nested
synchronization, multiple flushes and a scan of the input string for
newlines that in the end is pointless in this context since newLine will
always flush anyway (if autoflush is enabled).
While performance of printing to console/file is likely to be
dominated by the I/O overheads, there are plenty of simple text
processing applications using stdout to pipe output to another process
for which performance of println could definitely matter.
Webrev: http://cr.openjdk.java.net/~redestad/8215412/jdk.00/
Bug: https://bugs.openjdk.java.net/browse/JDK-8215412
Using a simple test program like this:
public class Test {
public static void main (String ... args) {
for (int i = 0; i < Integer.parseInt(args[0]); i++)
System.out.println(args[1]);
}
}
... and stating the cost of running:
$ java Test 100000 tttttttttttttttttttttttttttttttttttttttttttttt | wc -l
... I get a 15-30% reduction in cycles and wall clock time (larger
reduction the more output is produced).
Thanks!
/Claes
More information about the core-libs-dev
mailing list