CPU load and FPS decrease spikes after Java garbage collection

Started by Fataho, July 20, 2017, 18:20:33

Previous topic - Next topic


I am using LWJGL 2 and 3 to generate 3D scene and I get CPU load and FPS decrease (from 60 to 10-20) spikes after Java garbage collection. Does any one had a similar problem? What can cause it?  Here is an image:
Similar situation with LWJGL 2:
These images are from Java VisualVM, where I measure performance.

I managed to remove spikes by adding these VM paramters, (poor hack):
1. I made Heap memory static, so it does not change (first two lines).
2. I made young generation memory only 3m (third line), this forces very frequent, but unnoticable GC.
Ne generation memory is cleared rapidly, however Old generation memory increases very slowly, at some point it should reach limit. This would cause a GC with a lag, however it should happen once in few hours.
Here is an images of Visual GC:
and a CPU and heap usages:


Perhaps you are generating too much garbage?
Hard to say without knowing what you do.


Quote from: Cornix on July 20, 2017, 20:17:15
Perhaps you are generating too much garbage?
Hard to say without knowing what you do.

But spikes appear even heap is practically empty? It does not look like this is the case. Also you can see in plots that heap memory is not that full.



Quote from: bobjob on July 21, 2017, 10:20:39
are you manually calling System.gc() in your code?

No. I do nothing what is related to GC. The spike frequency increases when I load more models into 3d space, since more frequently GC is called. And it does not matter how much memory GC has to clean, even if it is few megabytes, the FPS decrease spike still happens.


I have found the problem. I was creating a FloatBuffer every time I needed a Matrix4f. GC had to remove all created FoatBuffers and that was the reason of spikes.