Carsten came today to me and told me that he had an exciting finding:

$entity =  $myObject->getEntity();
echo($entity);
echo($entity);

is faster than:

echo($myObject->getEntity());
echo($myObject->getEntity());

I couldn’t believe that but it was the truth. When I dug deeper in propel i found this line generated [reformatted]:

public function getEntity($con = null) {
  include_once 'lib/model/om/BaseEntityPeer.php';
  if ($this->aEntity === null && ($this->entity_gid !== null)) {
    $this->aEntity = EntityPeer::retrieveByPK($this->entity_gid, $con);
  }
  return $this->aEntity;
}

so, what is the magic here? as you might know, include_once comes with a performance hit. and here you will get this performance hit each and every time you call the getter. Isn’t that annoying?

I found the guilty propel builder and did a small patch which places the include inside the if (where it is actually needed) and the performance hit is gone. Neat, isn’t it?

The patch can be found here: PHP5ComplexObjectBuilder.patch

Enjoy!