Controller::extend Effects in speed

Hello,

i have a resubale code in almost 6 to 7 controllers. I am thinking to add extension in plugin boot method. will this affect the backend speed or can do it without having any bad effects. There are 6 methods which i can refactor and add to one single plugin.

Thanks alot

Hi @ibrarartisan

Yes, technically, it does impact performance slightly since it will import those classes to perform the extension, even if the request does not ever use those classes.

If you extending many classes many times, then you should extend via the extension container instead. This will reference the class name as a string instead of autoloading it into memory.

Here is an example:

use October\Rain\Extension\Container as Extension;

Extension::extendClass(\Acme\Demo\Controllers\MyController::class, function($controller) {
    // Same as \Acme\Demo\Controllers\MyController::extend(...)
});
1 Like

@daft Thanks alot. will try like this.