Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#203: Expand caching + general improvements #204

Conversation

marcus-talbot42
Copy link
Contributor

  • Added CanonicalClassNameStore, saving the canonical names of classes, in order to prevent repeated reflective access.
  • Added caching for the selection of valid BeanConverters.
  • Replaced most usages of TreeMap with some form of HashMap, in order to improve performance.

In order to lower the impact of reflective access, we add the
CanonicalClassNameStore, saving the canonical name of classes.

- Created CanonicalClassNameStore
- Updated direct calls to CanonicalClassName#determineCanonicalClassName
 calls to the CanonicalClassNameStore#getOrComputeClassName.
As some BeanConverters should only be added within the relevant scope,
it turned out to be impossible to create a global store. Rather than
that, we create an instance of the BeanConverterStore only in the
CoreConfiguration, and in the first layer OverrideConfiguration.

As the OverrideConfigurations are stripped from the CoreConfiguration
after a successful mapping, this should guarantee that any cache built
up within OverrideConfigurations is not propagated to the cache within
the CoreConfiguration, while allowing the CoreConfiguration to form its
own cache.

- Updated BeanConverterStore, to make it publicly instantiable.
- Updated CoreConfiguration and OverrideConfiguration, to include the
BeanConverterStore.
- Updated AbstractMapStrategy, to use the BeanConverterStore whenever
possible.
As BeanMapper largely doesn't use TreeMaps anymore, for performance
reasons, tests needed to be updated to reflect the unordered nature of
Maps in BeanMapper.
Updated BeanMatchStore, to use faster collections, and remove the need
for (relatively) expensive calls to get the names of classes, by simply
passing the classes themselves.

Since classes have an excellent hashCode-implementation, using classes
as the key for the data store, in combination with the relatively fast
HashMap, makes more sense than using the TreeMap.
Replaced the use of a TreeMap, with the use of a ConcurrentHashMap, for
slightly better performance.
Removed OverrideField, in preparation for the next release.
As using a TreeMap for incomparable elements causes problems, the
MapCollectionHandler now creates a HashMap by default.
Through analysis of what can actually change in the
OverrideConfiguration, it now uses direct references to the collection
in the parent when the collection cannot be edited in the
OverrideConfiguration.
Changed the call to the BeanMapperTraceLogger, to no longer evaluate the
 String before it is logged.
- Updated CoreConfiguration to be able to get a BeanConverter from it.
beanConverterMap.forEach((key, value) -> this.beanConverterMap.put(key, new HashMap<>(value)));
}

public BeanConverter get(Class<?> source, Class<?> target) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is wel beter als de get en de add synchronized zijn.

- Made #get and #add synchronized.
@marcus-talbot42 marcus-talbot42 merged commit 8ec03b1 into master Apr 11, 2024
1 of 2 checks passed
@marcus-talbot42 marcus-talbot42 deleted the improvement/203-Expand-caching-to-include-other-expensive-unchanging-operations branch April 11, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants