-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add generated code to the psr-0 autoloader section so when optimizing… #15438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add generated code to the psr-0 autoloader section so when optimizing… #15438
Conversation
… the autoloader on a production environment the autoloader will find more classes in its classmap. This should result in fewer file_exists calls and might increase the performance a tiny bit.
Already found one problem with this on a local development environment (but not sure if people will actually run into this):
The last command first clears all those generated classes, but then uses the autoloader to get such a class it just deleted, and then fails. So it might be annoying for local environments to have this, but the solution is to not use an optimized autoloader on local environments. Not sure how many devs use an optimized autoloader during development. So yeah, I don't know... |
@mslabko could you please take a look into this? I'm pretty sure it was considered during autoloader optimization efforts. |
Very curious to see what the final results are here. Thanks @hostep for chasing this down! @orlangur One note here that I'll add…if this was considered during autoloader deployments and intentionally not done then the mention in devdocs telling folks to run the dump-autoload command after DI compilation is pointless and should be removed. |
Hi @hostep, changes must be applied to Please create a separate PR mentioning me. |
Hi @orlangur, as you requested: #16435 Just out of curiosity, all PR's should first be made against 2.2-develop from now on? (well until 2.3 is released I guess). I don't really like this as there is more chance that something might be forgotten to be forward ported that way. But if those are the new rules, I'll try to adhere to them :) |
Yes, since
It's totally opposite actually :) Before such change people were not able to fix issues in latest stable version of Magento - as you remember, it was Regarding you question that generation was previously removed, I have no idea, let's wait for reply from Olga or @mslabko. |
@sidolov : so it has been discussed with @buskamuza why in 64424bc#diff-b5d0ee8c97c7abd7e3fa29b9a27d1780 this was reverted? I just want to be sure that nothing bad could happen by adding this again. |
… the autoloader on a production environment the autoloader will find more classes in its classmap. This should result in fewer file_exists calls and might increase the performance a tiny bit.
Description
Hi!
This PR was triggered by some discussions over here: davidalger/capistrano-magento2#102
When you read the Magento documentation around performance best practices for deploying to a production environment, you'll see something like this:
Since the docs mention you should dump the autoloader after certain php classes got autogenerated, you would assume that the autoloader classmap file (
vendor/composer/autoload_classmap.php
) should have a mapping of those generated classes.But that isn't the case right now.
This PR fixes this.
This should - in theory - increase the autoloading performance ever so slightly on production environments, since the autoloader wouldn't have to go searching for files on the filesystem but would already find them in the classmap and wouldn't have to perform
file_exists
calls for those generated classes.Watch out:
vendor/composer/ClassLoader.php
file and some research on the world wide web."psr-4"
or the"psr-0"
or the"classmap"
section of the"autoload"
section in thecomposer.json
file. It was already suggested to put it in theclassmap
section over here: Improve performances by improving composer autoload #9102 but I'm not sure after reading the composer documentation? It seems to work in all 3 sections while testing, but I've decided to put it in the already being used"psr-0"
section for now.magento/project-community-edition
of which the sources I can't seem to find on github (unless thecomposer.json
file which comes with it is somehow build using thecomposer.json
file of this project?)composer.json
file of already existing projects doesn't get updated automatically after upgrading to a newer version of Magento.var/generation/
Fixed Issues (if relevant)
None that I could find
Manual testing scenarios
bin/magento setup:di:compile
composer dump-autoload -o
vendor/composer/autoload_classmap.php
and see if you can find a mapping to a file insidegenerated/code
, you won't find anycomposer.json
as in this PRcomposer dump-autoload -o
vendor/composer/autoload_classmap.php
and see if you can find a mapping to a file insidegenerated/code
, you will find some referencesContribution checklist