MZ Performance drop from 60 to 20fps when loading the game

Hi everyone,
I was working on my game when I noticed a weird problem I haven't noticed before (but I think I was there).

The game is fluid about 8ms when played but if I load a save I can goes to 32ms of latency on the same map,
and if I change map and come back It goes back to a stable 8ms
I made a performance capture to show the difference :

Spoiler: screenshot when loading
when loading
Untitled 1.png


Untitled 2.png


Untitled 3.png

Untitled 4.png

Spoiler: screenshot after changing map
after changing map
Untitled 7.png

Untitled 8.png

Untitled 9.png

Any idea what can cause this problem ? I've never had this on MV only on MZ, the game have better performance on MZ than MV but isn't stable,
seems like something stacking in memory of something..

Also noticed that sometimes fps cap to 30fps when a lot happens, before coming back to 60fps (or sometimes staying to 30fps)
and this only on MZ too, not MV.

Thanks again for the help
Is that a lighting plugin I see, or is that just parallax lighting? Because lighting plugins can be a huge source of fps problems.
Is that a lighting plugin I see, or is that just parallax lighting? Because lighting plugins can be a huge source of fps problems.
yes it is (I tried with shora lightning and community lightning) but I have this problem even without
(made a lot of variation of my project)
also the game is fluid with everything before the loading issue
I don't know what the problem is, but what I'd do to troubleshoot is:

1.) Make sure you start a new game and get to the point where this problem is, then save and load and see if the problem is there. Loading a save from a project you've worked on can cause problems.

2.) See if the problem persists with no plugins. If so, something is wrong with your project itself.
If not, then add 1 plugin at a time back until you get the latency issues again, and that plugin is where your problem is.
You might also run into problems if you are using a plugin to remember event positions when you leave or return to the map or vice-versa you might need to have a plugin that can remember them. Assuming you are using ABS in your project a lot of moving events might cause some latency issues.

@Danatoth had the best advice. Especially, the loading an edited save file.
Hi!
@jackass__ I don't think I have a good knowledge of the performance feature from the Dev Tools, but I believe, you can have a better view of what process is taking most of the scripting time on this screen, and maybe this will help you:
1717879631462.png


As you can see above, there is a list of activity that shows where the ms time is being spent. Maybe this could help you and others to take a look of what is taking so much of your time.

I see that you showed the screenshot on the Summary table. I guess you just need to do it again and click on the "Bottom-Up" table to show the screen above.
I don't know what the problem is, but what I'd do to troubleshoot is:

1.) Make sure you start a new game and get to the point where this problem is, then save and load and see if the problem is there. Loading a save from a project you've worked on can cause problems.

2.) See if the problem persists with no plugins. If so, something is wrong with your project itself.
If not, then add 1 plugin at a time back until you get the latency issues again, and that plugin is where your problem is.
thanks for your time, I did test this before as it seemed save related but no change here
and tried to find the source of this problem but it seemed tricky

You might also run into problems if you are using a plugin to remember event positions when you leave or return to the map or vice-versa you might need to have a plugin that can remember them. Assuming you are using ABS in your project a lot of moving events might cause some latency issues.

@Danatoth had the best advice. Especially, the loading an edited save file.
thanks I was thinking that too because in my mv version the enemies spawned de spawn when loading a save and on mz they stay, but even without even respawn plugin the lag build in weirds ways

Hi!
@jackass__ I don't think I have a good knowledge of the performance feature from the Dev Tools, but I believe, you can have a better view of what process is taking most of the scripting time on this screen, and maybe this will help you:


As you can see above, there is a list of activity that shows where the ms time is being spent. Maybe this could help you and others to take a look of what is taking so much of your time.

I see that you showed the screenshot on the Summary table. I guess you just need to do it again and click on the "Bottom-Up" table to show the screen above.

thanks a lot for this, I was new to it too but it helped me too see a little more
I did the test again and got this

Spoiler: screenshot
Untitled 12.png

seems the most build up came from pixi fonction call (animation frame fired, request animation and ticker_tick)

