I need some help on a performance issue concerning the native Symfony Serializer
If I try to serialize an entity array like this :
$serializedReservations = $this->serializer->serialize($reservations, 'json', ['groups' => 'reservationDetails', 'enable_max_depth' => true]);
The serialization take more than 1s
On the other hand, if I do :
$data = [];
foreach ($reservations as $reservation){
$data['idreservation'] = $reservation->getIdreservation();
$data['idcommand'] = $reservation->getCommand()->getIdCommand();
$data['title'] =$reservation->getCommand()->getTitle();
$data['serialnumber'] = $reservation->getStock()->getSerialNumber();
$data['ubd'] = $reservation->getStock()->getUBD();
}
$serializedReservations = $this->serializer->serialize($data, 'json', ['groups' => 'reservationDetails', 'enable_max_depth' => true]);
Serialization only take 21 ms !
So of course it's faster to serialize an array than an entity, but why is the 1st method so slow when it contains exactly the same datas (the "reservationDetails" group filter the same 6 data I get from the data[]) ?
If someone has an idea or even a lead, I'm interested. If I can't fix the problem I might try to switch to JmsSerializer.