The implementations of equals, compare and mismatch can be reimplemented using underlying mismatch methods that in turn defer to a single method, vectorizedMismatch, that accesses the memory contents of arrays using Unsafe.getLongUnaligned.
The vectorizedMismatch implemetnation can be optimized efficiently by C2 to obtain an approximate 8x speed up when performing a mismatch on byte[] arrays (of a suitable size to overcome fixed costs).
The contract of vectorizedMismatch is simple enough that it can be made an intrinsic (see JDK-8044082) and leverage SIMDs instructions to perform operations up to a width of say 512 bits on supported architectures. Thus even further performance improvements may be possible.
- blocks
-
JDK-8044082 Efficient array comparison intrinsics
- Draft
- is blocked by
-
JDK-8033148 Lexicographic comparators and mismatchers for arrays
- Closed
- relates to
-
JDK-8172156 (array) Tune thresholds for vectorized mismatch in Arrays.equals()
- Open
-
JDK-8193806 AARCH64: create intrinsic for vectorized mismatch
- Closed
-
JDK-6655180 (array) Reduce JNI overhead for Arrays.equals() with float/double arrays
- Closed
-
JDK-8074124 Most Unsafe.get*() access shapes are losing vs. the plain Java accesses
- Open
-
JDK-8143355 Update for addition of vectorizedMismatch intrinsic for x86
- Resolved