question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Garbage collection pressure created by Method.getParameters()

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gsmetcommented, Aug 13, 2018

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

0reactions
raphwcommented, Aug 31, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid GC pressure in C# and .NET - InfoWorld
When you call the GC.Collect() method, the runtime conducts a stack walk to decide which items are reachable and which are not. This...
Read more >
8 Techniques to Avoid GC Pressure and Improve Performance ...
GC Pressure (garbage collector pressure) is when the GC doesn't keep up with memory deallocations. When the GC is pressured, it will spend...
Read more >
Garbage collection best practices - Unity - Manual
Invoking the garbage collector once per second has a negative effect on performance. If the garbage collector only runs once per minute, it...
Read more >
Optimizing garbage collection in a high load .NET service
This is a known technique. Rather than always creating and discarding new objects, which puts pressure on the garbage collector, we can ...
Read more >
How to determine which method is generating the most garbage
You have no control over garbage collection. finalize(), runFinalizersOnExit() etc are not guaranteed to run.. · 1 · but WHY is that your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found