This PR was merged into the 4.3 branch.
Discussion
----------
revert #30525 due to performance penalty
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR |
This reverts #30525, because it introduced a large performance penalty.
Here is the effect of that PR when I upgrade my Api Platform project from 4.2.9 to 4.3.1:
https://blackfire.io/profiles/compare/28bfbc61-3649-4896-bd03-7201239134cd/graph?settings%5Bdimension%5D=wt&settings%5Bdisplay%5D=landscape&settings%5BtabPane%5D=nodes&selected=Symfony%5CComponent%5CVarExporter%5CInternal%5CExporter%3A%3Aexport%403&callname=main()
The reverted PR targeted master. This should go in 4.3?
Commits
-------
3d37cc98f6
revert #30525 due to performance penalty
This commit is contained in:
commit
e8c68d533d
@ -24,13 +24,6 @@ class PropertyInfoCacheExtractor implements PropertyInfoExtractorInterface, Prop
|
||||
{
|
||||
private $propertyInfoExtractor;
|
||||
private $cacheItemPool;
|
||||
|
||||
/**
|
||||
* A cache of property information, first keyed by the method called and
|
||||
* then by the serialized method arguments.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $arrayCache = [];
|
||||
|
||||
public function __construct(PropertyInfoExtractorInterface $propertyInfoExtractor, CacheItemPoolInterface $cacheItemPool)
|
||||
@ -110,34 +103,22 @@ class PropertyInfoCacheExtractor implements PropertyInfoExtractorInterface, Prop
|
||||
}
|
||||
|
||||
// Calling rawurlencode escapes special characters not allowed in PSR-6's keys
|
||||
$encodedMethod = rawurlencode($method);
|
||||
if (\array_key_exists($encodedMethod, $this->arrayCache) && \array_key_exists($serializedArguments, $this->arrayCache[$encodedMethod])) {
|
||||
return $this->arrayCache[$encodedMethod][$serializedArguments];
|
||||
$key = rawurlencode($method.'.'.$serializedArguments);
|
||||
|
||||
if (\array_key_exists($key, $this->arrayCache)) {
|
||||
return $this->arrayCache[$key];
|
||||
}
|
||||
|
||||
$item = $this->cacheItemPool->getItem($encodedMethod);
|
||||
$item = $this->cacheItemPool->getItem($key);
|
||||
|
||||
$data = $item->get();
|
||||
if ($item->isHit()) {
|
||||
$this->arrayCache[$encodedMethod] = $data[$encodedMethod];
|
||||
// Only match if the specific arguments have been cached.
|
||||
if (\array_key_exists($serializedArguments, $data[$encodedMethod])) {
|
||||
return $this->arrayCache[$encodedMethod][$serializedArguments];
|
||||
}
|
||||
}
|
||||
|
||||
// It's possible that the method has been called, but with different
|
||||
// arguments, in which case $data will already be initialized.
|
||||
if (!$data) {
|
||||
$data = [];
|
||||
return $this->arrayCache[$key] = $item->get();
|
||||
}
|
||||
|
||||
$value = $this->propertyInfoExtractor->{$method}(...$arguments);
|
||||
$data[$encodedMethod][$serializedArguments] = $value;
|
||||
$this->arrayCache[$encodedMethod][$serializedArguments] = $value;
|
||||
$item->set($data);
|
||||
$item->set($value);
|
||||
$this->cacheItemPool->save($item);
|
||||
|
||||
return $this->arrayCache[$encodedMethod][$serializedArguments];
|
||||
return $this->arrayCache[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user