Get the latest tech news
Strings Just Got Faster
In JDK 25, Strings used as keys in immutable Maps can be much faster.
The method linker.downcallHandle(…) takes a symbol and additional parameters to bind a native call to a Java MethodHandle via the Foreign Function & Memory API introduced in JDK 22. Now that we know how String::hashCode works, we can unveil the performance changes made (which consists of a single line of code): the internal field String.hash is marked with the JDK-internal@Stable annotation. There is an unfortunate corner case that the new improvement does not cover: if the hash code of the String happens to be zero, constant folding will not work.
Or read this on Hacker News