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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3d4905ac8ef Reduce reflection overhead of 
ByteBufferUtil::newDirectByteBuffer (#15878)
3d4905ac8ef is described below

commit 3d4905ac8ef48aa9043d0166506a2ea6776d5505
Author: Dino Occhialini <dino.occhial...@gmail.com>
AuthorDate: Tue Jun 17 01:35:40 2025 -0700

    Reduce reflection overhead of ByteBufferUtil::newDirectByteBuffer (#15878)
---
 .../pinot/segment/spi/memory/ByteBufferUtil.java   | 35 +++++++++++++++-------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git 
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/memory/ByteBufferUtil.java
 
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/memory/ByteBufferUtil.java
index 6e9bbe420a6..39d579c11d3 100644
--- 
a/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/memory/ByteBufferUtil.java
+++ 
b/pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/memory/ByteBufferUtil.java
@@ -19,6 +19,9 @@
 package org.apache.pinot.segment.spi.memory;
 
 import com.google.common.collect.Lists;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.lang.reflect.Constructor;
 import java.nio.ByteBuffer;
 import java.util.List;
@@ -42,11 +45,14 @@ public class ByteBufferUtil {
         Constructor<? extends ByteBuffer> dbbCC =
             (Constructor<? extends ByteBuffer>) 
Class.forName("java.nio.DirectByteBuffer")
                 .getDeclaredConstructor(Long.TYPE, Integer.TYPE, Object.class, 
memorySegmentProxyClass);
+        dbbCC.setAccessible(true);
+        MethodHandle dbbCCMh = MethodHandles.lookup()
+            .unreflectConstructor(dbbCC)
+            .asType(MethodType.methodType(ByteBuffer.class, long.class, 
int.class, Object.class, Object.class));
         return (addr, size, att) -> {
-          dbbCC.setAccessible(true);
           try {
-            return dbbCC.newInstance(Long.valueOf(addr), 
Integer.valueOf(size), att, null);
-          } catch (Exception e) {
+            return (ByteBuffer) dbbCCMh.invokeExact(addr, size, att, (Object) 
null);
+          } catch (Throwable e) {
             throw new IllegalStateException("Failed to create 
DirectByteBuffer", e);
           }
         };
@@ -56,11 +62,14 @@ public class ByteBufferUtil {
         Constructor<? extends ByteBuffer> dbbCC =
             (Constructor<? extends ByteBuffer>) 
Class.forName("java.nio.DirectByteBuffer")
                 .getDeclaredConstructor(Long.TYPE, Integer.TYPE, Object.class);
+        dbbCC.setAccessible(true);
+        MethodHandle dbbCCMh = MethodHandles.lookup()
+            .unreflectConstructor(dbbCC)
+            .asType(MethodType.methodType(ByteBuffer.class, long.class, 
int.class, Object.class));
         return (addr, size, att) -> {
-          dbbCC.setAccessible(true);
           try {
-            return dbbCC.newInstance(Long.valueOf(addr), 
Integer.valueOf(size), att);
-          } catch (Exception e) {
+            return (ByteBuffer) dbbCCMh.invokeExact(addr, size, att);
+          } catch (Throwable e) {
             throw new IllegalStateException("Failed to create 
DirectByteBuffer", e);
           }
         };
@@ -70,11 +79,14 @@ public class ByteBufferUtil {
         Constructor<? extends ByteBuffer> dbbCC =
             (Constructor<? extends ByteBuffer>) 
Class.forName("java.nio.DirectByteBuffer")
                 .getDeclaredConstructor(Long.TYPE, Integer.TYPE);
+        dbbCC.setAccessible(true);
+        MethodHandle dbbCCMh = MethodHandles.lookup()
+            .unreflectConstructor(dbbCC)
+            .asType(MethodType.methodType(ByteBuffer.class, long.class, 
int.class));
         return (addr, size, att) -> {
-          dbbCC.setAccessible(true);
           try {
-            return dbbCC.newInstance(Long.valueOf(addr), 
Integer.valueOf(size));
-          } catch (Exception e) {
+            return (ByteBuffer) dbbCCMh.invokeExact(addr, size);
+          } catch (Throwable e) {
             throw new IllegalStateException("Failed to create 
DirectByteBuffer", e);
           }
         };
@@ -90,7 +102,7 @@ public class ByteBufferUtil {
     for (CreatorSupplier supplier : _SUPPLIERS) {
       try {
         creator = supplier.createCreator();
-      } catch (ClassNotFoundException | NoSuchMethodException e) {
+      } catch (ClassNotFoundException | NoSuchMethodException | 
IllegalAccessException e) {
         if (firstException == null) {
           firstException = e;
         }
@@ -108,7 +120,8 @@ public class ByteBufferUtil {
   }
 
   private interface CreatorSupplier {
-    ByteBufferCreator createCreator() throws ClassNotFoundException, 
NoSuchMethodException;
+    ByteBufferCreator createCreator()
+        throws ClassNotFoundException, NoSuchMethodException, 
IllegalAccessException;
   }
 
   private interface ByteBufferCreator {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to