im going crazy been weeks since im troublehsooting some spikes ,the spike happens when i switch to a tab and then i return to the game tab, i dont see any bad in the perfomance and not sure how to check the perfomance tool when i switch tabs in google chrome, is makking cazy, please appreciate advices ,guidance or ideas, i want to ge the solution by myself just need a litle push
while im at the game and playing the ms maintains at 5-6ms always for cpu and gpu , the problem happens when i switch to other tab and return back btw
does browser stop or pause requestAnimationFrame? or i need to handle by myself?
The browsers should reduce the number of rendered frames to save battery, and to free CPU/GPU for foreground tabs. They could also pause RAFs while the tab is in the background or even put it into sleep mode completely.
However, is some of my projects I’ve experienced this - after switching to another tab, the rendering is significantly reduced (as expected), but when I return back, I see a rapid motion.
In my case it was my fault - the animation was based on small steps and global time, so when I switched back to the tab after 1 minute, the animation detected a minute of lost animations and tried to compensate this by recreating all skipped animations.
I’m not sure whether your spikes are cased by the same issue, so take it with a grain of salt.
In any case, you may log how often you get RAFs and decide what to do based on this.
Also the spikes might be caused by memory/buffer swapping, so this might be beyond your control from the code.