I've run into a really weird case - I have the following code:
new String(data, position, len, Charset.forName("windows-1255"));
where data
is a byte[]
, and position
and len
are int
s.
When I run it on jdk 1.6.0_38, it runs really slow (for a set iteration 411 seconds), and when I run this:
new String(data, position, len);
it runs the same iteration in less than 1 sec. Some more data:
can anyone explain this weird behavior?
I think you ran into this issue. The article claims that the constructor you are using is inefficient, because it always makes a defensive copy of the provided byte[] buffer, which then can lead to frequent GCing. I guess if you do a long enough iteration, the performance differences can become that visible - just like it is mentioned in the article's summary.
As for the access vialoation, it seems to be this problem.