MZ Process Throttling Effort

I have been working on the Jams_Mapper plugin and most of the processing is done when you move between maps (I call them sectors since they are a sector of the $dataMap that gets updated).

I noticed that most of my processing is triggered when I cross from one sector to another in order to refresh the other sectors and there is a visible stutter in the application when you cross this line. In order to combat this issue I was going to implement throttling in my event bus to spread the load across multiple engine ticks and that has improved the issue significantly, but I wanted to know if there were any other tips to spread processing across game engines frames or other solutions in general.

Jams_EventBus.js

JavaScript:
JamsEventBus.prototype.execute = function () {
    if (this.backlog.length > 0) {
        const { eventType, id, arg } = this.backlog[0];
        this.subscriptions[eventType][id](arg);
        this.backlog.shift();
    }
};

JamsEventBus.prototype.execution = function (eventType, arg) {
    var d = Date.now();
    var len = this.backlog.length;
    var interval = 10;
    var loop = 0;
    if (len > 10) {
        loop = Math.ceil(len / 5);
        interval = 0;
    }

    for (let i = 0; i <= loop; i++) {
        if (d - this.tick > interval) {
            this.execute();
            this.tick = d;
        }
    }
};

the ticks are coming from SceneManager.updateFrameCount.

JavaScript:
let _updateFrameCount = SceneManager.updateFrameCount;
SceneManager.updateFrameCount = function () {  
 
   ...
    Jams.EventBus.execution();
    _updateFrameCount();
};
you should make sure that the "stutter" is really caused by processor load and not by something else like load delay, because spreading processes does nothing against load delay.
you should make sure that the "stutter" is really caused by processor load and not by something else like load delay, because spreading processes does nothing against load delay.
I assume you mean file load delay. I guess I could load the files ahead of the time and see if that resolves the issue completely. Right now I load and render 9 map files to make the one map. I could instead load 21 maps into memory, render only 9 into $dataMap, and the other 12 will be ready for rendering when the player crosses the sector line. I will do some tests and see if that helps the issue.
With that detail, there is even a third possibilitiy depending on the size of the maps: RAM use.

If too much RAM is used, Windows automatically switches to using a larger part of virtual memory, which means storing data on the harddrive instead of in RAM.

That of course also slows down everything, but I can't even guess the probability for that as it depends too much on map size and map type.
Just as an info to keep in the back of your mind.

Original thread: https://forums.rpgmakerweb.com/threads/process-throttling-effort.160026/