FPS Spike Issue


(Nate ) #1

Hey guys! Some testing for my game I have noticed that every now and then the FPS spikes from 60 to 100, then once it is 100 sometimes it returns to 60 but if it does not everything runs poorly and twitchy. Can anyone provide some insight as to why this might be occurring?

Thank you


(Ultima2876) #2

A few things to check;

-Are you running the game in a browser? Games will generally run at a more even frame rate when ran inside the browser (or in an Adobe Air executable).

-Is it a debug compile? Games will be slower and generally will show inconsistent performance in debug compiles. Make sure to use release compile mode for any kind of performance testing.

-Are you using the debug console? This can cause erratic lag and can throw off performance testing. Try to keep it disabled and use a separate fps counter (or Adobe scout) to get a better idea of performance.


(Zachary Lewis) #3

The Console displays the value of FP.frameRate each update. FP.frameRate is set during Engine.render(), and is based on an averaged value of frame times for each of the frames in the frame list.

The way it is tracked is fairly simple.

  1. Get the elapsed time of the frame.
  2. Add this time to the previous frame times.
  3. Store this time.
  4. If the number of stored frame times is greater than 10, remove the first one added from the list and subtract this time from the previous frame times.
  5. Calculate the average frame time across the last 10 frames.
  6. Convert this number into frames per second.

What this does is provide a sliding window of the 10 most recent frame times. This is the FPS value that you see in the Console.

To answer your question, since this is an average of 10 frame times, you may see the FPS spike if you have a very long frame time get dropped and a very short frame time gets added. Take a look at this:

       f0Β Β  f1   f2   f3   f4Β Β  f5Β Β  f6Β Β  f7Β Β  f8Β Β  f9Β Β  | fSumΒ Β  fAvg  FPS
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”+β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
frame0 80ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms | 240ms  24ms  42 fps
frame1 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16ms  8ms | 152msΒ  15msΒ  66 fps
frame2 16ms 16ms 16ms 16ms 16ms 16ms 16ms 16msΒ  8ms 26ms | 162msΒ  16msΒ  60 fps

In three frames, the frame rate starts at 42 fps, spikes to 66 fps, then returns to 60 fps, even though most of the frames are running at 16ms (60 fps).


(Ultima2876) #4

… Wow, I had no idea that’s how it worked. In Stage3DPunk I have duplicated that behaviour almost exactly (except I believe I’m using the last 60 frames) to give an average frame rate in addition to the β€˜regular’ console one… which seems to also be an average. Haha!


(Nate ) #5

I see, well this has been an education! Thanks guys! Also I fired it up in my internet browser and seems to run just fine constantly!


(John Andersson) #6

When is stage3dpunk ready!?!?!? :smiley:


(Ultima2876) #7

Haha, it’s actually ready for release… right now. Has been for a week or two, but I’ve been so busy with a new job that I haven’t had time to write the β€˜release’ post yet. Hoping to do it this weekend!