@@ -60,3 +60,32 @@ Before using this normalizer in a Symfony application it must be registered as
60
60
a service and :doc: `tagged </service_container/tags >` with ``serializer.normalizer ``.
61
61
If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
62
62
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