Expression performance regression due to missing annotation types on context classes #33948
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
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
![Screenshot 2024-11-22 at 16 48 03](https://private-user-images.githubusercontent.com/38216452/389118890-176dbb48-9cf1-43d8-872e-8505817a1aed.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4Njg4OTUsIm5iZiI6MTczODg2ODU5NSwicGF0aCI6Ii8zODIxNjQ1Mi8zODkxMTg4OTAtMTc2ZGJiNDgtOWNmMS00M2Q4LTg3MmUtODUwNTgxN2ExYWVkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDE5MDMxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZjMDExNGVkZDYwYjEwMTViNDZiZmNmN2Q0NzA2YTJkOGJjNmM4NDhmZGE2NjQ0YmM4NmZmMzNmMzgzYzMxZTUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2YiSLYS6wCnoVPBlLnISRqf50QSzDXs1uDI9Rhhqcyo)
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 injava.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
The text was updated successfully, but these errors were encountered: