Description
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.