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

This thread has been reopened at OP’s request as they still need the thread.
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 ❣️

Hi, thanks for this, I'll try it (I made a patch myself but I will compare it with this)

As for your fps drops due to map events, I don't have an answer but I'm still trying stuff out and I'm interested to this issue (making some kind of vampire survivor abs type of game) so any lead is good to take
(already use some of the ways mentioned by TheAm-Dol with nrp plugins but It doesn't solve this, also tried lots of things with nwjs and pixi updates)
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 ❣️
Hi again, did u find anything regarding those fps drops when having lots of events ? I'm having the same issue and making something close to a vampire survivor game this could really help.
Thanks again !
So what's the situation now? Still have fps drop after loading a save?
So what's the situation now? Still have fps drop after loading a save?
So I've found some kind of work around for the load issue, but still experiencing lag when having lots of events on map and I was curious about @Nafraju leads on how to improve performance and stability (already upgraded nwjs and tried pixi too)

​

​

​

I see. I don't know if events alone will cause lags. I've tried like 100 normal events on the same map but there's no visible slow down. But what if you have a thousand?

There are many operations are very slow.
1. Canvas based filters, I don't think community lighting uses them last time I checked, but I'm not sure if there are other plugins.
2. Other canvas based drawing. Like blt, drawText, etc. Because they require texture updating, so if you have many of them it could be slow.
3. Creating bitmaps on the fly. If a plugin creates temporary images very frequently it can be very slow.
4. Loading images on the fly. Like 3, but it is unlikely, check just in case.
5. Path finding, for example, if 1000 events try to find a path, each needs to check other 999 events to see if they block the path. Also if the map is very big, they may also need to check many tiles.
6. Other filters, blend effects, etc. WebGl shaders can be fast, but they don't do magic, if there are too many of them.
7. It is unlikely, but if you print something on the console every frame it can be very slow. Reading and writing files can also be slow, even if the files are stored locally.
So after having working a lot on the game and forgetting about this issue (always tested with new game instead of loading), seems like there's still a performance issue when loading a save.

I start new game the game runs smoothly, I save, I load the save the game stutter (constant), I change map and come back It runs smoothly again.

Maybe the save store too much information that get cleared when changing maps ?
Any idea on a possible fix or plugin that manage heavy save files ?

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