You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2022/05/16 16:41:47 UTC

[arrow] branch master updated: ARROW-16568: [Java] Enable skip BOUNDS_CHECKING with setBytes and getBytes of ArrowBuf

This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 0cc320c6e3 ARROW-16568: [Java] Enable skip BOUNDS_CHECKING with setBytes and getBytes of ArrowBuf
0cc320c6e3 is described below

commit 0cc320c6e3b1b1298fe887c4bafe13fd0621e906
Author: stczwd <qc...@163.com>
AuthorDate: Mon May 16 12:41:21 2022 -0400

    ARROW-16568: [Java] Enable skip BOUNDS_CHECKING with setBytes and getBytes of ArrowBuf
    
    We have BOUNDS_CHECKING_SKIP in ArrowBuf.setByte or ArrowBuf.getByte, it helps to remove unexpected bounds checks. However, it doesn't exists in ArrowBuf.setBytes or ArrowBuf.getBytes, which makes 10% cpu time cost for checking bounds in our environment.
    
    Closes #13161 from jackylee-ch/skip_bounds_check_for_set_or_get_bytes
    
    Authored-by: stczwd <qc...@163.com>
    Signed-off-by: David Li <li...@gmail.com>
---
 .../src/main/java/org/apache/arrow/memory/ArrowBuf.java    | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java
index d7827073ea..173d0a52dc 100644
--- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java
+++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/ArrowBuf.java
@@ -692,12 +692,14 @@ public final class ArrowBuf implements AutoCloseable {
   }
 
   private void checkIndex(long index, long fieldLength) {
-    // check reference count
-    this.ensureAccessible();
-    // check bounds
-    if (isOutOfBounds(index, fieldLength, this.capacity())) {
-      throw new IndexOutOfBoundsException(String.format("index: %d, length: %d (expected: range(0, %d))",
-        index, fieldLength, this.capacity()));
+    if (BoundsChecking.BOUNDS_CHECKING_ENABLED) {
+      // check reference count
+      this.ensureAccessible();
+      // check bounds
+      if (isOutOfBounds(index, fieldLength, this.capacity())) {
+        throw new IndexOutOfBoundsException(String.format("index: %d, length: %d (expected: range(0, %d))",
+                index, fieldLength, this.capacity()));
+      }
     }
   }