Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-14 Thread Mike Duigou
Looks good David. Mike On May 13 2013, at 22:10 , David Holmes wrote: > On 14/05/2013 5:05 AM, Alan Bateman wrote: >> On 13/05/2013 08:12, David Holmes wrote: >>> Thanks for all the feedback and discussion. I've rewritten the patch >>> to use Peter's suggestion of caching the char[] instead of t

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-14 Thread Alan Bateman
On 14/05/2013 06:10, David Holmes wrote: : I'm not sure what to say about the copy-on-change-after-toString approach. As the offset/count fields have been removed from String then it could only be the count == value.length case. It would clearly be a win in some cases but no help in others. R

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-14 Thread Remi Forax
On 05/14/2013 07:10 AM, David Holmes wrote: [...] So here is hopefully final webrev: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v5/ It is the same approach as v3, but as Florian pointed out the cache should be cleared before the mutating action - just in case there is an exception.

Re: Race in String.contentEquals ( was Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks)

2013-05-13 Thread Peter Levart
Right, sb.length() should be used. I will correct that as soon as I get to the keyboard. Regards, Peter On May 14, 2013 7:22 AM, "David Holmes" wrote: > Thanks Peter! I've filed > > 8014477 > Race condition in String.contentEquals when comparing with StringBuffer > > On 14/05/2013 8:34 AM, Peter

Race in String.contentEquals ( was Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks)

2013-05-13 Thread David Holmes
Thanks Peter! I've filed 8014477 Race condition in String.contentEquals when comparing with StringBuffer On 14/05/2013 8:34 AM, Peter Levart wrote: On 05/14/2013 12:09 AM, Peter Levart wrote: I noticed a synchronization bug in String.contentEquals method. If called with a StringBuffer argument

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread David Holmes
On 14/05/2013 5:05 AM, Alan Bateman wrote: On 13/05/2013 08:12, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v3/ I too am

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread Peter Levart
On 05/14/2013 12:09 AM, Peter Levart wrote: I noticed a synchronization bug in String.contentEquals method. If called with a StringBuffer argument while concurrent thread is modifying the StringBuffer, the method can either throw ArrayIndexOutOfBoundsException or return true even though the co

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread Peter Levart
On 05/13/2013 09:05 PM, Alan Bateman wrote: On 13/05/2013 08:12, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v3/ I to

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread Alan Bateman
On 13/05/2013 08:12, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v3/ I too am concerned that any form of caching that a

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread Florian Weimer
On 05/10/2013 08:03 AM, David Holmes wrote: Short version: Cache the value returned by toString and use it to copy-construct a new String on subsequent calls to toString(). Clear the cache on any mutating operation. webrev: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v2/ Shouldn't you

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread David Holmes
On 13/05/2013 6:39 PM, Peter Levart wrote: On 05/13/2013 10:07 AM, Remi Forax wrote: Hi David, On 05/13/2013 09:12 AM, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread Peter Levart
On 05/13/2013 10:07 AM, Remi Forax wrote: Hi David, On 05/13/2013 09:12 AM, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webre

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread David Holmes
On 13/05/2013 6:07 PM, Remi Forax wrote: Hi David, On 05/13/2013 09:12 AM, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread Remi Forax
Hi David, On 05/13/2013 09:12 AM, David Holmes wrote: Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v3/ I too am concerned that any form of

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-13 Thread David Holmes
Thanks for all the feedback and discussion. I've rewritten the patch to use Peter's suggestion of caching the char[] instead of the actual String: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v3/ I too am concerned that any form of caching that avoids the array-copy (which is the crux of

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-10 Thread Martin Buchholz
On Fri, May 10, 2013 at 10:36 AM, Mike Duigou wrote: > The implementation looks OK to me. I like Peter's suggestion of caching > the char[] rather than string. > > I do wish that the cache could be in a soft reference but understand that > there are tradeoffs to doing so. I am worried about leaks

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-10 Thread Mike Duigou
The implementation looks OK to me. I like Peter's suggestion of caching the char[] rather than string. I do wish that the cache could be in a soft reference but understand that there are tradeoffs to doing so. I am worried about leaks with this implementation. Another possibility, to go totall

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-10 Thread David Chase
On 2013-05-10, at 2:47 AM, David Holmes wrote: > Right this was our first thought too, but the specification for toString > states that a new String is created. So to go this path we'd also have to > push through a spec change for StringBuilder/StringBuffer. Given this is an > obscure corner ca

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-10 Thread Alan Bateman
On 10/05/2013 07:03, David Holmes wrote: Short version: Cache the value returned by toString and use it to copy-construct a new String on subsequent calls to toString(). Clear the cache on any mutating operation. webrev: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v2/ Testing: microb

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-10 Thread Peter Levart
Hi David, One remote incompatibility note: the String returned from StringBuffer.toString() is retained by StringBuffer until the next call to StringBuffer mutating method. This can be observed for example if the returned String object is wrapped by a WeakReference. This is really a remotely

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-09 Thread David Holmes
Hi Dave, On 10/05/2013 4:25 PM, David Schlosnagle wrote: Hi David, Would it be beneficial to push the toStringCache up to AbstractStringBuilder so that StringBuilder.toString() benefits from this cache as well? It seems like this would affect both StringBuilder and StringBuffer for repeated cal

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-09 Thread David Holmes
Hi David, On 10/05/2013 4:39 PM, David Schlosnagle wrote: One other quick comment, if the toStringCache is non-null during invocation of toString(), that seems to imply that the StringBuffer/StringBuilder has not been mutated since the last invocation of toString(), is there any reason to still

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-09 Thread David Schlosnagle
One other quick comment, if the toStringCache is non-null during invocation of toString(), that seems to imply that the StringBuffer/StringBuilder has not been mutated since the last invocation of toString(), is there any reason to still use the String copy constructor? This would address the http:

Re: RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-09 Thread David Schlosnagle
Hi David, Would it be beneficial to push the toStringCache up to AbstractStringBuilder so that StringBuilder.toString() benefits from this cache as well? It seems like this would affect both StringBuilder and StringBuffer for repeated calls to toString(), although StringBuffer would obviously have

RFR: 8013395 StringBuffer.toString performance regression impacting embedded benchmarks

2013-05-09 Thread David Holmes
Short version: Cache the value returned by toString and use it to copy-construct a new String on subsequent calls to toString(). Clear the cache on any mutating operation. webrev: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v2/ Testing: microbenchmark for toString performance; new reg