Any idea what can cause this ? (on mz I didn't changed the pixi version 5.3.12)
Read a lot about gabage collection and tried stuff but didn't solve this, I'm also on nwjs 83 (but same older version didn't work better, they even perform less as expected)

Edit:

Seems related to this "requestanimationframe" as almost all the build up link back to this
but I'm not sure what to do with this
Spoiler: screenshot
Untitled.png
requestanimationframe
That's responsible for rendering the game, so it makes sense that most things go under it.

What would have been more useful is a comparison between your game running normally and the abnormal behaviour after loading it - whatever the difference is will likely point to the culprit.
That's responsible for rendering the game, so it makes sense that most things go under it.

What would have been more useful is a comparison between your game running normally and the abnormal behaviour after loading it - whatever the difference is will likely point to the culprit.
Here I just did that, recorded on the same session :
Spoiler: screenshot
when overload
Untitled 15.png

when fluid
Untitled 16.png

Edit:
This is when I load a map and it shutters and the second screen after changing map and coming back

Also Is there a way to clear the memory when loading the same way it does when changing map ?
Like simulate a map change when loading the game, It wouldn't fix the real issue but could help to limit this problem
(the frustrating thing is the game is really smooth when this problem doesn't occur so it doesn't seems like a classic performance issue, more like something build up when to much occurs)

I've heard long time ago that when mz think your system can't handle the performance, it cap to about 30fps limit to be more digest (could be the problem here?)
Do you know anything about this ? It seems like if I reach a certain point (performance wise) I get this problem, and I've never had this on mv (stable but a lot less fluid maybe due to 64bit of mz)

Here another detailled screen without and with overload on same session:
Spoiler: screenshot
without
Untitled 20.png

with
Untitled 21.png

Also noticed when changing the plugin list (enable or disable a plugin) It doesn't do this loading problem, like changing the plugin list reset the loading (like changing map).
Up

If anyone has an idea I'm still searching but without success
Up

If anyone has an idea I'm still searching but without success
1 - There are a lot of sofiscated ways to know what is going on, by using the Dev tools like we did above. You could search the web ways to understando how to properly use it and then you could understand what is going on.

2 - Another way would be replicate the issue. After that, set a plugin off, and try replicate the issue again. If the issue persist, so it's not that plugin. Keep doing that until you find the plugin which is causing this.
If in the end is not a plugin, then is something to do with some event command.

Either way, it is work to do. And it seems you will not find the problem so easy. Maybe it's easy to fix, but hard to find the problem. In another words, it's something that will take time.

So i suggest you do one of the approachs above, or if you really don't want to do them, at least try upload the project replicating the issue and posting it here, to see if anyone is willing to take a look.

Good luck!
So after a lot of research and trial and error, I found the source of the issue
It seems to be the size of the save file and not the number of animations displayed.

When playing with a lot going on (spawned events for abs) the fps increased but decreased normally when killing the enemies (deleting the events), but when saving the game, on load it seemed to register every events (normal, spawned, deleted or not) and stacking in some cache, so the fps would tank a lot and when changing scene come back to normal.

On mv I didn't had this problem because I was using "TN_LightSaveData_Map.js" by
Terunon, but wasn't on mz because It only worked on mv (and didn't this It was needed this much)

Basically when loading it transfer the player on the same map to reload all events and put back only de remaining ones, to make save files a lot smaller (great for abs and mobile games).

I was able to reuse a part of the code on mz to reload events at start :

Spoiler: code
Scene_Load.prototype.reloadMapIfUpdated = function() {
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
};

It works, but it glitch a little at start with events spawning and despawning visually,
not as clean as TN_LightSaveData_Map.js (who contain this code with some other to retain events and make it more smooth)

Spoiler: TN_LightSaveData_Map.js
//グローバル変数
var TN_gameMap = [];
(function() {
'use strict';
//イベントをセーブから除外
var TN_Game_System_onBeforeSave = Game_System.prototype.onBeforeSave;
Game_System.prototype.onBeforeSave = function() {
TN_Game_System_onBeforeSave.apply(this, arguments);
TN_gameMap = $gameMap._events;
$gameMap._events = [];
};
//除外したイベントデータを復帰
var TN_Scene_Save_onSavefileOk = Scene_Save.prototype.onSavefileOk;
Scene_Save.prototype.onSavefileOk = function() {
TN_Scene_Save_onSavefileOk.call(this);
$gameMap._events = TN_gameMap;
};
//常にリロード時読み込み直す
Scene_Load.prototype.reloadMapIfUpdated = function() {
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
};
//読み込みなおしでイベントが重なるの防止
var TN_Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
TN_Game_Map_setup.apply(this, arguments);
this.moveReloadEvents();
};
//再生成でイベントが重なったとき移動可能な上下左右マスにずらす
Game_Map.prototype.moveReloadEvents = function() {
var events = $gameMap.eventsXy($gamePlayer._newX, $gamePlayer._newY);
var l = events.length;
var ev;
for (var i = 0; i < l; i++){
ev = events;
if (ev._priorityType === 1 && !ev._through){
if (this.isAirshipLandOk(ev.x, ev.y + 1)){
ev.locate(ev.x, ev.y + 1);
continue;
}
if (this.isAirshipLandOk(ev.x - 1, ev.y)){
ev.locate(ev.x - 1, ev.y);
continue;
}
if (this.isAirshipLandOk(ev.x + 1, ev.y)){
ev.locate(ev.x + 1, ev.y);
continue;
}
if (this.isAirshipLandOk(ev.x, ev.y - 1)){
ev.locate(ev.x, ev.y - 1);
continue;
}
}
};
};

})();

Seems like there's a simple fix to use this on mz but I didn't found it yet
Is there something obvious to change to make it compatible with mz ?

Also did this loading heavy save file issue a common known problem ?
(I didn't though it can cause this)
Anyone has an idea how to fix this code on mz ? or maybe an alternative ?
Up
So after a lot of research and trial and error, I found the source of the issue
It seems to be the size of the save file and not the number of animations displayed.

When playing with a lot going on (spawned events for abs) the fps increased but decreased normally when killing the enemies (deleting the events), but when saving the game, on load it seemed to register every events (normal, spawned, deleted or not) and stacking in some cache, so the fps would tank a lot and when changing scene come back to normal.

On mv I didn't had this problem because I was using "TN_LightSaveData_Map.js" by
Terunon, but wasn't on mz because It only worked on mv (and didn't this It was needed this much)

Basically when loading it transfer the player on the same map to reload all events and put back only de remaining ones, to make save files a lot smaller (great for abs and mobile games).

I was able to reuse a part of the code on mz to reload events at start :

Spoiler: code
Scene_Load.prototype.reloadMapIfUpdated = function() {
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
};

It works, but it glitch a little at start with events spawning and despawning visually,
not as clean as TN_LightSaveData_Map.js (who contain this code with some other to retain events and make it more smooth)

Spoiler: TN_LightSaveData_Map.js
//グローバル変数
var TN_gameMap = [];
(function() {
'use strict';
//イベントをセーブから除外
var TN_Game_System_onBeforeSave = Game_System.prototype.onBeforeSave;
Game_System.prototype.onBeforeSave = function() {
TN_Game_System_onBeforeSave.apply(this, arguments);
TN_gameMap = $gameMap._events;
$gameMap._events = [];
};
//除外したイベントデータを復帰
var TN_Scene_Save_onSavefileOk = Scene_Save.prototype.onSavefileOk;
Scene_Save.prototype.onSavefileOk = function() {
TN_Scene_Save_onSavefileOk.call(this);
$gameMap._events = TN_gameMap;
};
//常にリロード時読み込み直す
Scene_Load.prototype.reloadMapIfUpdated = function() {
$gamePlayer.reserveTransfer($gameMap.mapId(), $gamePlayer.x, $gamePlayer.y);
$gamePlayer.requestMapReload();
};
//読み込みなおしでイベントが重なるの防止
var TN_Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
TN_Game_Map_setup.apply(this, arguments);
this.moveReloadEvents();
};
//再生成でイベントが重なったとき移動可能な上下左右マスにずらす
Game_Map.prototype.moveReloadEvents = function() {
var events = $gameMap.eventsXy($gamePlayer._newX, $gamePlayer._newY);
var l = events.length;
var ev;
for (var i = 0; i < l; i++){
ev = events;
if (ev._priorityType === 1 && !ev._through){
if (this.isAirshipLandOk(ev.x, ev.y + 1)){
ev.locate(ev.x, ev.y + 1);
continue;
}
if (this.isAirshipLandOk(ev.x - 1, ev.y)){
ev.locate(ev.x - 1, ev.y);
continue;
}
if (this.isAirshipLandOk(ev.x + 1, ev.y)){
ev.locate(ev.x + 1, ev.y);
continue;
}
if (this.isAirshipLandOk(ev.x, ev.y - 1)){
ev.locate(ev.x, ev.y - 1);
continue;
}
}
};
};

})();

Seems like there's a simple fix to use this on mz but I didn't found it yet
Is there something obvious to change to make it compatible with mz ?

