MZ Slow reading of plugin configuration

Hi!

In the process of creating a plugin, I encountered an unexpected problem: the slow operation of the development environment.

My plugin has a simple, but nested structure. In theory, it can be infinite, but in practice, serious problems begin beyond the third level of nesting.

As an example, I will give the most used structure


Spoiler: Example code
JavaScript:
/*~struct~Card:
 * @param CardType
 * @type select
 * @option Image
 * @value image
 * @option Text
 * @value text
 * @default text
 *
 * @param ImageCard
 * @type struct<ImageCard>
 *
 * @param TextCard
 * @type struct<TextCard>
 *
 * @param Map
 *
 * @param Event
 *
 * @param State
 * @type boolean
 * @default false
 *
 * @param Cards
 * @type struct<Card>[]
 *
 * @param CardWindowSettings
 * @type struct<CardWindowSettings>
 * @default {"Width":"400","Height":"300"}
 */

In general, nothing complicated, the structure is not that big. Both compiled and interpreted languages (and their execution environment) can easily read all such structures with nesting of 3 levels in less than 50ms.

But not RPG Maker MZ.

Inside I see the following structures:

1730842911033.png


Spoiler: Plugins file
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"TextCard\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"


If the game engine or interpreter uses parsing (and I believe it does), such a structure will cause a huge number of problems. It is difficult and takes a long time to read.

Why can't you write and read the plugin structure normally? If you write the data as JSON, there will clearly be fewer problems.

I would like to ask the community what their thoughts are on this matter? Perhaps I am doing something wrong or the game engine is not working correctly. Is there a solution to the problem of long loading?

In any case, I will try to figure it out myself, but I would like to hear an outside opinion
The game I develop for has structures way worse than that, and a lot of them. XD It has absolutely no discernible effect on startup time, and that's the only point at which it would be affected, as it's parsed into more straightforward properties at that point.

Here's an illustrative example; this is about a quarter of our plugins.js.
1730843193447.png
Yes, but I encountered a problem already at this level. And the most annoying thing is that the data is lost as a result. All those structures that I filled in earlier simply refuse to be displayed correctly, although they are in the plugins file and the game interpreter works with them correctly.

I don't understand what the problem is :|
The game I develop for has structures way worse than that, and a lot of them. XD It has absolutely no discernible effect on startup time, and that's the only point at which it would be affected, as it's parsed into more straightforward properties at that point.

Here's an illustrative example; this is about a quarter of our plugins.js.View attachment 322279
depends how you parse the struct as I use a nice recursive one that can
be infinite, but didn't test struct inside a struct calling itself of that struct.

you can use seperate structs to read them thought.
I work with recursion quite well. There are certainly no problems with it in the code itself. But for RMMZ, it may be a problem, apparently.
depends how you parse the struct as I use a nice recursive one that can
be infinite, but didn't test struct inside a struct calling itself of that struct.

you can use seperate structs to read them thought.
Yes, but I encountered a problem already at this level. And the most annoying thing is that the data is lost as a result. All those structures that I filled in earlier simply refuse to be displayed correctly, although they are in the plugins file and the game interpreter works with them correctly.

I don't understand what the problem is :|
What method do you use for extracting the parameters?
It's funny to see such a problem
1730844301042.png
Inside my code I use JSON.parse(). It's all right. It works fast and when needed.

The problem is working with the configuration. RMMZ can't load the configuration properly after working with it for a while.

It opens the empty one without problems. Obviously
What method do you use for extracting the parameters?
This is the function I use for it. It works for any number of nesting levels with no issues:

JavaScript:
TLB.SKABase.parseParameters = function(parameters, destination) {
    for (const param in parameters) {
        const value = parameters[param];
        if (value.length > 0 && !isNaN(value)) {
            if (Math.floor(value) === value) destination[param] = parseInt(value);
            else destination[param] = parseFloat(value);
        } else if (value.length > 0) {
            try {
                destination[param] = JSON.parse(value);
                TLB.SKABase.parseParameters(destination[param], destination[param]);
            } catch (e) {
                destination[param] = value;
            }
        }
    }
};
I understand. I use this parsing in my plugin.
Spoiler: Parsing
JavaScript:
function SafeParse(json) {
    try {
        if (json != null && json)
            return JSON.parse(json);
        return null;
    } catch (e) {
        console.error(`Error parsing JSON data ${e}`);
        return null;
    }
}

