Skip to content
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

[FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter #19485

Merged
merged 1 commit into from Sep 14, 2016

Conversation

Projects
None yet
6 participants
@tgalopin
Copy link
Member

commented Jul 29, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? -
Fixed tickets -
License MIT
Doc PR -

Following the cache warmer for annotations PR (#18533), this PR introduces a cache warmer for YAML and XML Validator configuration.

Based on the PhpArrayAdapter, it uses the naming conventions (Resources/config/validation) 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 annotations PR:

  • validation configuration 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)

This PR also deprecates the framework.validator.cache key in favor of the cache pool introduced in #18544.

@tgalopin tgalopin changed the title [FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter [WIP][FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter Jul 29, 2016

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch 5 times, most recently from 90616f5 to 3b05660 Jul 29, 2016

@tgalopin tgalopin changed the title [WIP][FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter [FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter Jul 30, 2016

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch 3 times, most recently from 2586e76 to 94543a9 Jul 30, 2016

@tgalopin

This comment has been minimized.

Copy link
Member Author

commented Jul 30, 2016

I think this is ready for reviews.

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch 6 times, most recently from 7e9ce05 to 41a9e8f Jul 31, 2016

private $fallbackPool;
/**
* @param array $bundles The application bundles to find validation metadata in.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 1, 2016

Member

out of sync

$adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
$arrayPool = new ArrayAdapter(0, false);
$loader = $this->validatorBuilder->getLoaders();

This comment has been minimized.

Copy link
@nicolas-grekas
$loader = $this->validatorBuilder->getLoaders();
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loader), new Psr6Cache($arrayPool));
foreach ($this->extractSupportedLoaders(array($loader)) as $loader) {

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 1, 2016

Member

no need for the array() wrapper, should be $loaders instead

$metadataFactory = new LazyLoadingMetadataFactory($loader, $this->metadataCache);
if (!$metadataFactory) {
$metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($this->getLoaders()), $this->metadataCache);

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 1, 2016

Member

$loaders = $this->getLoaders();
$metadataFactory = new LazyLoadingMetadataFactory(count($loaders) > 1 ? new LoaderChain($loaders) : $loaders[0], $this->metadataCache);

@@ -138,6 +134,32 @@ private function parseFile($path)
}
/**
* Load the classes YAML descriptions.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 1, 2016

Member

useless phpdoc

@@ -183,6 +185,26 @@ protected function parseFile($path)
}
/**
* Load the classes XML descriptions.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 1, 2016

Member

useless phpdoc

*
* @return array The classes names
*/
public function getClassesNames()

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 1, 2016

Member

getMappedClasses

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch from 41a9e8f to 00f9541 Aug 1, 2016

@tgalopin

This comment has been minimized.

Copy link
Member Author

commented Aug 1, 2016

Updated

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch from 00f9541 to 9092925 Aug 1, 2016

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch 6 times, most recently from 0d20399 to c84db06 Aug 1, 2016

@tgalopin

This comment has been minimized.

Copy link
Member Author

commented Aug 1, 2016

Added tests for the warmer.

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch 2 times, most recently from 522a48a to 5568b27 Aug 1, 2016

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Aug 1, 2016

👍

@mickaelandrieu

This comment has been minimized.

Copy link
Contributor

commented Aug 2, 2016

@tgalopin only have a question about performances.
Nicolas said at SymfonyLive that for now doctrine is a little bit more performant than Symfony cache.
Is this PR intended to improve performance or/and to implement Cache component ?

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Aug 2, 2016

@mickaelandrieu I also said that the difference in terms of performance was negligible and that we shouldn't care. In fact, PhpArrayAdapter is faster than Doctrine (for what it means :) ).

*
* @author Titouan Galopin <galopintitouan@gmail.com>
*/
class ValidatorCacheWarmer implements CacheWarmerInterface

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 2, 2016

Contributor

This cache warmer is very similar to the one you proposed for the serializer, can't we create a new abstract class ?

This comment has been minimized.

Copy link
@tgalopin

tgalopin Aug 2, 2016

Author Member

Even if it seems similar, there is only a few lines that can be shared. I don't think it's worth it.

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 2, 2016

Contributor

I think it can be used in third party libraries and promote cache warmers by making them much easier to use.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 2, 2016

Member

Let's discuss about this in another PR: it's not directly related to this PR and would deserve a dedicated line in the changelog.

*
* @return string[] The classes names
*/
public function getMappedClasses()

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 2, 2016

Contributor

Can we create an interface here as well ?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 2, 2016

Member

Not worth it imho, we don't need to open extensibility here, we have Xml & Yaml loader, let's way until others of the same kind arrive (I doubt any will soon)

*/
private function loadClassesFromXml()
{
// This method may throw an exception. Do not modify the class'

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 2, 2016

Contributor

The classes map should be stored here.

This comment has been minimized.

Copy link
@tgalopin

tgalopin Aug 2, 2016

Author Member

What do you mean?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 2, 2016

Member

@Ener-Getick looks like it is, see below

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 2, 2016

Contributor

You're right sorry, i thought it was the same error than the other pr...

* @param string $phpArrayFile The PHP file where metadata are cached.
* @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached.
*/
public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArrayFile, CacheItemPoolInterface $fallbackPool)

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 2, 2016

Contributor

I only have a last suggestion: shouldn't we inject an instance of PhpArrayAdapter and add a method `getFallbackPool`` to it to avoid duplicating data in several places ?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Aug 3, 2016

Member

I suggest to consider all potential factorizations in the next PR we're talking about just above.

This comment has been minimized.

Copy link
@GuilhemN

GuilhemN Aug 3, 2016

Contributor

Ok fine for me then :)

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch 2 times, most recently from 290db2c to 4365d7c Aug 3, 2016

@tgalopin tgalopin force-pushed the tgalopin:php-array-validator branch from 4365d7c to 6bdaf0b Aug 11, 2016

fabpot added a commit that referenced this pull request Sep 14, 2016

feature #19507 [FrameworkBundle] Introduce a cache warmer for Seriali…
…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
@fabpot

This comment has been minimized.

Copy link
Member

commented Sep 14, 2016

Thank you @tgalopin.

@fabpot fabpot merged commit 6bdaf0b into symfony:master Sep 14, 2016

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Sep 14, 2016

feature #19485 [FrameworkBundle] Introduce a cache warmer for Validat…
…or based on PhpArrayAdapter (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | -
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Following the cache warmer for annotations PR (#18533), this PR introduces a cache warmer for YAML and XML Validator configuration.

Based on the PhpArrayAdapter, it uses the naming conventions (`Resources/config/validation`) 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 annotations PR:

- validation configuration 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)

This PR also deprecates the framework.validator.cache key in favor of the cache pool introduced in #18544.

Commits
-------

6bdaf0b [FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter

@fabpot fabpot referenced this pull request Oct 27, 2016

Merged

Release v3.2.0-BETA1 #20317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.