MV Why is SceneManager.renderScene() called on every requested frame?

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. 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?
I didn't know this, but I'm curious on your answer and what you changed.
as it might be useful.
I'd be interested in implementing this and testing it some more myself, if you don't mind sharing whatever needs to be modified.

edit:
also, if one of our resident Wizards is having to ask, I'm afraid maybe only the other resident Wizards may be able to answer.
Thus, we must summon the wizards and have them convene on this:
@chaucer @Arthran @caethyril
Is it in some ways similar to a parallel event with a wait frame so that it doesn't execute every frame? And, does it have to come from a higher refresh rate of 165Hz, 144Hz, etc. in order to work?

Commenting to follow post.
Commenting to follow post.
You can click the Watch button at the top of the thread.
I'd be interested in implementing this and testing it some more myself, if you don't mind sharing whatever needs to be modified.
At this point I've collected so many high refresh rate-related fixes that I'll probably bundle them all into a plugin if this one turns out not to have any unforeseen problems. But for now do feel free to try this:
JavaScript:
SceneManager.updateMain = function () {
    let newFrame = false;
    if (Utils.isMobileSafari()) {
        this.changeScene();
        this.updateScene();
        newFrame = true;
    } else {
        var newTime = this._getTimeInMsWithoutMobileSafari();
        var fTime = (newTime - this._currentTime) / 1000;
        if (fTime > 0.25) fTime = 0.25;
        this._currentTime = newTime;
        this._accumulator += fTime;
        while (this._accumulator >= this._deltaTime) {
            newFrame = true;
            this.updateInputData();
            this.changeScene();
            this.updateScene();
            this._accumulator -= this._deltaTime;
        }
    }
    if(newFrame) this.renderScene();
    this.requestUpdate();
};
It would actually be quite useful to hear from a bunch of people with different games and systems on whether this breaks anything.

Is it in some ways similar to a parallel event with a wait frame so that it doesn't execute every frame? And, does it have to come from a higher refresh rate of 165Hz, 144Hz, etc. in order to work?
I guess that's some way to describe it - it is a bit like that.
It should help with any refresh rate higher than 60Hz.

To temper expectations a bit: this fix will not increase frame rates in any situation - if a computer can't handle 60 frames, then rendering on each of those makes sense. But it should reduce resource consumption on machines that can handle way more than 60.
You can click the Watch button at the top of the thread.
I'm not skilled enough to follow like a ninja...

Haha. Thanks - I forgot about the button.
It would actually be quite useful to hear from a bunch of people with different games and systems on whether this breaks anything.
Ill take you up on this and let you know if it causes any strange behavior
It would actually be quite useful to hear from a bunch of people with different games and systems on whether this breaks anything.
Currently, no issues.
60Hz refresh rate does not have an impact with normal code or your code with 3-7% CPU usage.

120Hz refresh rate with normal code runs at around 6-10% CPU usage.
120Hz refresh rate with your code runs at around 4-9% CPU usage.

Edit: It does stay at the lower range around 4-6% as I am playing through it more.

There were moments of it staying around 7 and 8% with either code in use so I'm guess when it doesn't need to refresh, the CPU is lower.

*Edit: thoughts to self since Mac did address this already - I just wanted to make sure I also understood it the same way:
(If you are not using higher than 60Hz, there isn't much of a benefit. That being said, those who are running higher refresh rates might benefit at least from what I can see right now with what I am doing. It doesn't hurt to have it in there from what it seems whether the user is running 60Hz or 120Hz, etc.)

Didn't really see any frame drops. Also tested a variable increase count on a parallel event to see if it adds up to 60 after 1 second and it was fine.

I'll leave the code in there and let you know if there are issues later down the road.

Running MV 1.6.2 on Surface Pro 9 i5 (12th Gen) 2.5 Ghz with 16GB RAM.
If you are not using higher than 60Hz, there isn't much of a benefit.
The whole point is that if you're not using a higher than 60hz monitor there's no change 😛

Your monitor is only requesting the refresh 60 times per second if it's a 60hz monitor, so limiting the refreshes to 60 times per second does nothing.

There's not supposed to be any benefit to 60hz monitor systems, it's supposed to reduce CPU usage on systems with faster monitors.
The whole point is that if you're not using a higher than 60hz monitor there's no change 😛

Your monitor is only requesting the refresh 60 times per second if it's a 60hz monitor, so limiting the refreshes to 60 times per second does nothing.

There's not supposed to be any benefit to 60hz monitor systems, it's supposed to reduce CPU usage on systems with faster monitors.
Thanks, Turan!

It was more of a statement for me to make sure I am also understanding since everyone is very helpful (edited the message above to reflect this) - and, it's nice to test it as well for myself. I wasn't trying to present anything new, rather, to make sure that I am also understanding what he did.
Yea, it looks to me like another high-Hz oversight in the core scripts. 👋

That said, I would've expected extra render passes to mostly impact GPU usage rather than CPU. Perhaps the bias is due to PIXI, integrated graphics, and/or plugins.

