spatie/laravel-settings

v2.8.0 slows laravel boot time by over 1000ms

gigerIT opened this issue · 10 comments

Hello Spatie Team

Thanks for your great work.
We came across an issue with this package.
As soon as we update from v2.7.0 to v2.8.0 we're getting about 1s slower request for every single route.
Debugbar shows it's consumed by the boot process.

PHP 8.2 Laravel Sail + Octane

We've experienced the same issue. It slows every requests. (@rubenvanassche)

Recorded profile:
image

The problem might be related to https://github.com/spatie/php-structure-discoverer which was added in this PR #198

Screenshot from 2023-03-01 14-39-56

Could you tell me how big the directories are (in files) where you're automatically searching for settings?

For now we're going to revert this change, until we can make structure discoverer more performant. So this should be fixed with 2.8.1.

@rubenvanassche Our /app directory is ~1000 files

Yeah that might be causing problems, structure discoverer is using PHP tokens to parse files with classes etc opposed to Reflection which is a lot quicker but can completely crash your application if a file had a huge syntactic error in it.

Hopefully we can make it a bit faster in the future

@rubenvanassche The project in which i came across the issue has an app directory with 272 files.
I guess disabling autodiscover and adding the classes manually would be fine.
(That's a one time job vs scanning a whole directory on every request)

Yeah, that's a possible solution. Version 2.8.1 reverts the system to the old implementation a bit more prone to errors but it is a factor of magnitudes faster so in the meantime we're going to keep the old discovery code.

What we did here at Spatie was locally caching the discovered classes, because our App dir also became way to large, problem is that you always should remember to recache when adding or changing a settings class.

What about adding it to the artisan command? php artisan make:setting SettingName --group=groupName would also add an entry to the settings array in the config?

Mhh, that's a solution but I think it takes us a bit too far. Let's keep it as is for now