Also did this loading heavy save file issue a common known problem ?
(I didn't though it can cause this)

Still searching for a way to use this code on mz, does anyone knows what I can change inside the code to make it work or an alternative for mz ?
thanks again
Hi @jackass__ ,

I modded your posted plugin code, matching to the MZ-Code-Files-Codes.
But I cannot test it because I am using another SavePlugin in all my projects.
So please test it. If it is still not working on MZ please contact me and I will fix it.
Spoiler: Modded PluginCode
JavaScript:
//グローバル変数
var TN_gameMap = [];
(function() {
'use strict';
//イベントをセーブから除外
var TN_Game_System_onBeforeSave = Game_System.prototype.onBeforeSave;
Game_System.prototype.onBeforeSave = function() {
TN_Game_System_onBeforeSave.apply(this, arguments);
TN_gameMap = $gameMap._events;
$gameMap._events = [];
};
//除外したイベントデータを復帰
var TN_Scene_Save_onSavefileOk = Scene_Save.prototype.onSavefileOk;
Scene_Save.prototype.onSavefileOk = function() {
TN_Scene_Save_onSavefileOk.call(this);
$gameMap._events = TN_gameMap;
};
//常にリロード時読み込み直す
Scene_Load.prototype.reloadMapIfUpdated = function() {
    //if ($gameSystem.versionId() !== $dataSystem.versionId) {
        const mapId = $gameMap.mapId();
        const x = $gamePlayer.x;
        const y = $gamePlayer.y;
        const d = $gamePlayer.direction();
        $gamePlayer.reserveTransfer(mapId, x, y, d, 0);
        $gamePlayer.requestMapReload();
    //};
};
//読み込みなおしでイベントが重なるの防止
var TN_Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
TN_Game_Map_setup.apply(this, arguments);
this.moveReloadEvents();
};
//再生成でイベントが重なったとき移動可能な上下左右マスにずらす
Game_Map.prototype.moveReloadEvents = function() {
var events = $gameMap.eventsXy($gamePlayer._newX, $gamePlayer._newY);
var l = events.length;
var ev;
for (var i = 0; i < l; i++){
ev = events;
if (ev._priorityType === 1 && !ev._through){
if (this.isAirshipLandOk(ev.x, ev.y + 1)){
ev.locate(ev.x, ev.y + 1);
continue;
}
if (this.isAirshipLandOk(ev.x - 1, ev.y)){
ev.locate(ev.x - 1, ev.y);
continue;
}
if (this.isAirshipLandOk(ev.x + 1, ev.y)){
ev.locate(ev.x + 1, ev.y);
continue;
}
if (this.isAirshipLandOk(ev.x, ev.y - 1)){
ev.locate(ev.x, ev.y - 1);
continue;
}
}
};
};

})();

But:

Hi @ EVERYONE,

I have kinda the same issue with dropping FPS,
but this is not Savefile-related.
It is because of having a Lot of MapEvents running on larger Maps.
An having those MapEvents is the main part of this project.

Half-remembering on my webdesign-phase (a long time ago) javascript had
commands for the client browser to change the default-resources-values
for CPU-Priority-Usage
for GPU-Usage
for Media-Cache-Size (like MV ONLY ImageCache.limit = 10 * 1000 * 1000 * 1000; )
for ...

But I don't know those commands any more.
If someone could help me with remembering those commands it would help me ❣️
Firstly, this is a necro and therefore should be it's own new thread. Feel free to link back to this thread as a reference in your new thread.
It is because of having a Lot of MapEvents running on larger Maps.
Map events by themselves have little to no overhead on CPU utilization.
What does cause overhead are parallel events running. If you have a high number of parallel events running on a single map, then you are likely trying to do something very inefficiently, and you should reconsider the logic of how you are handling it.

Also keep in mind that a parallel event will be checked every cycle (frame).
Do your map events need to be checked every single frame of the game? Or is it something that maybe only needs it's information updated once second? Almost never do you need something checked every cycle, therefore it's better to use the "wait" command and add a wait frame to reduce the priority of the event.

I highly recommend redoing your events' logic in order to consolidate and reduce the amount of parallel processing you have going on.
With that said, you can also create an event culler that culls far away events to reduce overhead on a single map. This is a patchwork solution that shouldn't be used as substitution to more performant logical events.
You can set 1 parallel map event (I recommend with a 20 wait frame) checking:
Code:
!$gameMap.event(event ID).isNearTheScreen();
(set in a conditional)
Then you can execute this script to change a self switch on or off:
Code:
$gameSelfSwitches.setValue([map, event, 'self-switch'], true);
By setting a self switch remotely with this command you can create a dummy event that doesn't process anything, and then by checking if it is near the screen, change the self switch to activate an event page that enables the parallel processing, therefore effectively acting as a culler.
Hi @TheAM-Dol,

about yours Firstly:
Firstly, this is a necro and therefore should be it's own new thread. Feel free to link back to this thread as a reference in your new thread.

I responds to @jackass__ (after s/he is waiting nearly a year) with providing theirs wish to have the plugin modded to MZ.

And because maybe s/he knows the answer of my question - related to the same topic, I ask my Question here.


about your "answer":
Yes those are Parallel-processing-MapEvents, too.
And all what you mentioned are workarounds to shrink the resources-usage which I knew ell.
But, those are also shinking the game-design-dev-possibilities a Lot.
So I want to use those MapEvents as they are, but without dropping the FPS.
And by checking taskmanager the RPG-MZ project doesn't use the power of my PC.

.
Okay, well, you're welcome.

RPG Maker is a single-threaded, primarily CPU bound program.
If you want unlimited capabilities use Unreal or Unity.
Or build an engine from scratch.
Necro-post notice: @Nafraju If OP still needs the thread, they can request it to be reopened.

Original thread: https://forums.rpgmakerweb.com/threads/performance-drop-from-60-to-20fps-when-loading-the-game.169348/