(@TheAM-Dol - just so you know, tagging people in an edit doesn't send a notification. I magically saw this anyway, though~ 😮‍💨)
tagging people in an edit doesn't send a notification.
Yeah, that's a source of annoyance for me. It also appears that people don't get notified when tagged in a post that requires approval.
tagging people in an edit doesn't send a notification
Oh no 😮
Well, one wizard has seen it...then I must do the summoning ritual again. Correctly this time.
Earth, Wind, Fire, I call upon @Arthran and @chaucer

@Mac15001900 I'll put this in my game as "Mac_IfSh!tBreaks-disableThisFirst"
(hopefully) Soon I'll be doing a lot of playtesting of my game, so I think I'll have a good chance to see where things go wrong, but Caethyril makes it sound like it's just ol dev's forgetting things exist above 60 again.
Clearly they aren't Monster & Redbull fueled twitchy FPS players who need literally every frame.
Hmmm.... this is very interesting! I never really looked too deeply into the core of the game loop logic, but this is definitely a good find, this can greatly improve performance in a lot of cases as it removes unnecessary render calls! I don't see any harm in this? it does not make sense to re-render the last frame if nothing has changed.

But as a side not if you want a REALLY big boost in performance just completely comment out "this.renderScene()" and it free's up the GPU usage by nearly 100%!!! This is something the rpg maker dev's dont want you to know, in fact this thread will probably be deleted shortly, so definitely take this advice while you can! 😮

Clearly I am joking, don't actually do that, cause then your game won't render XD but for reals though, yeah OP's finding seem valid? does this perhaps have any effect on the "fast forward" button of currently running events? I.E. when an event is runnning and you hold the ok button, I know that somewhere it double updates the scene when this occurs, I dont remember exactly where or when, but that's the only thing I could possibly think MAY be an issue, if it is at all.

Alternatively, this code i believe also is only valid for MV users, as MZ handles the render call elsewhere, via a pixi ticker, looking into the code very briefly( I could be wrong, but dont think so ), MZ MAY already account for this, I'd need to test further to confirm this 😛 I'll run a quick test to confirm this right now..

EDIT:

Just tested MZ, and my assumption was correct, because it is in a ticker, it seems this issue is not there in MZ, I ran my monitor in both 144 hz, and 60 hz, and there is never an instance where it renders needlessly.
MZ MAY already account for this,
That's because during development of MZ one of the developers started playing CS:GO competitively.
Thereafter they suddenly learned that things can go faster than 60.
That's because during development of MZ one of the developers started playing CS:GO competitively.
Thereafter they suddenly learned that things can go faster than 60.
anything higher than 60hz refresh rate is simply a marketing gimmick just like Resolutions size, the human eye can't even see more than 60 fps, and it can't see higher than 4k resolution :x

Okay sorry I'll stop joking around and derailing the topic now D; but yeah, I checked the code, and this seems solid, I can't see any issues coming from this. Good find @Mac15001900 ! 🙂

At this point I've collected so many high refresh rate-related fixes that I'll probably bundle them all into a plugin if this one turns out not to have any unforeseen problems.
You should definitely do this! It could benefit a lot of projects! 🙂
anything higher than 60hz refresh rate is simply a marketing gimmick...the human eye can't even see more than 60 fps
It depends on what is changing on the screen.

It depends on what is changing on the screen.

I'm pretty sure he's making a joke, and while hardly scientific:
Nvidia did research into it and found an improvement in games. They are not impartial though, because obviously they sell "more frames".
So I believe Linus (of LTT) challenged the claim in a small sample group (just folks around the office) and found that it's diminishing returns, but definitely anyone playing on a monitor over 60hz could actually perform better.
It seemed the returns fell off over 120/144hz.

Secondly, it's worth mentioning that tons of research went into VR to reduce the simulation sickness that VR causes, and the research showed that at minimum 90hz was required to at least create the illusion of smooth motion in such a confined space, and greater reduces the sickness.
It depends on what is changing on the screen.

oh haha i was just joking xD I mean, I can definitely tell the difference between 30, and 60, and DEFINITELY between 60 and 120+ but I've never seen a 200hz+ monitor irl to compare xD I just remember this argument a long time ago, and idk why it popped into my head when he mentioned 60 fps lol but yeah, you can definitely see more than 60fps, and can definitely see more than 4k, I mean tha last one is relative to the size of the screen I'd say but yeah xD my bad lol

So I believe Linus (of LTT) challenged the claim in a small sample group (just folks around the office) and found that it's diminishing returns, but definitely anyone playing on a monitor over 60hz could actually perform better.
This is true u_u but this was only to detect if there was any benefit to higher fps monitors iirc... I think he did a seperate video to determine if people could actually tell the refresh rates of a monitor( or maybe it was someone else ), and iirc, almost everyone could tell the monitors correctly, therefore proving the human eye can DEFINITELY see more than 60 fps lol. Just it doesn't really benefit you to have a monitor that's like 240hz for gameplay necessarily lol. also for people like me who have poor reflexes anyways I dont even think 30 fps -> 60fps would help me play better, imo you gotta have good reflexes, but this is purely my opinion I've done 0 testing on this XD

Secondly, it's worth mentioning that tons of research went into VR to reduce the simulation sickness that VR causes, and the research showed that at minimum 90hz was required to at least create the illusion of smooth motion in such a confined space, and greater reduces the sickness.

As someone who's both played, and built a VR( prototype ) game, I can DEFINITELY confirm this.. and 90hz.. is really the BARE minimum, I would not recommend playing a vr game at 90hz if it has a lot of motion in it... I'd recommend something more like 120... :/

Original thread: https://forums.rpgmakerweb.com/threads/why-is-scenemanager-renderscene-called-on-every-requested-frame.169623/