In article <510c0a6a$0$8985$> ,
jlp <> wrote:
> The String class was modified in JDK 1.7.0_6.
> String.substring that was 0(1) before JDK 1.7.0_6, now becomes O(n)
>
> All is well explained at :
> http://java-performance.info/changes...java-1-7-0_06/
>
> I wrote a small test:
> https://gist.github.com/4692960
>
> java -Xms128M -Xmx128M teststring.Main 100000 1000000
>
> On my desktop:
> jdk 1.7.0_11 => 33 seconds / 252 KBytes Memory
> jdk 1.6.0_38 => 25 milliseconds / 782 KBytes Memory
> more than 1000 times faster ! ( Ok! for this stupid test
)
>
> I don't think it is a good improvement ! Uses less memory, but you
> retrieve it, when the object is garbaged
> What do you think about this ?
It's an unbelievable change. Buffer sharing in Java 1-6 had the simple
workaround of calling the String(String) constructor. There's no
workaround for Strings getting much slower in Java 7+.
What Oracle did in Java 7 would only make sense if CharSequence had
buffer sharing and better support. I just checked Java 7, and
CharSequence looks more useless than ever. String.subSequence()
allocates a new char[] and the usual parsers (Integer, Long, Float)
still only accept a String. Slow Strings it is.
Side rant:
Sun broke buffer sharing between StringBuffer and String back in Java 5.
The reason was so that AbstractStringBuilder class could support the
implementations for both StringBuffer and StringBuilder. Had they kept
the implementations split, we could still have a very fast
StringBuffer.toString(). As a final F-U, none of classes can be
extended even through there's no buffer sharing that can be hacked.
--
I will not see posts from Google because I must filter them as spam