Skip to content

Expression performance regression due to missing annotation types on context classes #33948

@justinas-dabravolskas

Description

@justinas-dabravolskas

Performance degradation with SpEL expressions occurs when the expression context contains objects lacking annotations.

This issue commonly arises when using Guava collections without JSR-305 annotations at runtime.

The root cause is that org.springframework.core.convert.TypeDescriptor attempts to load annotations for all context classes. If annotations are missing, this leads to classpath scanning during each evaluation, significantly impacting performance. The actual impact varies depending on the classpath and concurrent thread count. In a single threaded testing, it resulted in approximately a twofold decrease in speed. The penalty hit increases with concurrency because of synchronization in java.lang.ClassLoader.loadClass. Although SpEL doesn’t inherently require annotations, TypeDescriptor still loads them by default. Perhaps a variant of TypeDescriptor that omits the annotation loading process could be introduced to address this inefficiency.
Screenshot shows profiler output while evaluating against Guava map in a loop.
Using org.springframework:spring-expression:6.1.15
Screenshot 2024-11-22 at 16 48 03

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions