You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/05/15 07:07:09 UTC

[GitHub] [incubator-seatunnel] ruanwenjun commented on a diff in pull request #1882: [Refactor][connector-doris] it's recommanded to use zero-length array parameter for list.toArray method for better performance

ruanwenjun commented on code in PR #1882:
URL: https://github.com/apache/incubator-seatunnel/pull/1882#discussion_r873120843


##########
seatunnel-connectors/seatunnel-connectors-flink/seatunnel-connector-flink-doris/src/main/java/org/apache/seatunnel/flink/doris/sink/DorisOutputFormat.java:
##########
@@ -207,7 +207,7 @@ public synchronized void flush() throws IOException {
                 result = OBJECT_MAPPER.writeValueAsString(batch);
             }
         } else {
-            result = String.join(this.lineDelimiter, batch.toArray(new CharSequence[batch.size()]));
+            result = String.join(this.lineDelimiter, batch.toArray(new CharSequence[0]));

Review Comment:
   I don't think this change will get a better performance. 
   1. If we use `new CharSequence[0]`, it will create a extra Object array with length `batch.size()` and copy the element from batch to new array. 
   2. If we use `new CharSequence[batch.size()]`, it will just copy the element from batch to the given array.
   ```java
   public <T> T[] toArray(T[] a) {
       if (a.length < size)
           // Make a new array of a's runtime type, but my contents:
           return (T[]) Arrays.copyOf(elementData, size, a.getClass());
       System.arraycopy(elementData, 0, a, 0, size);
       if (a.length > size)
           a[size] = null;
       return a;
   }
   ```
   I don't think this change is necessary unless you can provide a benchmark test result. 



-- 
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: commits-unsubscribe@seatunnel.apache.org

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