belugabehr commented on code in PR #3175:
URL: https://github.com/apache/avro/pull/3175#discussion_r1902268580


##########
lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java:
##########
@@ -173,9 +178,15 @@ public int hashCode() {
     if (h == 0) {
       byte[] bytes = this.bytes;
       int length = this.length;
-      h = 1;
-      for (int i = 0; i < length; i++) {
-        h = h * 31 + bytes[i];
+      // If the array is filled, use the underlying JDK hash functionality.
+      // Starting with JDK 21, the underlying implementation is vectorized.
+      if (length > 7 && bytes.length == length) {
+        h = Arrays.hashCode(bytes);

Review Comment:
   It does fall back, but in my micro benchmarks, I found that it is better to 
implement this skip logic before bothering to jump into the method call itself 
especially since the length needs to be interrogated anyway.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to