Skip to content

Inefficient reflection operations for destroy method determination #26498

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

Closed
jengebr opened this issue Feb 2, 2021 · 0 comments
Closed

Inefficient reflection operations for destroy method determination #26498

jengebr opened this issue Feb 2, 2021 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@jengebr
Copy link

jengebr commented Feb 2, 2021

Affects: Spring 4.x, 5.x


Problem:
Each call to DisposableBeanAdapter.hasDestroyMethod() for a given bean class will return the same boolean value, however in many cases those invocations issue one or two reflection operations to determine whether those methods exist. In the case of high-volume web applications, request-scoped beans are frequently initialized, resulting in many repetitve reflection operations.

Impact:
In two large, publicly-facing web applications, this problem uses between 1% and 3% cpu, and adds several milliseconds of latency to the server response.

Suggested solution:
We solved this internally by caching the result in a WeakHashMap<String, Boolean> keyed off of the classname. There was some discussion of using the Class rather than the name but we saw slightly better performance with this configuration.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 2, 2021
@jhoeller jhoeller self-assigned this Feb 2, 2021
@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 Feb 2, 2021
@jhoeller jhoeller changed the title Inefficient reflection operations during bean creation Inefficient reflection operations for destroy method determination Feb 2, 2021
@jhoeller jhoeller added this to the 5.3.4 milestone Feb 2, 2021
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x labels Feb 2, 2021
jhoeller added a commit that referenced this issue Feb 14, 2021
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) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants