-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Config][DI] Add ComposerResource to track the runtime engine + deps #21505
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
Conversation
af806a8
to
c71d9ee
Compare
self::$globalVersions = array(); | ||
|
||
foreach (get_loaded_extensions() as $ext) { | ||
self::$globalVersions[$ext] = phpversion($ext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also add the PHP version ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's already there, because among the extensions, there is always "Core", which holds the php version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then OK.
$r = new \ReflectionClass($class); | ||
$v = dirname(dirname($r->getFileName())).DIRECTORY_SEPARATOR; | ||
if (file_exists($v.'composer/installed.json')) { | ||
self::$globalVendors[$v] = @filemtime($v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should rather hash the file. If you rerun composer install
, the file will be touched by composer even when there is no change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the file is touched, we'd better recompute the container once rather than compute the hash again and again IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
namespace Symfony\Component\Config\Resource; | ||
|
||
/** | ||
* ComposerResource tracks the PHP version and composer dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
composer
-> Composer
private $versions; | ||
private $vendors; | ||
|
||
private static $globalVersions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the name of these variables. What about $existingVersions
or $installedVersions
? (same for the $globalVendors
var).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to $runtimeVersions & $runtimeVendors
6f67de1
to
7368e32
Compare
6d7bedd
to
c3e7022
Compare
Any files in vendors are now excluded from tracking, transferring tracking responsibility to the new ComposerResource. This should save a bunch of checks in practice, thus enhance DX. |
b7adaad
to
e930f40
Compare
$driver = 'php'; | ||
} else { | ||
// add the directory itself as a resource | ||
$container->fileExists($dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also rather add $dir.'/'.$configPath
as a resource, as creating the directory and adding files in it could change the config (adding the whole bundle as a resource when <bundle>/Resources
does not exist was a mistake IMO, hurting performance for some people using annotation, and not working fine anyway as it was not detecting the creation of the folder which would change the type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the code is as it is because $configPath
can be a glob/missing subdirs, so the loop just removes "glob+sub-dirs" until a real one is found.
@@ -67,7 +66,7 @@ private function updateDefinition(ContainerBuilder $container, $id, Definition $ | |||
try { | |||
$m = new \ReflectionFunction($factory); | |||
if (false !== $m->getFileName() && file_exists($m->getFileName())) { | |||
$container->addResource(new FileResource($m->getFileName())); | |||
$container->fileExists($m->getFileName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't you replace the file_exists check above instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need: if the file does not exist, we should not track its non-existence
return 'annotation'; | ||
// add the closest existing directory as a resource | ||
$resource = $dir.'/'.$configPath; | ||
while (!is_dir($resource)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only way to reach this code now is that one of the glob calls found something, so we are sure that $dir.'/'.$configPath
exists (and we need to track both its existence and the addition/removal of files in it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, the code change in this file only ensures that only one resource is added. The remaining logic is untouched. I wouldn't change anything else than the double resource issue here.
have you tried profiling the dev environment of Symfony to see the impact this PR has ? |
no, but it's not hard to say that if you happen to have some bundles, everything config-related in them won't be tracked anymore, thus the gain can be huge (esp since this involves i/o). Add autowiring to the mix, which creates resources for every single service when looking for filling type hints - it's even bigger :) |
@nicolas-grekas could you try profiling it to give numbers ? (blame the mail I receive from the Sensiolabs marketing telling me I need to measure things to be able to optimize them... 😄 ) |
e930f40
to
2cf2170
Compare
@stof and you were right to ask, because that needed some polishing :)
|
0a834df
to
53985cc
Compare
1738293
to
4e58b34
Compare
4e58b34
to
a960c76
Compare
Thank you @nicolas-grekas. |
… engine + deps (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [Config][DI] Add ComposerResource to track the runtime engine + deps | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - So that the container is invalidated whenever a new PHP runtime is used, a PHP-extension is added, or vendors are changed. Commits ------- a960c76 [Config][DI] Add ComposerResource to track runtime + vendors
This PR was merged into the 3.3 branch. Discussion ---------- [DI] Use GlobResource for non-tracked directories | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a I noticed that some of my excluded directories are still tracked by the container and changes to files inside them make it recompile. This brought me to the `$trackContents || is_dir($path)` line introduced in #21505. Commits ------- 048eb18 [DI] Use GlobResource for non-tracked directories
So that the container is invalidated whenever a new PHP runtime is used, a PHP-extension is added, or vendors are changed.