Then I use class constructors. I feel more comfortable this way: I describe the structure once and forget about it.

But the problem I'm talking about is related to the editor itself. The rpgmz interface refuses to display my nested structure correctly.

This is the function I use for it. It works for any number of nesting levels with no issues:

JavaScript:
TLB.SKABase.parseParameters = function(parameters, destination) {
    for (const param in parameters) {
        const value = parameters[param];
        if (value.length > 0 && !isNaN(value)) {
            if (Math.floor(value) === value) destination[param] = parseInt(value);
            else destination[param] = parseFloat(value);
        } else if (value.length > 0) {
            try {
                destination[param] = JSON.parse(value);
                TLB.SKABase.parseParameters(destination[param], destination[param]);
            } catch (e) {
                destination[param] = value;
            }
        }
    }
};
I understand. I use this parsing in my plugin.
Spoiler: Parsing
JavaScript:
function SafeParse(json) {
    try {
        if (json != null && json)
            return JSON.parse(json);
        return null;
    } catch (e) {
        console.error(`Error parsing JSON data ${e}`);
        return null;
    }
}

Then I use class constructors. I feel more comfortable this way: I describe the structure once and forget about it.

But the problem I'm talking about is related to the editor itself. The rpgmz interface refuses to display my nested structure correctly.
Ohh you mean in the plugin manager? Yeah, that's just how it works. You need to go down a level in the nesting to see it properly, it's the same on my end.
Yes. Does it also periodically erase your data? Can you give any recommendations on this matter?

It's unpleasant to work like this...
Ohh you mean in the plugin manager? Yeah, that's just how it works. You need to go down a level in the nesting to see it properly, it's the same on my end.
Yes. Does it also periodically erase your data? Can you give any recommendations on this matter?

It's unpleasant to work like this...
Nope, it never erases anything. Can you give me an example?
Unfortunately I can't. In that case I'll analyze
Nope, it never erases anything. Can you give me an example?
I believe loops are always slower than block iterators, because of the constant "if index >= max, end; else, loop"
see if you can process everything by whole blocks.

you mention cards.
is there any image loading? loading whole images in memory always takes time.
In fact, the interpreter will work equally well with both whole blocks and loops. The interpreter used reads the file as a whole, caching, and then executes the code line by line as specified by the logic (constructors, calls, etc.). There is an interpreter that reads the code line by line, but this is not our case.

Anyway, I do use images, but they are loaded only when the plugin is running. We are talking about configuring the configuration by rpgmz itself. In my case, the editor does not work well with opening the configuration and working with it
I believe loops are always slower than block iterators, because of the constant "if index >= max, end; else, loop"
see if you can process everything by whole blocks.

you mention cards.
is there any image loading? loading whole images in memory always takes time.
The problem is you can't fix the editor itself. I don't know how it reads the plugin but clearly it doesn't use JavaScript. Maybe Qt? But the point is you can't change that. There are lots of possibilities, I can only guess. Maybe it reads the file every time when a parameter is a struct. But who knows.

If it can't be fixed maybe you need to consider simplifying it.
Or use external database instead of plugin settings.:rswt2:
Yes. Does it also periodically erase your data?
I helped another person troubleshoot something like this, and it was a bug in the latest version of MZ, 1.8.1.

Try going into Betas in the Steam properties and downgrading the editor to 1.8.0. The other user did that and it immediately saved his changes correctly.
I helped another person troubleshoot something like this, and it was a bug in the latest version of MZ, 1.8.1.

Try going into Betas in the Steam properties and downgrading the editor to 1.8.0. The other user did that and it immediately saved his changes correctly.
Sorry for the late reply.

This happened on version 1.8.0.

I haven't checked on version 1.8.1. Maybe the problem will go away

Original thread: https://forums.rpgmakerweb.com/threads/slow-reading-of-plugin-configuration.173055/