You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fury.apache.org by "chaokunyang (via GitHub)" <gi...@apache.org> on 2024/07/20 11:01:46 UTC
[I] [Java] Optimize map deep copy performance [fury]
chaokunyang opened a new issue, #1744:
URL: https://github.com/apache/fury/issues/1744
## Is your feature request related to a problem? Please describe.
Map kv items are homogeneous mostly, we can cache the previoues immutable info and reduce type dispatch cost to speed up performance.
## Describe the solution you'd like
<!-- A clear and concise description of what you want to happen. -->
## Additional context
#1679
--
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@fury.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #1744:
URL: https://github.com/apache/fury/issues/1744#issuecomment-2241969284
Same for collection and object array deep copy
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed issue #1744: [Java] Optimize map deep copy performance
URL: https://github.com/apache/fury/issues/1744
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on issue #1744:
URL: https://github.com/apache/fury/issues/1744#issuecomment-2241734857
Excuse me, I didn't understand the issue requirement , do you mean that in code below, we should not invoke the `copyObject`'s `getClassInfo` , but instead cache a final `info` instance in Serializer instance? Is this enough?
```java
Map newMap = fury.copy(oldMap);
@Override
public T copy(T originMap) {
......
copyEntry(originMap, newMap);
return onMapCopy(newMap);
}
protected <K, V> void copyEntry(Map<K, V> originMap, Map<K, V> newMap) {
++ ClassInfo keyClassInfo= classResolver.getOrUpdateClassInfo(entry.getKey().getClass());
++ ClassInfo valueClassInfo= classResolver.getOrUpdateClassInfo(entry.getValue().getClass());
for (Map.Entry<K, V> entry : originMap.entrySet()) {
-- newMap.put(fury.copyObject(entry.getKey()), fury.copyObject(entry.getValue()));
++ newMap.put(fury.copyObject(entry.getKey(),keyClassInfo), fury.copyObject(entry.getValue(), valueClassInfo));
}
}
-- public <T> T copyObject(T ob) {
// We can add a new method with additional parameter classInfo
++ public <T> T copyObject(T obj, ClassInfo classInfo) {
if (obj == null) {
return null;
}
Object copy;
-- ClassInfo classInfo = classResolver.getOrUpdateClassInfo(obj.getClass());
switch (classInfo.getClassId()) {
case ClassResolver.PRIMITIVE_BOOLEAN_CLASS_ID:
case ClassResolver.PRIMITIVE_BYTE_CLASS_ID:
case ClassResolver.PRIMITIVE_CHAR_CLASS_ID:
case ClassResolver.PRIMITIVE_SHORT_CLASS_ID:
case ClassResolver.PRIMITIVE_INT_CLASS_ID:
case ClassResolver.PRIMITIVE_FLOAT_CLASS_ID:
case ClassResolver.PRIMITIVE_LONG_CLASS_ID:
case ClassResolver.PRIMITIVE_DOUBLE_CLASS_ID:
case ClassResolver.BOOLEAN_CLASS_ID:
case ClassResolver.BYTE_CLASS_ID:
case ClassResolver.CHAR_CLASS_ID:
case ClassResolver.SHORT_CLASS_ID:
case ClassResolver.INTEGER_CLASS_ID:
case ClassResolver.FLOAT_CLASS_ID:
case ClassResolver.LONG_CLASS_ID:
case ClassResolver.DOUBLE_CLASS_ID:
case ClassResolver.STRING_CLASS_ID:
return obj;
case ClassResolver.PRIMITIVE_BOOLEAN_ARRAY_CLASS_ID:
boolean[] boolArr = (boolean[]) obj;
return (T) Arrays.copyOf(boolArr, boolArr.length);
......
case ClassResolver.ARRAYLIST_CLASS_ID:
copy = arrayListSerializer.copy((ArrayList) obj);
break;
case ClassResolver.HASHMAP_CLASS_ID:
copy = hashMapSerializer.copy((HashMap) obj);
break;
// todo: add fastpath for other types.
default:
copyDepth++;
copy = classInfo.getSerializer().copy(obj);
copyDepth--;
}
return (T) copy;
}
```
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #1744:
URL: https://github.com/apache/fury/issues/1744#issuecomment-2254031201
If we serialize nested object, the classinfo may be overwrite by other map
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #1744:
URL: https://github.com/apache/fury/issues/1744#issuecomment-2241969076
It's like:
```java
protected <K, V> void copyEntry(Map<K, V> originMap, Map<K, V> newMap) {
ClassResolver classResolver = fury.getClassResolver();
for (Map.Entry<K, V> entry : originMap.entrySet()) {
K key = entry.getKey();
if (key != null) {
ClassInfo classInfo = classResolver.getClassInfo(key.getClass(), keyClassInfoWriteCache);
key = fury.copyObject(key, classInfo.getClassId());
}
V value = entry.getValue();
if (value != null) {
ClassInfo classInfo =
classResolver.getClassInfo(value.getClass(), valueClassInfoWriteCache);
value = fury.copyObject(value, classInfo.getClassId());
}
newMap.put(key, value);
}
}
```
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on issue #1744:
URL: https://github.com/apache/fury/issues/1744#issuecomment-2245319550
> It's like:
>
> ```java
> protected <K, V> void copyEntry(Map<K, V> originMap, Map<K, V> newMap) {
> ClassResolver classResolver = fury.getClassResolver();
> for (Map.Entry<K, V> entry : originMap.entrySet()) {
> K key = entry.getKey();
> if (key != null) {
> ClassInfo classInfo = classResolver.getClassInfo(key.getClass(), keyClassInfoWriteCache);
> key = fury.copyObject(key, classInfo.getClassId());
> }
> V value = entry.getValue();
> if (value != null) {
> ClassInfo classInfo =
> classResolver.getClassInfo(value.getClass(), valueClassInfoWriteCache);
> value = fury.copyObject(value, classInfo.getClassId());
> }
> newMap.put(key, value);
> }
> }
> ```
The `classResolver.getOrUpdateClassInfo(obj.getClass())`already use a Class -> ClassInfo map `classInfoMap` in `ClassResolver.java`, why do we introduce another `classInfoWriteCache` ? I'm sorry, but I'm struggling to understand this part.
```java
@Internal
public ClassInfo getOrUpdateClassInfo(Class<?> cls) {
ClassInfo classInfo = classInfoCache;
if (classInfo.cls != cls) {
classInfo = classInfoMap.get(cls);
if (classInfo == null || classInfo.serializer == null) {
addSerializer(cls, createSerializer(cls));
classInfo = classInfoMap.get(cls);
}
classInfoCache = classInfo;
}
return classInfo;
}
```
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org
Re: [I] [Java] Optimize map deep copy performance [fury]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed issue #1744: [Java] Optimize map deep copy performance
URL: https://github.com/apache/fury/issues/1744
--
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@fury.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fury.apache.org
For additional commands, e-mail: commits-help@fury.apache.org