-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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 StandardTypeLocator
for hotspot when the same classes are resolved
#31579
Comments
@xuhaihong using complex SpEL expressions like these has definitely an impact. You could remove the use of SpEL in your key by a |
@snicoll thanks, will take a look at the CacheResolver whether it could help with the key evaluation. For the TypeLocator, I am thinking to maintain a global class cache or possible a singleton customized standardTypeLocator. private Map<String, Class<?>> commonCache = new ConcurrentHashMap<>();
@Override
public Class<?> findType(String typeName) throws EvaluationException {
Class<?> cachedClazz = commonCache.get(typeName);
if(cachedClazz == null) {
cachedClazz = super.findType(typeName);
commonCache.putIfAbsent(typeName, cachedClazz);
}
return cachedClazz;
} |
We've decided to implement that cache out-of-the-box. |
StandardTypeLocator
for hotspot when the same classes are resolved
@jhoeller @snicoll thanks for coming up this change quickly. IIUC, just with the changes in locator might not work in all the scenairos. It should work in the spring context initialization process, as it is cached in the bean factory, while not in the cache scenario. According to the codes in the CacheOperationExpressionEvaluator.createEvaluationContext, the CacheEvaluationContext is recreated each time, and the typeLocator is not shared among those new created instances, that is why I mentioned in the previous comment that, something like a 'global cache' is required. I am thinking something should be changed on the spring cache implementations. Possibly, it should be allowed to set a shareable typeLocator. |
Good point @xuhaihong! Juergen and I looked at it a bit more and concluded that some more work is needed. Please watch #31617 for updates. We appreciate you taking the time to test and report back. |
Hi,
We are using spring cache mechanism in the application, something like below
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.
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.
private final CacheOperationExpressionEvaluator evaluator = new CacheOperationExpressionEvaluator();
I am using an old springframework version 4.3.30, but seems that it faces the same issue in the new spring versions.
Thanks !
The text was updated successfully, but these errors were encountered: