laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.84k stars 645 forks source link

Add cache check before registering routes #1367

Closed serpentblade closed 8 months ago

serpentblade commented 8 months ago

If routes are already cached, it is not necessary to re-register Horizon routes on every request.

I've found that many Laravel packages don't check for already cached routes and will needlessly re-register routes that already exist in the cache anyway. This reduces boot times in production by ~0.5 ms which adds up when applied to multiple other first-party Laravel packages.

I can open PRs in other projects if this is approved.

driesvints commented 8 months ago

loadRoutesFrom already checks for this. Please check the underlying code.

serpentblade commented 8 months ago

I see that loudRoutesFrom does handle this check already. But that doesn't account for the fact that when routes are cached Routes::group(...) is called only to have nothing happen.

If adding this code is not considered a valid solution, perhaps moving Route::groups(...) into the routes file instead is more acceptable? Ultimately my aim here is to not have this code run at all if it is not required to run.

driesvints commented 8 months ago

Thanks. I'll leave the decision with @taylorotwell but I don't feel this is necessary.

siarheipashkevich commented 7 months ago

@driesvints @serpentblade will be better to move 'Route::group' inside routes files for avoiding extra logic.