Skip to content

Optimize StandardTypeLocator for hotspot when the same classes are resolved #31579

Closed
@xuhaihong

Description

Hi,

We are using spring cache mechanism in the application, something like below

@Cacheable(value = "ProductQueryService.countByParam",
        key = "#param.userId + '#' + #param.category + '#' + T(java.util.Arrays).toString(#param.excludeStatus),
        condition = "T(com.xxxx.CacheConditionUtils).checkIffFieldsExists"
            + "(#param,"
            + " new java.lang.String[] {'userId', 'category','excludeStatus'}")",
        unless = "#result < 10000"
    )

while debugging one performance issue in the production environment, we observed lots of loadClass behaviors due to the using those classes in the condition or key value, which somewhat affects the response time in the concurrent accesses, as the loadClass is marked as synchronized in the classLoader implementation.

image

It is straightforward that, I am thinking to provide a customized typeLocator, which may avoid the loadClass invocations. After digging the codes for a while, it seems no luck to do that. I could see the following possible enhancements.

  1. Remove the final modifier for the evaluator variable in the CacheAspectSupport class, and provide the setter/getter methods to change it, so I could set my own TypeLocator by overriding the createEnavluationContext.
    private final CacheOperationExpressionEvaluator evaluator = new CacheOperationExpressionEvaluator();
  2. The inner class CacheOpearationContext in CacheAspectSupport is already marked protected, while the createEvaluationContext method is marked as private, seems that replacing the private with protected may also be helpful.

I am using an old springframework version 4.3.30, but seems that it faces the same issue in the new spring versions.
Thanks !

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