DEV Community

marius-ciclistu
marius-ciclistu

Posted on • Originally published at marius-ciclistu.Medium on

Maravel Framework 10.60.0

Maravel Framework 10.60.0 avoid run-time reflection on method auto-wire to speed up the boot process


Maravel Framework 10.60.0

After multiple months in which I sought to reduce the reflection usage at run-time in Maravel Framework for improving its boot time , I came up with this POC which introduces 2 new commands, usable in both Maravel Micro-Framework and Maravelith Template:

php artisan autowiring:cache
php artisan autowiring:clear
Enter fullscreen mode Exit fullscreen mode

By default it will precompile at deploy time the method’s definitions from the registered Service Providers (boot method only) and from the used Controllers in the route definitions. Besides those it will also include by default (but it can also be configured in config/app.php):

/**
 * artisan autowiring::cache source paths for public methods (except __construct).
 * The Controllers and Service providers are handled automatically
 */
'autowiring' => [
    [
        'path' => \app()->path() . DIRECTORY_SEPARATOR . 'Console' . DIRECTORY_SEPARATOR . 'Commands',
        'methods' => ['handle', '__invoke'],
    ],
    [
        'path' => \app()->path() . DIRECTORY_SEPARATOR . 'Jobs',
        'methods' => ['handle', '__invoke'],
    ],
    [
        'path' => \app()->path() . DIRECTORY_SEPARATOR . 'Http' . DIRECTORY_SEPARATOR . 'Requests',
        'methods' => ['validator', 'authorize', 'after', 'rules'],
    ],
],
Enter fullscreen mode Exit fullscreen mode

This will not include the __construct methods because those are handled in a different way.

Version 10.60.1 contains also:

php artisan event:cache
php artisan event:clear
Enter fullscreen mode Exit fullscreen mode

for Maravel Micro-Framework, which include events as observers. To auto-discover them, override in EventServiceProvider these methods but only when event:cache is ran on deploy :

/**
 * Determine if events and listeners should be automatically discovered.
 */
public function shouldDiscoverEvents(): bool
{
    return true;
}

/**
 * Determine if events as observers and listeners should be automatically discovered.
 */
public function shouldDiscoverEventsAsObservers(): bool
{
    return true;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)