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 01:57:32 UTC

[GitHub] [incubator-seatunnel] legendtkl opened a new pull request, #1882: [Refactor][connector-doris] it's recommanded to use zero-length array parameter for list.toArray method for better performance

legendtkl opened a new pull request, #1882:
URL: https://github.com/apache/incubator-seatunnel/pull/1882

   ## Purpose of this pull request
   minor change
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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


[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

Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #1882:
URL: https://github.com/apache/incubator-seatunnel/pull/1882#discussion_r873143008


##########
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:
   @legendtkl Maybe we need to add a benchmark module, then we can easy to test this kind of case. https://github.com/apache/kafka/tree/trunk/jmh-benchmarks



-- 
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


[GitHub] [incubator-seatunnel] legendtkl closed pull request #1882: [Refactor][connector-doris] it's recommanded to use zero-length array parameter for list.toArray method for better performance

Posted by GitBox <gi...@apache.org>.
legendtkl closed pull request #1882: [Refactor][connector-doris] it's recommanded to use zero-length array parameter for list.toArray method for better performance
URL: https://github.com/apache/incubator-seatunnel/pull/1882


-- 
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


[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

Posted by GitBox <gi...@apache.org>.
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


[GitHub] [incubator-seatunnel] legendtkl 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

Posted by GitBox <gi...@apache.org>.
legendtkl commented on code in PR #1882:
URL: https://github.com/apache/incubator-seatunnel/pull/1882#discussion_r873129758


##########
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 read the code, and you're right. Let's close the PR. @ruanwenjun 



-- 
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