RFR [9]: 8050142: Optimize java.util.Formatter (original) (raw)
Claes Redestad claes.redestad at oracle.com
Mon Jul 14 11:26:59 UTC 2014
- Previous message: RFR [9]: 8050142: Optimize java.util.Formatter
- Next message: RFR [9]: 8050142: Optimize java.util.Formatter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
good suggestions, I'll incorporate them.
/Claes
On 2014-07-14 13:08, Andrej Golovnin wrote:
Hi Claes,
in the method Formatter$FormatSpecifier#justify(String) you can pre-calculate the capacity of the StringBuilder to avoid array copying, e.g. instead of 2931 StringBuilder sb = new StringBuilder(); use this one: 2931 StringBuilder sb = new StringBuilder(s.length() + sp); And in the method Formatter$FormatSpecifier#justify(StringBuilder) you can avoid creation of the StringBuilder object in the line 2956, e.g. instead of: 2956 StringBuilder tmp = new StringBuilder(sp); 2957 for (int i = 0; i < sp; i++) {_ _2958 tmp.append(' ');_ _2959 }_ _2960 sb.insert(0, tmp);_ _you can write this:_ _2956 char[] tmp = new char[sp];_ _2957 Arrays.fill(tmp, ' ');_ _2958 sb.insert(0, tmp);_ _It's not a big improvement but maybe you can change the line_ _3781 exp.append("0").append(len - 1);_ _to use the character-based API to append a single character._ _Best regards,_ _Andrej Golovnin_ _On Mon, Jul 14, 2014 at 12:07 PM, Claes Redestad_ _<claes.redestad at oracle.com <mailto:claes.redestad at oracle.com>> wrote: Hi, please review this patch which optimizes away some allocations from java.util.Formatter and achieve 1.1-1.3x speedups of micros targetting String.format. See bug for more details. webrev: http://cr.openjdk.java.net/~redestad/8050142/webrev.0 <http://cr.openjdk.java.net/%7Eredestad/8050142/webrev.0> bug: https://bugs.openjdk.java.net/browse/JDK-8050142 Testing: JPRT, jtreg (java/lang/String, java/util/Formatter), SPECjbb2013 and microbenchmarks Thanks! /Claes
- Previous message: RFR [9]: 8050142: Optimize java.util.Formatter
- Next message: RFR [9]: 8050142: Optimize java.util.Formatter
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]