Skip to content

Commit

Permalink
perf(java): optimize list copy perf (#1769)
Browse files Browse the repository at this point in the history
## 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
```
  • Loading branch information
chaokunyang authored Jul 27, 2024
1 parent beb0797 commit 4cdb9a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Object kryo_copy_list(KryoState.DataState state) {
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(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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"})
Expand Down Expand Up @@ -68,8 +70,16 @@ public T copy(T originCollection) {
}

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);
}
}

Expand Down

0 comments on commit 4cdb9a2

Please sign in to comment.