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