Performance downside of loading plugin in a certain way

Does anyone on here know if there is any performance downside on loading plugins when the plugins are inside another folder to maintain the structure of the code it is distributed under?

What I mean is this.
I create a plugin like so:

bin\cake bake plugin Code\MyPlugin

The plugin is created inside:

plugins/Code/MyPlugin

I then create other things for that plugin such as helpers, components and behaviors etc:

When these plugins are pushed to GitHub the plugin can then be installed via composer like:

composer require code/my-plugin

Then the plugin can be loaded:

bin\cake plugin load Code/MyPlugin

And the plugin is loaded. All is working fine.

Where the plugin is required I then add it, in the UsersTable for example:

$this->addBehavior(‘Code/MyPlugin.Behavior1’, );
$this->addBehavior(‘Code/MyPlugin.Behavior2’, );

A behavior which resides inside the App itself instead of a plugin would be loaded as:

$this->addBehavior(‘Behavior’, );

So, my question is this:

Is there any downside in terms of performance,
when loading code which resides inside a plugin such as in:

$this->addBehavior(‘Code/MyPlugin.Behavior3’, );

As opposed to loading in any other way?

Am using CakePHP version 4.3 by the way.

The reason why I ask this is because the site is loading really slow. The Users/login page is taking close to 3 seconds which is far too long. So, am not sure if the problem is being caused because of the way the plugins which the App is using resides in a structure as explained above. The same Users/login page, exactly same code functionality, loads in less than 30 seconds with debug enabled. But the difference is only that this other Users/login page uses CakePHP version 4.2 so am wondering what is causing the problem.

Any input would be welcome.

Thanks

The only difference between a composer installed plugin and a “private” installed plugin is the fact, that you need to define the composer autoloading config in the composer.json (which the cake bake plugin MyPlugin CLI already does for you)

See Plugins - 4.x

Other than that both install methods are identical because your plugin files are just located in the filesystem (private plugins in plugins and vendor plugins in vendor/your-handle/your-repo)

If you have performance problems you should enable the debugkit and check the Timer and SqlLog Tab to see if its either

  • something in your code or
  • some query which is misbehaving

But there are many other reasons why a live app doesn’t perform as you expect it compared to a local setup (like SSD vs HDD hardware, a misconfigured SQL Server or anything else the system admin of your live machine can/should help you with)

Hi @KevinPfeifer, thanks for the input man. Much appreciated.

I am still not sure what is causing the problem, but thanks to your comment I went and checked again on the docs and realized that some of the plugins which I am using did not even have to be loaded because I am only interested in using the Behavior/Helper/Component classes from the plugin etc.

I have DebugKit installed and checked everything and cannot see anything wrong. I even baked an entire demo app, CakepHP version 4.3 just to test loading time and its still super slow compared to other apps which I have running else. I will continue investigating.

Thanks again man.

Well are you able to give more details on what exactly is slow? Maybe show some screenshots of the Timer and SqlLog tab?

Also - If you believe its the behavior why not just remove it and check again.

1 Like

Or if you can reproduce the slow performance you can use a profiling tool like xdebug or SPX to get more detailed data on which functions are slow.

Kevin, I would do that but I just don’t have the time right now. And its not the behavior. Right now am converting most of the code which my apps use to plugins which can be installed via composer.