Skip to content

Commit 6d51c6c

Browse files
committed
[Serializer] move note on Custom Normalizer page about cacheable performance
1 parent 8a7d32e commit 6d51c6c

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

components/serializer.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,32 +1499,6 @@ Once configured, the serializer uses the mapping to pick the correct class::
14991499
$repository = $serializer->deserialize($serialized, CodeRepository::class, 'json');
15001500
// instanceof GitHubCodeRepository
15011501

1502-
Performance
1503-
-----------
1504-
1505-
To figure which normalizer (or denormalizer) must be used to handle an object,
1506-
the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the
1507-
:method:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization`
1508-
(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`)
1509-
of all registered normalizers (or denormalizers) in a loop.
1510-
1511-
The result of these methods can vary depending on the object to serialize, the
1512-
format and the context. That's why the result **is not cached** by default and
1513-
can result in a significant performance bottleneck.
1514-
1515-
However, most normalizers (and denormalizers) always return the same result when
1516-
the object's type and the format are the same, so the result can be cached. To
1517-
do so, make those normalizers (and denormalizers) implement the
1518-
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
1519-
and return ``true`` when
1520-
:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod`
1521-
is called.
1522-
1523-
.. note::
1524-
1525-
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
1526-
as well the ones included in `API Platform`_ natively implement this interface.
1527-
15281502
Learn more
15291503
----------
15301504

serializer/custom_normalizer.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,32 @@ Before using this normalizer in a Symfony application it must be registered as
6060
a service and :doc:`tagged </service_container/tags>` with ``serializer.normalizer``.
6161
If you're using the :ref:`default services.yaml configuration <service-container-services-load-example>`,
6262
this is done automatically!
63+
64+
Performance
65+
-----------
66+
67+
To figure which normalizer (or denormalizer) must be used to handle an object,
68+
the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the
69+
:method:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization`
70+
(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`)
71+
of all registered normalizers (or denormalizers) in a loop.
72+
73+
The result of these methods can vary depending on the object to serialize, the
74+
format and the context. That's why the result **is not cached** by default and
75+
can result in a significant performance bottleneck.
76+
77+
However, most normalizers (and denormalizers) always return the same result when
78+
the object's type and the format are the same, so the result can be cached. To
79+
do so, make those normalizers (and denormalizers) implement the
80+
:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface`
81+
and return ``true`` when
82+
:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod`
83+
is called.
84+
85+
.. note::
86+
87+
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
88+
as well the ones included in `API Platform`_ natively implement this interface.
89+
90+
.. _`API Platform`: https://api-platform.com
91+

0 commit comments

Comments
 (0)