Inflector
Inflector copied to clipboard
Prevent lib/helpers.php to be autoloaded in every request
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.
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.
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.