Hi Michael,
As you might expect performance of strings is very sensitive and has
been tuned extensively over the years many times.
Though this improves the performance for 1 character strings. It will
have an impact on *every other* length of string.
You'll need to show that it does not impact performance of longer strings.
It may be worth looking further at other ways to achieve the result.
Regards, Roger
On 11/22/21 3:52 PM, Michael Bien wrote:
Hello,
I kept forgetting which variants of the String methods perform better
with single-char-Strings and which with char (IDEs had the tendency to
suggest the wrong variant since it changed between JDK releases). So i
wrote JMH benchmarks and noticed that the last method with a
performance difference seems to be String.indexOf() - all other
variants performed equally (unless I overlooked some).
this might be fairly easy to fix:
https://github.com/openjdk/jdk/pull/6509
(side effect: contains("c") is also faster)
I haven't looked into the intrinsified code of StringLatin1 and
StringUTF16 to check if it could be fixed there (mostly because i
actually don't know how the JVM assembles those intrinsics). It might
be possible to improve this for short Strings in general, not just for
chars, dependent on why the intrinsified version is actually slower
for single-char-Strings. I opted for the trivial fix in java code.
best regards,
michael