You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor symfony#12825 [Serializer] add caution for normalize Datetime object with GetSetMethodNormalizer (spike31)
This PR was merged into the 3.4 branch.
Discussion
----------
[Serializer] add caution for normalize Datetime object with GetSetMethodNormalizer
I noticed an issue with the GetSetMethodNormalizer, not a real issue, but just a warning about its use.
If we normalize an object which returns a Datetime, without defining the DatetimeNormalizer; on many objects at the same time, we explode the memory of PHP and time of use.
Example :
```php
$serializer = new Serializer([new GetSetMethodNormalizer()]);
$objects = [];
for ($i = 0, $n = 100;$i<$n; $i++) {
$objects[] = new MyObject(new \DateTime('now'));
}
$serializer->normalize($objects);
dd('memory_get_peak_usage', (memory_get_peak_usage(true) / 1024 / 1024) . ' MiB');
```
"memory_get_peak_usage"
"46 MiB"
```php
$serializer = new Serializer([new DateTimeNormalizer(), new GetSetMethodNormalizer()]);
$objects = [];
for ($i = 0, $n = 100;$i<$n; $i++) {
$objects[] = new MyObject(new \DateTime('now'));
}
$serializer->normalize($objects);
dd('memory_get_peak_usage', (memory_get_peak_usage(true) / 1024 / 1024) . ' MiB');
```
"memory_get_peak_usage"
"14 MiB"
------
For i = 1000 => 334 Mib 🌊
Commits
-------
369ea13 add caution for datetime object
0 commit comments