I have installed 3 libraries with Composer for my PHP project. However, I don't need to have autoloading set up for all 3 libraries, for each page load.
Is there a way to only set up auto-loading for a library when I need it? So rather than calling vendor/autoload.php
on every page load, I can call vendor/autoload-swiftmailer.php
for example?
It makes no sense to selectively use differently configured autoloaders when using Composer. Here's why:
Optimizing for performance is a good thing. But you need to have measurements in order to see where time is being used, and you'd need to profile your code in order to get an idea where it is useful to improve performance. A function call that can be reduced from 25 milliseconds to 22 milliseconds is not a worthy goal - unless it is called 100.000 times in a loop.
I'm pretty sure autoloading is not the root of any performance problem - but dealing with three or more different autoload configurations will create a maintenance problem in the long run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With