I've been basing my plugin design on the default ones from kadokawa, but just realized there's a bit of an inefficiency with the way it works. This is for those plugins that have plugin commands called from the event.
They usually start off like this:
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command === 'keyword') {This means if every plugin aliases pluginCommand, and the first command in the function is to call the aliased function, every single time a plugin command is processed, it's going to go through every single plugin that aliases this function, even if the very first one encountered is the one that needs to run.Let's say the plugin is my Smart Pathfinding plugin, and it's the last one in the user's plugin list of 100 plugins, all that allow plugin commands within the event.
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command.toUpperCase() === 'SMARTPATH') { // do stuff here } };The dev adds a plugin command
The function in my plugin is encountered, which calls the aliased function in the previous plugin, which calls the aliased function in the previous plugin, and so on all the way back to the first of the 100 plugins. When it reaches the end and there are no more aliased functions to call, then it starts working its way back through them in the opposite direction, checking for the command that's actually being run. Finally it bubbles up through the list and ends up back at my plugin. None of the other 99 plugins did anything, and now that mine is back in control I finally do something with it.This is highly inefficient, especially if there are some plugins that have a larger number of commands that they're looking for. I should be doing my checks first to see if MY plugin wants to handle the command, and only if it doesn't, should the aliased function be called. In the example above, if mine is last in the list, it would recognize the command straight away, and there would be no calls to aliased functions at all.
I imagine the time to process is probably quite small, but we have people here who have a hundred or more scripts, and if they do the same in their MV projects with plugins, and likely use plugin commands more often as a result, this could make an impact on performance.
The comparison is like this:
The current way, every time a plugin command is called, it checks conditions in 100 different plugins.
If we only call the aliased function if the current plugin doesn't know about the command, it would average to checking conditions in 50 different plugins, if we make the assumption that each plugin is called with the same frequency.
The dev can then decide, if order is not dictated by plugin dependencies, to put the most commonly used ones towards the bottom of the list, to reduce the potential for performance issues due to the number of plugins being used.
Thoughts?
Or do all of you know this and already call the aliased function as the exception, and I'm just late to the party?
They usually start off like this:
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command === 'keyword') {This means if every plugin aliases pluginCommand, and the first command in the function is to call the aliased function, every single time a plugin command is processed, it's going to go through every single plugin that aliases this function, even if the very first one encountered is the one that needs to run.Let's say the plugin is my Smart Pathfinding plugin, and it's the last one in the user's plugin list of 100 plugins, all that allow plugin commands within the event.
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function(command, args) { _Game_Interpreter_pluginCommand.call(this, command, args); if (command.toUpperCase() === 'SMARTPATH') { // do stuff here } };The dev adds a plugin command
Code:
SmartPath 0 5 3
I imagine the time to process is probably quite small, but we have people here who have a hundred or more scripts, and if they do the same in their MV projects with plugins, and likely use plugin commands more often as a result, this could make an impact on performance.
The comparison is like this:
The current way, every time a plugin command is called, it checks conditions in 100 different plugins.
If we only call the aliased function if the current plugin doesn't know about the command, it would average to checking conditions in 50 different plugins, if we make the assumption that each plugin is called with the same frequency.
The dev can then decide, if order is not dictated by plugin dependencies, to put the most commonly used ones towards the bottom of the list, to reduce the potential for performance issues due to the number of plugins being used.
Thoughts?
Or do all of you know this and already call the aliased function as the exception, and I'm just late to the party?