RFR: 8282664: Unroll by hand StringUTF16 and StringLatin1 polynomial hash loops [v13]
Sandhya Viswanathan
sviswanathan at openjdk.org
Wed Dec 21 01:59:01 UTC 2022
On Tue, 20 Dec 2022 19:52:34 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/StringUTF16.java line 418:
>>
>>> 416: return 0;
>>> 417: } else {
>>> 418: return ArraysSupport.vectorizedHashCode(value, ArraysSupport.UTF16);
>>
>> Special case for 1 missing here.
>
> Intentionally left out. Array length is always even for `UTF16` arrays, but we could add a case for `2` that'd return `getChar(bytes, 0)` but I didn't see much of a win when I tested this.
I do see a 1.5x gain with this special case added:
return switch (value.length) {
case 0 -> 0;
case 2 -> getChar(value, 0);
default -> ArraysSupport.vectorizedHashCode(value, ArraysSupport.UTF16);
};
before: 0.987 ns/op
after: 0.640 ns/op
-------------
PR: https://git.openjdk.org/jdk/pull/10847
More information about the hotspot-dev
mailing list