Hangleton commented on code in PR #13162:
URL: https://github.com/apache/kafka/pull/13162#discussion_r1090683591


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1225,13 +1226,11 @@ public static long tryWriteTo(TransferableChannel 
destChannel,
      * @param length The number of bytes to write
      * @throws IOException For any errors writing to the output
      */
-    public static void writeTo(DataOutput out, ByteBuffer buffer, int length) 
throws IOException {
+    public static void writeTo(DataOutputStream out, ByteBuffer buffer, int 
length) throws IOException {
         if (buffer.hasArray()) {
             out.write(buffer.array(), buffer.position() + 
buffer.arrayOffset(), length);
         } else {
-            int pos = buffer.position();
-            for (int i = pos; i < length + pos; i++)
-                out.writeByte(buffer.get(i));
+            Channels.newChannel(out).write(buffer);

Review Comment:
   Thanks for the follow-up. 
   
   1. This new implementation ignores the `length` argument provided to the 
method if the buffer is not backed by an array. What if `length` does not equal 
the number of remaining bytes on the buffer?
   
   2. Is there an actual optimization offered by calling `write`? The 
implementation of direct buffers use a similar linear iteration. Do you have 
data showing performance improvements with this implementation?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to