Garbage collection pressure created by Method.getParameters()
See original GitHub issueI see that Method.getParameters() is implemented internally in the JDK as a clone() and this generates a lot of garbage collection pressure with Hibernate because of the way that Byte Buddy iterates over method parameters (I think), and also because Hibernate adds static methods to entity proxies with large numbers of parameters.
The offending code path is
ParameterList$ForLoadedExecutable$OfMethod.get(int) line: 320
ParameterList$ForLoadedExecutable$OfMethod.get(int) line: 307
AbstractList$Itr.next() line: 358
TargetMethodAnnotationDrivenBinder.compile(MethodDescription) line: 64
MethodDelegation$ImplementationDelegate$ForStaticMethod.of(MethodList<?>, MethodDelegationBinder) line: 759
MethodDelegation$WithCustomProperties.to(TypeDescription) line: 1223
MethodDelegation$WithCustomProperties.to(Class<?>) line: 1204
MethodDelegation.to(Class<?>) line: 255
the problem being that iterating over all method parameters causes a new instance of ParameterDescription.ForLoadedParameter.OfMethod to be created for each parameter, and each one takes a copy of all the parameter types via the JDK Method implementation. I imagine the iteration could be optimized.
I am using Flight Recorder to look at garbage collection pressure which slows down application startup for large (in this case pathological) apps - i.e. with large numbers of entities. I think if it could be optimized here it would have a beneficial effect on less pathological apps.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:14 (5 by maintainers)

Top Related StackOverflow Question
@raphw I think a good first step from the ByteBuddy POV is to avoid calling
Method#getParameters()more than once per method.I’ll change our implementation to avoid creating a new method delegation per proxy class.
I added a new build plugin to Byte Buddy that caches method return values on an instance. This is now done for all annotations by classes, methods and fields and for declared members of classes. Completed on master.