-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter #19507
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
9f42021
to
8f29578
Compare
f336e86
to
578d101
Compare
$values = $arrayPool->getValues(); | ||
$adapter->warmUp($values); | ||
|
||
foreach ($values as $k => $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.
I guess this is only there in case we are not on a php7 env ?
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.
Exactly :) .
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 think you should add a note specifiing that this should be removed once symfony will only support php >= 7.0
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.
This is not planned and not done anywhere else, and I think when this will happen we will have a lot of work to adapt the whole codebase anyway. I don't think it has much added value, don't you think?
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 should make the transition easier but your argument is true as well so let's not do anything it is just a fallback anyway :)
This looks very promising ☺ thanks ! |
140ef34
to
3dd2989
Compare
This is green and ready for intensive review :) . |
3dd2989
to
cb0f550
Compare
$cache = new Reference('serializer.mapping.cache.symfony'); | ||
} | ||
|
||
if ($cache) { |
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.
null !== $cache
?
1a318f0
to
e9bd2d8
Compare
I updated this PR to fix the potential BC break. |
1a6a85d
to
38ab487
Compare
I fixed the compatibility with older versions of the Serializer. I disabled the cache warmer for old versions of the serializer to avoid problems in cache generation. I think this PR is reaydy for review :) . |
*/ | ||
public function warmUp($cacheDir) | ||
{ | ||
if (!class_exists('Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory') |
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.
You can use the ::class
constant for all those checks.
38ab487
to
37fbb30
Compare
@@ -542,8 +543,18 @@ public function testObjectNormalizerRegistered() | |||
|
|||
public function testSerializerCacheActivated() | |||
{ | |||
if (!class_exists('Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory') |
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.
Can use ::class
too (same in all tests).
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.
Missed this one, thanks :)
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 updated this
👍, good work! |
37fbb30
to
a83ff96
Compare
{ | ||
if (!class_exists(CacheClassMetadataFactory::class) | ||
|| !method_exists(XmlFileLoader::class, 'getMappedClasses') | ||
|| !method_exists(YamlFileLoader::class, 'getMappedClasses')) { |
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 be on one line
a83ff96
to
810f469
Compare
Updated |
ping @symfony/deciders |
Thank you @tgalopin. |
…zer based on PhpArrayAdapter (tgalopin) This PR was merged into the 3.2-dev branch. Discussion ---------- [FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Following the cache warmer for annotations (#18533) and for the validator (#19485), this PR introduces a cache warmer for the Serializer YAML and XML metadata configuration (mainly groups). Based on the PhpArrayAdapter, it uses the naming conventions (Resources/config/serialization) to find the files and compile them into a single PHP file stored in the cache directory. This file uses shared memory on PHP 7. The benefit of this PR are the same than the ones of the previous PR: - serialization metadata cache can be warmed up offline - on PHP 7, there is no need for user extension to get maximum performances (ie. if you use this PR and the other one, you probably won't need to enable APCu to have great performances) - on PHP 7 again, we are not sensitive to APCu memory fragmentation last but not least, global performance is slightly better (I get 30us per class gain in Blackfire) As previous work on the Serializer cache system introduced issues (see 96e418a), it would be interesting to pay careful attention to the backward compatibility during the review (ping @Ener-Getick). Commits ------- 810f469 [FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter
Following the cache warmer for annotations (#18533) and for the validator (#19485), this PR introduces a cache warmer for the Serializer YAML and XML metadata configuration (mainly groups).
Based on the PhpArrayAdapter, it uses the naming conventions (Resources/config/serialization) to find the files and compile them into a single PHP file stored in the cache directory. This file uses shared memory on PHP 7.
The benefit of this PR are the same than the ones of the previous PR:
last but not least, global performance is slightly better (I get 30us per class gain in Blackfire)
As previous work on the Serializer cache system introduced issues (see 96e418a), it would be interesting to pay careful attention to the backward compatibility during the review (ping @Ener-Getick).