Inflector icon indicating copy to clipboard operation
Inflector copied to clipboard

Prevent lib/helpers.php to be autoloaded in every request

Open javiermarinros opened this issue 2 years ago • 2 comments

Is there any special reason to autoload lib/helpers.php using the "files" method in composer.json? Every request load those functions even when they are not intended to be used, with the performance penalty it implies.

Moving those helpers functions to some class loaded with the same "psr-4" methods as the others should do the job and prevent this issue.

javiermarinros avatar May 26 '22 17:05 javiermarinros

Hi Javier,

With OP cache enabled (and JIT, in the latest versions) the impact on performance should be negligible. Do you have a lot of packages adding "files" autoload? What's the impact of these on your request time? To improve OP cache efficiency, try to disable opcache.validate_timestamps in production. Once the files are cached, PHP will not check the files again.

I could remove the helpers from the autoload, but that would be a breaking change, and I'd rather avoid that unless there's a significant need.

olvlvl avatar May 29 '22 21:05 olvlvl

Hi Olivier,

Thank you for your answer.

Sure, OP cache and JIT help, and we are using preloading too, even opcache.validate_timestamps set to false. But even with all those technologies activated, a small amount of CPU cycles are wasted loading files that, in our case, are used in a really small % of requests.

Of course, this is not a deal breaker, just a small optimization hint. Many other Composer packages are also using using "files" in their autoload config even when a better approach is available, and I think this is something we can improve.

javiermarinros avatar May 30 '22 11:05 javiermarinros