Rm Mv - Update functions in my plugin

Hi people!

Well, I have lost account of how many times I rewrote my plugin... But I hope that is the last one!
It is a plugin that adds new sprites to the timer. And I'm unsure about the performance of the update functions of them.

I have made two versions:

1 - Used only the Sprite_Timer and made every other sprite inside. Like the gauge sprite:

this.gauge = new Sprite();
this.gauge.bitmap = new Bitmap(96,48)..

And so on.
There is a maximum of 7 sprites new.
Although I divided it with comments and proper functions names(Sprite_Timer.prototype.gauge...) I think that is a little unorganized.

So here, the Sprite_Timer.prototype.update carries all the update functions to all sprites.

2 - Made a class sprite for every sprite:
Sprite_timerBackground.prototype...
Sprite_timerGauge.prototype...

That seems cleaner to me, and more readable.

But now I have an update function for each sprite.

________________________________________________________________________________

So if before(method 1) I have made an only one check in Sprite_Timer that goes for every sprite:
Code:
Sprite_Timer.prototype.updateBitmap = function() {
    if (this._seconds !== $gameTimer.seconds()) {
        this._seconds = $gameTimer.seconds();
        // update all things that need update
    }
};

Now(method 2), in some sprites, I have this check again in the other update functions, in 3 or more times, because other sprites need the update to, like the gauge one for every second the timer goes.

So, how do you think about that?
Should I stick with method one? Or go with method two for a more readable code?
um... it's advanced than my knowledge
but why not test by yourself with performance
like fps or loading time etc

but... if by my self
I prefer one container
so I can move/scale it around
and other piece just move follow with already setting format
Hello Eliaquim!

Does the second option perform more updates than the first or do they do the exact same updates per second just in different orders? I agree the second one feels more organized but I can't tell whether it's more workload or just a different route to the same solution.

Seems like it could be a big O notation issue but it might aswell not be. I'm just saying the same thing in different ways now aren't I 😅

I'd go with the fastest CPU wise but if there's no meaningful difference I'd go with the most structured/aesthetically pleasing one.
@pasunna thanks for the answer!
The problem for me to test is that my desktop is a good one, so both methods I get 60 fps. =/

@ozubon thanks for the answer!
Does the second option perform more updates than the first or do they do the exact same updates per second just in different orders?
In method one and two they do the exact same updates, but in method two, although they will still do the same updates, they will repeat some codes again for example, we have this function below that have an if statement:

JavaScript:
Sprite_Timer.prototype.updatePerSec = function() {
    if (this._seconds !== $gameTimer.seconds()) {
        this._seconds = $gameTimer.seconds();
        // do things
    }
};

In method 1 there is the update function:
JavaScript:
Sprite_Timer.prototype.update = function() {
    Sprite.prototype.update.call(this);
    this.updatePerSec(); // made the if statement check and update all the things that must be update.

};

In method 2 this would be like this:
JavaScript:
Sprite_Timer.prototype.update = function() {
    Sprite.prototype.update.call(this); // called one time
    this.updatePerSec(); // made the if statement check and update this sprite

};

Sprite_timerGauge1.prototype.update = function() {
    Sprite.prototype.update.call(this); // called two times(repeating)
    this.updatePerSec(); // made the same if statement check again(two times) and update this sprite

};

Sprite_timerGauge2.prototype.update = function() {
    Sprite.prototype.update.call(this); // called tree times(repeating)
    this.updatePerSec(); // made the same if statement check again(3 times) and update this sprite

};

I agree the second one feels more organized but I can't tell whether it's more workload or just a different route to the same solution.
The same here! This is what I want to know xD
Personally, I might be inclined to use the first option, primarily because it means I'm not repeating code and it doesn't offend my way of thinking.

In terms of performance though you're going to be calling the inherited update method on each sprite the same amount of times and provided your custom update code isn't different between the two options these will be run the same number of times as well. All that's different is that you're running the first two lines of updatePerSec an extra 2 times in option 2 - I'm going to hazard a guess and say that the performance differences are negligible.

Keeping your code readable for yourself is incredibly valuable (I know because I'm currently suffering the consequences of not doing this) so if option 2 makes more sense to you I'd say go for it.
@Silva Got it...
but in case of the inherited update, I can do this to prevent it(overwrite the function)?
Code:
Sprite_timerBackground.prototype.update = function(){
return; // or leave in blank...
};
In theory you could. Though the inherited update method (provided you're using Sprite) isn't really doing anything unless it has children (just "forEach" on an empty array), so you'd probably only be saving 1/100th of a millisecond in processing time per update.
Hi people! I ended with the first option after all.
Thank you for all opinions!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/rm-mv-update-functions-in-my-plugin.119475/