TLDR: I've halved my game's CPU usage with one very simple change and I'm rather confused as to why this isn't the default.
So, this is something I've just noticed, and it rather stumped me.
Now, this makes perfect sense to me, but then at the end it goes on to call
I've changed it so that it only calls
Is there something I'm missing here? Is there some reason why it does that which I'm not aware of? Or is it just another case of core script writers not knowing that monitors with refresh rates above 60Hz exist?
So, this is something I've just noticed, and it rather stumped me.
SceneManager.updateMain is a function that's called every frame, using requestAnimationFrame, and is primarily responsible for figuring out how many in-engine frames need to be processed. E.g. if 3/60th of a second passed since the last frame was ran, it will process 3 frames at once, but if less that 1/60th of a second has passed, it will process none. Now, this makes perfect sense to me, but then at the end it goes on to call
this.renderScene()... every time. Even if no frame has actually been processed, so it's just re-rendering everything even if nothing has changed. This means that, for example, on my 165Hz monitor the scene gets re-rendered 165 times per second, even though it only changes 60 times.I've changed it so that it only calls
renderScene if a new frame has actually been produced, and it more than halved my CPU usage (from 16% to 7% in the game's laggiest room) with no apparent ill effects. The game runs the same, the cursor still updates at 165fps since it's handled elsewhere.Is there something I'm missing here? Is there some reason why it does that which I'm not aware of? Or is it just another case of core script writers not knowing that monitors with refresh rates above 60Hz exist?