I have a function in Symfony2 that modifies an object. The function can receive the object in one of two ways. First, the object can be passed to the function like this:
public function myFunction(Object $myObject)
{
// Do something with $myObject
}
Alternately, an object id (or any other attribute) can be passed to the function and used to find the object within the function, like this:
public function myFunction($id)
{
$myObject = $this->entityManager->getRepository('AppBundle\Entity\Object')->find($id);
// Do something with $myObject
}
Functionally, these two methods are equivalent. My question is, how do these two methods differ in their effect on the application's performance? I know the number of database queries should be minimized for optimized performance. So, how does the performance cost of an additional find()
query compare with the performance cost of passing an object to a function?