On Tue, 10 Aug 2021 09:18:39 GMT, Alan Bateman <al...@openjdk.org> wrote:

> It would be useful to get up to date performance data on using Charset vs. 
> charset name. At least historically, the charset name versions were faster 
> (see [JDK-6764325](https://bugs.openjdk.java.net/browse/JDK-6764325)).

The code in question was changed a few times since then, the last change was 
done by the https://github.com/openjdk/jdk/pull/2102. So currently the code for 
string.getBytes String/Charset uses the same code paths, except that the string 
version has an additional call to lookup the charset.
The string version:
https://github.com/openjdk/jdk/blob/66d1faa7847b645f20ab2e966adf0a523e3ffeb2/src/java.base/share/classes/java/lang/String.java#L1753
The charset version:
https://github.com/openjdk/jdk/blob/66d1faa7847b645f20ab2e966adf0a523e3ffeb2/src/java.base/share/classes/java/lang/String.java#L1777

I checked the performance and the charset is always faster, depending on the 
string size, up to x20.

@cl4es please confirm my observation since you did it already for 
https://github.com/openjdk/jdk/pull/2102

-------------

PR: https://git.openjdk.java.net/jdk/pull/5063

Reply via email to