RFR (S): 8065070: (fmt) Avoid creating substrings when building FormatSpecifier

Claes Redestad claes.redestad at oracle.com
Sun Nov 16 23:09:53 UTC 2014


Hi,

can I have a review for this small optimization to j.u.Formatter which 
removes a number of
String allocationswhen parsing format specifiers:

http://cr.openjdk.java.net/~redestad/8065070/webrev.00
https://bugs.openjdk.java.net/browse/JDK-8065070

Testing: jtreg

Reasonable improvement (~5-20%) when microbenchmarking String.format 
expressions with index,
precision and/or width specifiers. Example:

@Benchmark
public String formatIndexedDoubleExpr() {
     return String.format("%1$2.3f", pi);
}

before: 1082.564   18.943  ops/ms
after: 1309.945   18.219  ops/ms  # 1.21x

Thanks!

/Claes



More information about the core-libs-dev mailing list