diff --git a/components/serializer.rst b/components/serializer.rst index 3bf6cda7f33..56cd676984f 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -1295,6 +1295,32 @@ can use this simpler configuration: +Performance +----------- + +To figure which normalizer (or denormalizer) must be used to handle an object, +the :class:`Symfony\\Component\\Serializer\\Serializer` class will call the +:method:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface::supportsNormalization` +(or :method:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface::supportsDenormalization`) +of all registered normalizers (or denormalizers) in a loop. + +The result of these methods can vary depending on the object to serialize, the +format and the context. That's why the result **is not cached** by default and +can result in a significant performance bottleneck. + +However, most normalizers (and denormalizers) always return the same result when +the object's type and the format are the same, so the result can be cached. To +do so, make those normalizers (and denormalizers) implement the +:class:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface` +and return ``true`` when +:method:`Symfony\\Component\\Serializer\\Normalizer\\CacheableSupportsMethodInterface::hasCacheableSupportsMethod` +is called. + + .. note:: + + All built-in :ref:`normalizers and denormalizers ` + as well the ones included in `API Platform`_ natively implement this interface. + Learn more ---------- @@ -1304,6 +1330,11 @@ Learn more /serializer +.. seealso:: + + Normalizers for the Symfony Serializer Component supporting popular web API formats + (JSON-LD, GraphQL, HAL and JSONAPI) are available as part of the `API Platform`_ project. + .. seealso:: A popular alternative to the Symfony Serializer Component is the third-party @@ -1320,3 +1351,4 @@ Learn more .. _CSV: https://tools.ietf.org/html/rfc4180 .. _`RFC 7807`: https://tools.ietf.org/html/rfc7807 .. _`Value Objects`: https://en.wikipedia.org/wiki/Value_object +.. _`API Platform`: https://api-platform.com pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy