Maravel Framework 10.63 avoids runtime reflection on DI
marius-ciclistu

marius-ciclistu @marius-ciclistu

About: Creator of MaravelQL Definer of Equivalent constant engine torque Creator of maravel-rest-wizard / laravel-crud-wizard-free lib suites Creator of Maravel-Framework Maravel Maravelith

Location:
Romania
Joined:
Nov 17, 2025

Maravel Framework 10.63 avoids runtime reflection on DI

Publish Date: Feb 17
0 0


Maravel-Framework DI autoriring:cache

Maravel-Framework 10.63 improves the autowiring:cache command to include also constructors. Until this version, only the methods like boot, handle, __invoke and the controllers’ route methods were cached to not use reflection at runtime.

Additional directories and classes can be cached via config/app.php

/**
 * artisan autowiring:cache source paths for public methods (except __construct which is implicitly handled)
 * The CallQueuedHandler, controllers, middlewares, bult-in commands, service providers
 * + other classes resolved from Container during the autowiring:cache command execution are handled automatically
 * 'path' can be a single class or a directory
 */
'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

Benchmark for “Hello world” with optimizations (except Lumen):

This actual improvement is not visible in a single controller and route scenario but for complex projects where many classes are instantiated, this feature is a must.

Note:

Both Maravelith and Maravel templates can take advantage of this improvement.

If the concrete has contextual bindings (and constructor parameters) the old reflection is still used.

If the parameters are sent as array list , concrete will be instantiated directly with them. On failure, it will default to the old reflection but at the cost of building an Exception.

If the first parameters are sent as list and the last one(s) need to be auto-resolved, the above exception scenario will happen, which is slow. Always send all parameters as list, in the right order.

The method autowiring ( so non __construct ) does not support parameters as list!

Comments 0 total

    Add comment