DATACMNS-332 - Further performance improvements.
Reverted from ConcurrentHashMap to plain HashMap where concurrency wasn't an issue and profiling showed performance hotspots. Introduced caches for ParameterizedTypeInformation.getComponentType() and the resolved raw type in TypeDiscoverer.
This commit is contained in:
@@ -20,9 +20,9 @@ import static org.springframework.util.ObjectUtils.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
@@ -41,13 +41,13 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
|
||||
private final Constructor<T> constructor;
|
||||
private final List<Parameter<Object, P>> parameters;
|
||||
private final Map<PersistentProperty<?>, Boolean> isPropertyParameterCache = new ConcurrentHashMap<PersistentProperty<?>, Boolean>();
|
||||
private final Map<PersistentProperty<?>, Boolean> isPropertyParameterCache = new HashMap<PersistentProperty<?>, Boolean>();
|
||||
|
||||
/**
|
||||
* Creates a new {@link PreferredConstructor} from the given {@link Constructor} and {@link Parameter}s.
|
||||
*
|
||||
* @param constructor
|
||||
* @param parameters
|
||||
* @param constructor must not be {@literal null}.
|
||||
* @param parameters must not be {@literal null}.
|
||||
*/
|
||||
public PreferredConstructor(Constructor<T> constructor, Parameter<Object, P>... parameters) {
|
||||
|
||||
@@ -167,6 +167,7 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
private final PersistentEntity<T, P> entity;
|
||||
|
||||
private Boolean enclosingClassCache;
|
||||
private Boolean hasSpelExpression;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Parameter} with the given name, {@link TypeInformation} as well as an array of
|
||||
@@ -240,7 +241,12 @@ public class PreferredConstructor<T, P extends PersistentProperty<P>> {
|
||||
* @return
|
||||
*/
|
||||
public boolean hasSpelExpression() {
|
||||
return StringUtils.hasText(getSpelExpression());
|
||||
|
||||
if (this.hasSpelExpression == null) {
|
||||
this.hasSpelExpression = StringUtils.hasText(getSpelExpression());
|
||||
}
|
||||
|
||||
return this.hasSpelExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,8 +29,6 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
@@ -65,7 +63,7 @@ import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?, P>, P extends PersistentProperty<P>>
|
||||
implements MappingContext<E, P>, ApplicationEventPublisherAware, InitializingBean {
|
||||
|
||||
private final ConcurrentMap<TypeInformation<?>, E> persistentEntities = new ConcurrentHashMap<TypeInformation<?>, E>();
|
||||
private final Map<TypeInformation<?>, E> persistentEntities = new HashMap<TypeInformation<?>, E>();
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.core.GenericTypeResolver;
|
||||
class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T> {
|
||||
|
||||
private final ParameterizedType type;
|
||||
private TypeInformation<?> componentType;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ParameterizedTypeInformation} for the given {@link Type} and parent {@link TypeDiscoverer}.
|
||||
@@ -136,7 +137,12 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
|
||||
*/
|
||||
@Override
|
||||
public TypeInformation<?> getComponentType() {
|
||||
return createInfo(type.getActualTypeArguments()[0]);
|
||||
|
||||
if (componentType == null) {
|
||||
this.componentType = createInfo(type.getActualTypeArguments()[0]);
|
||||
}
|
||||
|
||||
return this.componentType;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -51,6 +51,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
private final Map<TypeVariable, Type> typeVariableMap;
|
||||
private final Map<String, TypeInformation<?>> fieldTypes = new ConcurrentHashMap<String, TypeInformation<?>>();
|
||||
|
||||
private Class<S> resolvedType;
|
||||
|
||||
/**
|
||||
* Creates a ne {@link TypeDiscoverer} for the given type, type variable map and parent.
|
||||
*
|
||||
@@ -261,7 +263,12 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
* @see org.springframework.data.util.TypeInformation#getType()
|
||||
*/
|
||||
public Class<S> getType() {
|
||||
return resolveType(type);
|
||||
|
||||
if (resolvedType == null) {
|
||||
this.resolvedType = resolveType(type);
|
||||
}
|
||||
|
||||
return this.resolvedType;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user