UnsignedBytesComparator? #299
hrstoyanov
started this conversation in
Ideas
Replies: 1 comment
-
If not available the Unsafe class will fall back to the pure java comparison. It's more than 5y that I read Unsafe is going to be removed, but it's still there, so I think we are going to be fine for years to come, and in case the fallback approach would still work. About the new vector API, let's wait until it's stable and approved, but it's definitely something we were looking for (Begin to document areas where we can take advantage of Java's Vector API #53). About the Comparable interface in Binary it's used in queries. Not common comparing arrays, but it's still possible. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@lvca looking at com.arcadedb.serializer.UnsignedBytesComparator class, I see it tries to implement byte[] comparator using sun.misc.Unsafe ,or falls back to "pure java comparator". There are 2 issues with it:
Are the gains so remarkable when using the forbidden APIs to justify the pain and hassle of these two classes (compared to the "pure java comparator")?
One idea: Does com.arcadedb.database.Binary really need to implement Comparable? How does it make sense to say one byte array is "greater" or "lesser" than another? If you can drop the Comparable requirement, or if you state that the byte arrays can be ordered by their length (but not content!), then you can just use java.util.Arrays.equals(byte[], byte[])
Are you targeting ArcadeDB for Java 8, 11 or 17+ ?
If you really, really need to order byte arrays based on content, there is a cleaner and much better way to implement byte vector comparison - As of Java 17 it is possible to use hardware-accelerated vector operations (including for comparison) . Unfortunately, it is still not finalized and you should run apps with --enable-preview flag, but it uses vector extensions in both x64(AVX) and ARM.
Beta Was this translation helpful? Give feedback.
All reactions