-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): fast object copy framework in fury java (#1701)
## What does this PR do? Object deep copy framework in fury java. This PR is only for non-jit serializer - For immutable object such as `String`、`java.time`、`int`、`byte`... return itself. - For mutable object, create new object and set all attributes. - For `pojo` / `bean` object, Use `ObjectSerializer.copy(obj)` to create a new object - For `Arrays`、`Collection`、`Map` object, create new object, traverse the elements, call `fory.copy(obj)` to generate new elements and set them to the new object. Some serializers have special `copy` methods. ## Related issues [[Java] fast object copy framework in fury java #1679](#1679) ## Does this PR introduce any user-facing change? - [x] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? 1. Provide `fury.copy(obj)` interface, which can deep copy the object without serialize / deserialize. For example: ```java User user = new User(); user.setName("a"); // If object contain circular references, please enable copy ref tracking by FuryBuilder#withCopyRefTracking(true) Fury fury = Fury.builder().withLanguage(Language.JAVA).withCopyRefTracking(true).build(); User newUser = fury.copy(user); ``` 2. Provide `FuryCopyable<T>` interface, which can customize the copy method of object. For example: ```java public class User implements Serializable, FuryCopyable<User> { @OverRide public User copy(Fury fury) { // do something System.out.println("object custom copy method"); return newUser; } } ``` ## Benchmark > Device windows 10、12 cores、24G > JDK java version "1.8.0_202" Java(TM) SE Runtime Environment (build 1.8.0_202-b08) Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode) java version "17.0.8" 2023-07-18 LTS Java(TM) SE Runtime Environment (build 17.0.8+9-LTS-211) Java HotSpot(TM) 64-Bit Server VM (build 17.0.8+9-LTS-211, mixed mode, sharing) > Test data see [benchmark code](https://github.com/zhaommmmomo/fury/tree/copy_benchmark/java/fury-benchmark/src/main/java/org/apache/fury/benchmark) ```java int size = 128; int[] intArr = new int[size]; List<Object> list = new ArrayList<>(size); Map<Object, Object> map = new ConcurrentHashMap<>(); BeanA beanA = BeanA.createBeanA(size); // org.apache.fury.test.bean.BeanA for (int i = 0; i < size; i++) { intArr[i] = i; list.add(i); map.put(i, UUID.randomUUID().toString()); } ``` > Test **JMH**: benchmarkMode({Mode.Throughput})、fork(1)、threads(1)、warmup(iterations = 3, time = 1)、measurement(iterations = 5, time = 5)、outputTimeUnit(TimeUnit.SECONDS) *JDK8* *JDK17* **JMH**: benchmarkMode({Mode.AverageTime})、fork(1)、threads(1)、warmup(iterations = 3, time = 1)、measurement(iterations = 5, time = 5)、outputTimeUnit(TimeUnit.MILLISECONDS) **Each benchmark method will be looped 10,000 times** *JDK8* *JDK17*
- Loading branch information
1 parent
a8a140b
commit 64c995d
Showing
40 changed files
with
1,400 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
java/fury-core/src/main/java/org/apache/fury/FuryCopyable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.fury; | ||
|
||
/** | ||
* Fury copy interface. Customize the copy method of the class | ||
* | ||
* @param <T> custom copy interface object | ||
*/ | ||
public interface FuryCopyable<T> { | ||
T copy(Fury fury); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.