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

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git


The following commit(s) were added to refs/heads/main by this push:
     new 4cdb9a2a perf(java): optimize list copy perf (#1769)
4cdb9a2a is described below

commit 4cdb9a2ad68d718d57c0dcabb187b2d18a61ae38
Author: Shawn Yang <[email protected]>
AuthorDate: Sat Jul 27 16:53:27 2024 +0800

    perf(java): optimize list copy perf (#1769)
    
    ## What does this PR do?
    
    optimize list copy perf
    
    ## Related issues
    Closes #1743
    
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fury/issues/new/choose) describing the
    need to do so and update the document if necessary.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    
    ## Benchmark
    
    ```
    
    Benchmark                     (bufferType)  (references)   Mode  Cnt        
Score         Error  Units
    CopyBenchmark.fury_copy_list         array         false  thrpt    3  
3942934.726 ± 2361062.022  ops/s
    CopyBenchmark.kryo_copy_list         array         false  thrpt    3   
910135.076 ±  914811.092  ops/s
    
    Benchmark                     (bufferType)  (references)   Mode  Cnt        
Score         Error  Units
    CopyBenchmark.fury_copy_list         array         false  thrpt    3  
5797916.088 ± 3054882.337  ops/s
    CopyBenchmark.kryo_copy_list         array         false  thrpt    3   
942358.419 ±  942454.986  ops/s
    ```
---
 .../main/java/org/apache/fury/benchmark/CopyBenchmark.java   |  2 +-
 .../fury/serializer/collection/CollectionSerializer.java     | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git 
a/java/benchmark/src/main/java/org/apache/fury/benchmark/CopyBenchmark.java 
b/java/benchmark/src/main/java/org/apache/fury/benchmark/CopyBenchmark.java
index 90f7025e..42309674 100644
--- a/java/benchmark/src/main/java/org/apache/fury/benchmark/CopyBenchmark.java
+++ b/java/benchmark/src/main/java/org/apache/fury/benchmark/CopyBenchmark.java
@@ -75,7 +75,7 @@ public class CopyBenchmark {
   public static void main(String[] args) throws IOException {
     if (args.length == 0) {
       String commandLine =
-          "org.apache.fury.*CopyBenchmark.*map -f 1 -wi 3 -i 3 -t 1 -w 2000s 
-r 2s -rf csv "
+          "org.apache.fury.*CopyBenchmark.*list -f 1 -wi 3 -i 3 -t 1 -w 2s -r 
2s -rf csv "
               + "-p bufferType=array -p references=false";
       System.out.println(commandLine);
       args = commandLine.split(" ");
diff --git 
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializer.java
 
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializer.java
index 0b575e51..bc94dde1 100644
--- 
a/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializer.java
+++ 
b/java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializer.java
@@ -22,6 +22,8 @@ package org.apache.fury.serializer.collection;
 import java.util.Collection;
 import org.apache.fury.Fury;
 import org.apache.fury.memory.MemoryBuffer;
+import org.apache.fury.resolver.ClassInfo;
+import org.apache.fury.resolver.ClassResolver;
 
 /** Base serializer for all java collections. */
 @SuppressWarnings({"unchecked", "rawtypes"})
@@ -68,8 +70,16 @@ public class CollectionSerializer<T extends Collection> 
extends AbstractCollecti
   }
 
   public void copyElements(T originCollection, Collection newCollection) {
+    ClassResolver classResolver = fury.getClassResolver();
     for (Object element : originCollection) {
-      newCollection.add(fury.copyObject(element));
+      if (element != null) {
+        ClassInfo classInfo =
+            classResolver.getClassInfo(element.getClass(), 
elementClassInfoHolder);
+        if (!classInfo.getSerializer().isImmutable()) {
+          element = fury.copyObject(element, classInfo.getClassId());
+        }
+      }
+      newCollection.add(element);
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to