lundi 28 août 2023

Does PHP8 Reflection more bad performance versus PHP7 without reflection

I have re write my code from old php 7.4 scripts. And i see my code be more slower than old version My old models export data from method toArray And his representation was like that

public function toArray()
{
   return [
      "id" => $this->id;
      "name" => $this->name;
      //And many other values
   ]
}

But now, with PHP 8, i have use reflection object to serialize my object. That take something like :

class MyModel extends Model
{
   #[AttributeExport]
   private int $id;

   #[AttributeExport]
   private string $name;
}

//In Model

abstract Model implement JsonSerialize
{
   function jsonSerialize(): array
   {
      //Here i get all my attributes from current class
      //And i construct array to return
   }
}

I may be mistakenly thinking that the problem may come from there. But do you think that on a large volume of data, this strategy can have an impact?

I used more abstract class compared to the old version to avoid code duplication. Dont know if that can impact too





Aucun commentaire:

Enregistrer un commentaire