[SOLVED] Random Frame Spike

Anyone else getting random frame spikes?
This code on an empty simple application and with a 120hz vsynced monitor prints:

    @Override
    public void simpleUpdate(float tpf) {
        super.simpleUpdate(tpf);
        if(tpf*1000>16){
            System.out.println("Spike : "+tpf*1000);
        }
    }
Spike : 16.539299
Spike : 23.974499
Spike : 16.2832
Spike : 16.6841
Spike : 35.360897
Spike : 27.8832
Spike : 19.6469
Spike : 34.481796
Spike : 33.9422
Spike : 28.845499
Spike : 25.912899
Spike : 43.3629
Spike : 42.961
Spike : 41.0638
Spike : 40.8127
Spike : 44.5886
Spike : 28.017199
Spike : 38.6125
Spike : 85.4524
Spike : 40.575798

The problem is most likely on my side, but i don’t know where to start looking. Happens with lwjgl and lwjgl3

1 Like

I’m running an older version of JME… and I have heavily instrumented it to notify me of frame spikes and spit out the app state that caused them. I generally do not see random frame spikes and can always attribute them to one of my app states.

Caveats:
my JME is 3.6 before it was released “sometime”
I run at 60 FPS
most of my watchdogs only trigger after 50 ms.

Note: I also generally consider ‘float’ tpf to be a bit garbage and never use it for anything. So all of my timings are based on System.nanoTime() and so wouldn’t reflect any issues with float-based TPF or how JME tracks time.

I do recommend you switch to a System.nanoTime() per update to see if that aligns with what you see.

Also, have you enabled the detailed profiler to see where the time goes?

1 Like

I used NanoTime in my code. I stripped it down as much i could to have most basic test case.
That’s the frame time graph i recorded. The interval seems to not total random:

JVisualVM might show a slight increase in cpu usage. I say might, because the bump i so little i am not 100% sure. Rather interestingly the frame after the spike makes up for the time mostly. Unfortunately this increases the problem if you are using classical movement*tpf code.

I tried with jm3 3.5.1, 3.6 and 3.6.1. Result are similar.

Nvidia 1080ti
Amd ThreadRipper 1950x

Are you using vsync on or having JME control the frame rate with sleeps? (Just trying to make sure the picture is complete… theoretically, either way can cause catch-up frames.)

vsync

Which OS?

I feel like I’ve seen similar reports about Windows 11 having random spikes unless you perform some magic config or what-not.

Windows 10. Microsoft says my pc is too old for Win11.

I played with the windows graphics settings, “Hardware accelerated GPU scheduling and variable refresh rate”
Enabled both.
. and the spikes are smaller now.

3 Likes