kano-code icon indicating copy to clipboard operation
kano-code copied to clipboard

Lower than expected FPS on some devices

Open keithclark opened this issue 5 years ago β€’ 2 comments

While testing the editor on a Kindle Fire 8 I noticed that the player only seems to run very simple creations at a max of 30fps when using the Repeat every 1 frames block. The Kindle Fire is more than capable of running at 60fps for basic drawing operations.

Digging into the code I noticed that the rAF callback calculates the delta time between the current and previous frames to determine when to run the next update:

https://github.com/KanoComputing/kano-code/blob/6a544976f1729caffa5cac0d22a1ea5818e64fc4/src/app/lib/modules/control/time.ts#L49-L54

It appears that this code isn't working correctly if rAF callbacks happen at inconsistent intervals. I've done some reading on FPS limiting and it seems that timing errors can be compensated for by changing this:

https://github.com/KanoComputing/kano-code/blob/6a544976f1729caffa5cac0d22a1ea5818e64fc4/src/app/lib/modules/control/time.ts#L52

to this:

startTimestamp = timestamp - (diff % dt);

In my case this works and bumps the frame rate back to 60fps. I also noticed an FPS increase on the PI3 kit. I was going to put a PR together with that change but I'd like your thoughts on this first.

In addition to (or instead of) the above, should there be a special case for when the "Repeat every n frames" interval is set to 1, as this should happen every rAF, regardless of frame deltas?

if (interval === 1) {
  this.frames[loopId] = requestAnimationFrame(func);
  return;
}

Any thoughts / ideas?

keithclark avatar Jan 17 '20 19:01 keithclark