[SOLVED] Engine having lagspikes on high-end gaming pc

This did not fix the problem, but without cap i’m getting 250-350 FPS rates, if I cap it to 60 or 90 it works perfect without the lagspikes

1 Like

At 250-350 FPS, you end up rendering frames that never get displayed… 4x as many at the low side.

So at 240 FPS, 3 out of 4 frames are rendered but never get displayed. Useful if you want to do some “raw performance” testing but not a useful way to run a game.

As to the GC, I slightly disagree with @frozenshade. Higher frame rates can cause issues because the concurrent GC can have less CPU time to run while the game is rendering frames it doesn’t need. So it’s not necessarily just delaying the issue to run a lower frame rate. (It probably is but not guaranteed.) It might get rid of it if the garbage issue is lots of short-lived objects (last only a frame) and relatively low count.

I used to run all of my apps un-vsynched by default because it was a nice test. Now I do the opposite and check for performance in different ways. Unrealistically high frame rates can cause various issues that you just don’t have to worry about otherwise.

2 Likes

So when you move or rotate, you multiply by the tpf.

Vector3f delta = new Vector3f();
delta = velocity.mult(tpf);
spatial.move(delta.x, delta.y, delta.z);
//
delta = spin.mult(tpf);
spatial.rotate(delta.x, delta.y, delta.z);

Well, this code isn’t very gc-friendly. The friendly version of the exact same thing would be:

Vector3f delta = new Vector3f();
velocity.mult(tpf, delta); // Or: delta.set(velocity).multLocal(tpf);
spatial.move(delta.x, delta.y, delta.z);
//
spin.mult(tpf, delta); // Or: delta.set(spin).multLocal(tpf);
spatial.rotate(delta.x, delta.y, delta.z);

This way, there is no new object creation but the delta one. However, if this is done on a loop I would recommend to create the delta vector externally to it (so it is not created each time). It can be also done without any extra vector object like:

spatial.move(velocity.x * tpf, velocity.y * tpf, velocity.z * tpf);
//
spatial.rotate(spin.x * tpf, spin.y * tpf, spin.z * tpf);

This way you avoid any vector creation.

Shouldn’t DoEscapeAnalysis with -server force JVM to allocate delta on stack instead of heap?