8000 [Serializer] Improve performance of CacheClassMetadataFactory::getMetadataFor() · Issue #35041 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Serializer] Improve performance of CacheClassMetadataFactory::getMetadataFor() #35041
Closed
@bastnic

Description

@bastnic

Symfony version(s) affected: I'm on 4.4.1 but surely may be all versions

Description
In prod mode, the system cache is a chain [phpArray, apcu]. This is given to CacheClassMetadataFactory that does the job to cache the computed data across each requests.

On an API Platform, I got this stacktrace tht calls CacheClassMetadataFactory:

#0 /var/www/project/apps/api/vendor/symfony/cache/Adapter/ChainAdapter.php(124): Symfony\Component\Cache\Adapter\AbstractAdapter->getItem('Lib_Core_Entity...')
#1 /var/www/project/apps/api/vendor/symfony/cache/Adapter/PhpArrayAdapter.php(127): Symfony\Component\Cache\Adapter\ChainAdapter->getItem('Lib_Core_Entity...')
#2 /var/www/project/apps/api/vendor/symfony/serializer/Mapping/Factory/CacheClassMetadataFactory.php(54): Symfony\Component\Cache\Adapter\PhpArrayAdapter->getItem('Lib_Core_Entity...')
#3 /var/www/project/apps/api/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php(166): Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory->getMetadataFor('Lib\\Core\\Entity...')
#4 /var/www/project/apps/api/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php(151): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize(Object(Lib\Core\Entity\Site), 'json', Array)
#5 /var/www/project/apps/api/vendor/symfony/serializer/Serializer.php(152): ApiPlatform\Core\Serializer\AbstractItemNormalizer->normalize(Object(Lib\Core\Entity\Site), 'json', Array)

The same calls is made a few hundred times. Each hitting apcu.

image

A very simple local cache clears everything:

image

How to reproduce
basic apip and symfony with last versions and apcu available. But should be reproducible with any use of AbstractObjectNormalizer.php.

Possible Solution
I'm not sure about the correct fixe:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0