| Q |
A |
| Bug? |
no |
| New Feature? |
no |
| Improvement? |
yes |
| Framework |
Laravel |
| Framework version |
v10.48.25 |
| Package version |
v4.4.0 |
| PHP version |
8.3.15 |
Actual Behaviour
Running dingo via the cached routes (i.e. php artisan api:cache results in slower execution of the route definitions.
Expected Behaviour
Compared to laravel's native route:cache command which can have up to a 5x performance increase in route parsing time, it appears that caching the routes in dingo degrades performance by around 5-10%, from my testing.
Steps to Reproduce
I followed the testing instructions outlined in this article: https://voltagead.com/laravel-route-caching-for-improved-performance/
Possible Solutions
I believe one of the reasons for this is that in the api:cache implementation it serializes/base64 encodes the result, which takes more resources to decode on every request, compared to native php found in the routes/api.php file.
One simple solution to improve performance is to remove the base64 encoding. This provides a minimal improvement.
Additionally using var_export() to serialise the route config as native php arrays and hydrating this when running the cached route file would give native laravel route cache-esk like performance.
I did investigate how to do this however app('api.router')->setAdapterRoutes() requires the routes to be hydrated with the existing /Illuminate/Route/Route class.
I'd be happy to investigate further and provide an MR if this is something you want to improve.
Edit: Just to add to this, laravel has Illuminate\Routing\CompiledRouteCollection which selectively hydrates the requested route from native php arrays, but im not sure if dingo is compatible with this class.
Actual Behaviour
Running dingo via the cached routes (i.e.
php artisan api:cacheresults in slower execution of the route definitions.Expected Behaviour
Compared to laravel's native
route:cachecommand which can have up to a 5x performance increase in route parsing time, it appears that caching the routes in dingo degrades performance by around 5-10%, from my testing.Steps to Reproduce
I followed the testing instructions outlined in this article: https://voltagead.com/laravel-route-caching-for-improved-performance/
Possible Solutions
I believe one of the reasons for this is that in the
api:cacheimplementation it serializes/base64 encodes the result, which takes more resources to decode on every request, compared to native php found in theroutes/api.phpfile.One simple solution to improve performance is to remove the base64 encoding. This provides a minimal improvement.
Additionally using
var_export()to serialise the route config as native php arrays and hydrating this when running the cached route file would give native laravel route cache-esk like performance.I did investigate how to do this however
app('api.router')->setAdapterRoutes()requires the routes to be hydrated with the existing/Illuminate/Route/Routeclass.I'd be happy to investigate further and provide an MR if this is something you want to improve.
Edit: Just to add to this, laravel has
Illuminate\Routing\CompiledRouteCollectionwhich selectively hydrates the requested route from native php arrays, but im not sure if dingo is compatible with this class.