Skip to content
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

Refine allocations for improved memory profile when creating a large amount of proxy instances #30499

Closed
mp911de opened this issue May 17, 2023 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@mp911de
Copy link
Member

mp911de commented May 17, 2023

JdkDynamicAopProxy allocates a lot of objects in findDefinedEqualsAndHashCodeMethods and in the constructor via AopProxyUtils.completeProxiedInterfaces (object arrays, collection instances) to compute whether the interfaces implement hashCode/equals methods.

This effect gets visible when creating several thousand (100000s) proxy instances. It would be neat to either have a built-in cache for these values or to be able to override these features so Spring Data could supply values from its caches.

Recorded allocations:

Allocations ProxyFactory

Right now, this isn't possible because the methods are private or being called within the constructor. Also, the implementation of invoke uses several package-private fields of ProxyConfig and other protected components.

We found this aspect while debugging a more significant memory issue via spring-projects/spring-data-commons#2831

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 17, 2023
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 21, 2023
@jhoeller jhoeller self-assigned this Dec 21, 2023
@jhoeller jhoeller added this to the 6.1.3 milestone Dec 21, 2023
@jhoeller
Copy link
Contributor

I've introduced a ProxiedInterfacesCache object that we cache in the AdvisedSupport instance along with the existing method cache there. JdkDynamicAopProxy detects that existing metadata cache for repeated creation of a particular proxy.

It is important to create such repeated proxies from the same AdvisedSupport (ProxyFactory) instance, otherwise the cached metadata won't be preserved. This is true for existing AOP cache arrangements as well, so generally recommendable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants