Skip to content

Use putIfAbsent in CachedIntrospectionResults.addTypeDescriptor [SPR-12102] #16718

Closed
@spring-projects-issues

Description

@spring-projects-issues

Craig opened SPR-12102 and commented

In #16486, CachedIntrospectionResults was changed to use a ConcurrentHashMap for typeDescriptorCache. This change is definitely positive and had a significant improvement to performance in my testing.

I think that using putIfAbsent (instead of just put) would be a further improvement in the addTypeDescriptor method. Changing:

void addTypeDescriptor(PropertyDescriptor pd, TypeDescriptor td) {
     this.typeDescriptorCache.put(pd, td);
}

to

void addTypeDescriptor(PropertyDescriptor pd, TypeDescriptor td) {
     this.typeDescriptorCache.putIfAbsent(pd, td);
}

should result in less writes to volatile variables improve performance of getTypeDescriptor.

Changing the other ConcurrentHashMap (strongClassCache and softClassCache) put()'s to putIfAbsent()'s would probably also be beneficial.


Affects: 4.1 RC2

Issue Links:

Referenced from: commits af6ef5f, 781a6d2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions