Skip to content

[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

Merged
merged 1 commit into from
Sep 14, 2016

Conversation

tgalopin
Copy link
Contributor

@tgalopin tgalopin commented Aug 2, 2016

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).

@tgalopin tgalopin changed the title [FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter [WIP][FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter Aug 2, 2016
@tgalopin tgalopin force-pushed the php-array-serializer branch from 9f42021 to 8f29578 Compare August 2, 2016 09:50
@nicolas-grekas nicolas-grekas changed the title [WIP][FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter [FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter Aug 2, 2016
@tgalopin tgalopin force-pushed the php-array-serializer branch 3 times, most recently from f336e86 to 578d101 Compare August 2, 2016 10:54
$values = $arrayPool->getValues();
$adapter->warmUp($values);

foreach ($values as $k => $v) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly :) .

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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 :)

@GuilhemN
Copy link
Contributor

GuilhemN commented Aug 2, 2016

This looks very promising ☺ thanks !

@tgalopin tgalopin force-pushed the php-array-serializer branch 7 times, most recently from 140ef34 to 3dd2989 Compare August 3, 2016 09:24
@tgalopin
Copy link
Contributor Author

tgalopin commented Aug 3, 2016

This is green and ready for intensive review :) .

@tgalopin tgalopin force-pushed the php-array-serializer branch from 3dd2989 to cb0f550 Compare August 3, 2016 13:06
$cache = new Reference('serializer.mapping.cache.symfony');
}

if ($cache) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null !== $cache?

@tgalopin tgalopin force-pushed the php-array-serializer branch 4 times, most recently from 1a318f0 to e9bd2d8 Compare August 16, 2016 17:10
@tgalopin
Copy link
Contributor Author

I updated this PR to fix the potential BC break.

@tgalopin tgalopin force-pushed the php-array-serializer branch 4 times, most recently from 1a6a85d to 38ab487 Compare August 17, 2016 12:54
@tgalopin
Copy link
Contributor Author

tgalopin commented Aug 17, 2016

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')
Copy link
Member

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.

@tgalopin tgalopin force-pushed the php-array-serializer branch from 38ab487 to 37fbb30 Compare August 17, 2016 13:25
@@ -542,8 +543,18 @@ public function testObjectNormalizerRegistered()

public function testSerializerCacheActivated()
{
if (!class_exists('Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory')
Copy link
Member

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one, thanks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this

@dunglas
Copy link
Member

dunglas commented Aug 17, 2016

👍, good work!

@tgalopin tgalopin force-pushed the php-array-serializer branch from 37fbb30 to a83ff96 Compare August 17, 2016 14:34
{
if (!class_exists(CacheClassMetadataFactory::class)
|| !method_exists(XmlFileLoader::class, 'getMappedClasses')
|| !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
Copy link
Member

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

@tgalopin tgalopin force-pushed the php-array-serializer branch from a83ff96 to 810f469 Compare August 17, 2016 18:09
@tgalopin
Copy link
Contributor Author

Updated

@nicolas-grekas
Copy link
Member

ping @symfony/deciders

@fabpot
Copy link
Member

fabpot commented Sep 14, 2016

Thank you @tgalopin.

@fabpot fabpot merged commit 810f469 into symfony:master Sep 14, 2016
fabpot added a commit that referenced this pull request Sep 14, 2016
…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
@tgalopin tgalopin deleted the php-array-serializer branch September 15, 2016 13:06
@fabpot fabpot mentioned this pull request Oct 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants