Confirm effectiveness of the cache of setter parameters
Closed this issue · 0 comments
yuu-nkjm commented
Effectiveness of setterParameterTypesMap
is confirmed by JMH. Updated code is slower than original one.
columnToAccessorMap.get(columnName).getSetterParameterType()
private final Map<List<String>, List<Class<?>>> setterParameterTypesMap =
new ConcurrentHashMap<>();
private List<Class<?>> getSetterParameterTypes(List<String> columns) {
return setterParameterTypesMap.computeIfAbsent(columns,
k -> columns.stream()
.map(columnName -> columnToAccessorMap.get(columnName).getSetterParameterType())
.collect(Collectors.toList()));
}
original code
final Class<?> setterParameterType = setterParameterTypes.get(i - 1);
final Object value =
resultSetConverter.getValueBySetterParameterType(resultSet, i, setterParameterType);
updated code
final Class<?> setterParameterType = columnToAccessorMap.get(columnName).getSetterParameterType();
// or with cache
// Class<?> setterParameterType = columnToAccessorMap.getSetterParameterType(columnName);
final Object value =
resultSetConverter.getValueBySetterParameterType(resultSet, i, setterParameterType);