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

Optimize GenericConversionService.findConverterForClassPair [SPR-6749] #11415

Closed
spring-projects-issues opened this issue Jan 21, 2010 · 3 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 21, 2010

Oliver Becker opened SPR-6749 and commented

The method findConverterForClassPair in GenericConversionService checks interfaces unnecessarily multiple times. This will lead to a performance penalty if no converter can be found.

The point is that addInterfaceHierarchy() adds the entire interface hierarchy to the classQueue (which was done for fixing #10963). However for every processed interface in the queue its entire hierarchy is appended to queue again. In the end a base interface of a multi-level interface hierarchy will be processed multiple times.


Affects: 3.0 GA

This issue is a sub-task of #10963

Issue Links:

Referenced from: commits ad93d20

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

The overhead of processing the same interfaces multiple times is illustrated by the following trace logging when converting a String[] array to a LinkedList:

GenericConversionService - Converting value array<String>['1', '2', '3'] of [TypeDescriptor java.lang.String[]] to [TypeDescriptor java.util.LinkedList<?>]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [[Ljava.lang.String;]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.LinkedList]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.List]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Deque]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Queue]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Cloneable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.AbstractSequentialList]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Queue]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.AbstractList]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.List]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.AbstractCollection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Iterable]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [[Ljava.lang.Object;]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.LinkedList]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.List]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.util.Collection]
TRACE: org.springframework.core.convert.support.GenericConversionService - Found matchable converters org.springframework.core.convert.support.ArrayToCollectionConverter@4104c575
TRACE: org.springframework.core.convert.support.GenericConversionService - Matching org.springframework.core.convert.support.ArrayToCollectionConverter@4104c575
DEBUG: org.springframework.core.convert.support.GenericConversionService - Checking if I can convert [TypeDescriptor java.lang.String] to [TypeDescriptor.NULL]
DEBUG: org.springframework.core.convert.support.GenericConversionService - Yes, I can convert
DEBUG: org.springframework.core.convert.support.GenericConversionService - Matched converter org.springframework.core.convert.support.ArrayToCollectionConverter@4104c575
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converting value '1' of [TypeDescriptor java.lang.String] to [TypeDescriptor java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - Found matchable converters org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
TRACE: org.springframework.core.convert.support.GenericConversionService - Matching org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
DEBUG: org.springframework.core.convert.support.GenericConversionService - Matched converter org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converted to '1'
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converting value '2' of [TypeDescriptor java.lang.String] to [TypeDescriptor java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - Found matchable converters org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
TRACE: org.springframework.core.convert.support.GenericConversionService - Matching org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
DEBUG: org.springframework.core.convert.support.GenericConversionService - Matched converter org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converted to '2'
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converting value '3' of [TypeDescriptor java.lang.String] to [TypeDescriptor java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.io.Serializable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Comparable]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.CharSequence]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - Looking for converters indexed by sourceType [java.lang.Object]
TRACE: org.springframework.core.convert.support.GenericConversionService - and indexed by targetType [java.lang.String]
TRACE: org.springframework.core.convert.support.GenericConversionService - Found matchable converters org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
TRACE: org.springframework.core.convert.support.GenericConversionService - Matching org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
DEBUG: org.springframework.core.convert.support.GenericConversionService - Matched converter org.springframework.core.convert.support.ObjectToStringConverter@203fa5ac
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converted to '3'
DEBUG: org.springframework.core.convert.support.GenericConversionService - Converted to list['1', '2', '3']

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

A second point to be made is that when a superclass is added, its interface hierarchy will likely be a subset (and hence overlap) with the interface hierarchy of the current class.

@spring-projects-issues
Copy link
Collaborator Author

Keith Donald commented

Now in addition to caching converter resolution results we track interfaces we've already attempted so we don't try the same interface again for a given sourceType and sourceType->targetType match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Projects
None yet
Development

No branches or pull requests

1 participant