Skip to content

Commit 76ecc21

Browse files
committed
[Serializer] Fix cache in MetadataAwareNameConverter
`isset` is used to test existence of values that is `null` by default, which result to always bypass the cache and force to do the calculate all the time. This is a critical perf improvement in prod mode for an api. Ref #35085
1 parent 0a86745 commit 76ecc21

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

NameConverter/MetadataAwareNameConverter.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function normalize($propertyName, string $class = null, string $format =
4747
return $this->normalizeFallback($propertyName, $class, $format, $context);
4848
}
4949

50-
if (!isset(self::$normalizeCache[$class][$propertyName])) {
50+
if (!\array_key_exists($class, self::$normalizeCache) || !\array_key_exists($propertyName, self::$normalizeCache[$class])) {
5151
self::$normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
5252
}
5353

@@ -64,7 +64,7 @@ public function denormalize($propertyName, string $class = null, string $format
6464
}
6565

6666
$cacheKey = $this->getCacheKey($class, $context);
67-
if (!isset(self::$denormalizeCache[$cacheKey][$propertyName])) {
67+
if (!\array_key_exists($cacheKey, self::$denormalizeCache) || !\array_key_exists($propertyName, self::$denormalizeCache[$cacheKey])) {
6868
self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
6969
}
7070

@@ -78,7 +78,7 @@ private function getCacheValueForNormalization(string $propertyName, string $cla
7878
}
7979

8080
$attributesMetadata = $this->metadataFactory->getMetadataFor($class)->getAttributesMetadata();
81-
if (!isset($attributesMetadata[$propertyName])) {
81+
if (!\array_key_exists($propertyName, $attributesMetadata)) {
8282
return null;
8383
}
8484

@@ -93,7 +93,7 @@ private function normalizeFallback(string $propertyName, string $class = null, s
9393
private function getCacheValueForDenormalization(string $propertyName, string $class, array $context): ?string
9494
{
9595
$cacheKey = $this->getCacheKey($class, $context);
96-
if (!isset(self::$attributesMetadataCache[$cacheKey])) {
96+
if (!\array_key_exists($cacheKey, self::$attributesMetadataCache)) {
9797
self::$attributesMetadataCache[$cacheKey] = $this->getCacheValueForAttributesMetadata($class, $context);
9898
}
9999

0 commit comments

Comments
 (0)