Apache9 commented on a change in pull request #3691:
URL: https://github.com/apache/hbase/pull/3691#discussion_r722271826
##########
File path:
hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java
##########
@@ -471,4 +485,57 @@ public static byte toByte(ByteBuffer buf, int offset) {
public static byte toByte(Object ref, long offset) {
return theUnsafe.getByte(ref, offset);
}
+
+ /**
+ * Zero fill a byte buffer as efficiently as possible.
+ * @param buf the byte buffer
+ */
+ public static void clear(final ByteBuffer buf) {
+ if (buf.isDirect()) {
+ clear(((DirectBuffer)buf).address(), buf.capacity());
Review comment:
Yes, unaligned stores will be a problem for some architectures, and for
most architectures, aligned stores will be faster than unaligned stores. But
usually, the address should be aligned as the compiler will do padding, and it
is a bit strange that the implementation will skip 8 bytes or 4 bytes stores
even if the length is not 8 bytes aligned.
I suppose the implementation should first do some stores to make the later
stores aligned, and then do the main loops with 8 bytes aligned(or maybe more
if we MMX or SSE), and finally we deal with the remaining several bytes if
needed.
Anyway, this could an optimization later, not a blocker issue for now.
--
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]