title: Doctrine 2 EntityManager causes time loss in first request
body: <p>Recently I integrated Doctrine 2 ORM into CodeIgniter 2. I configured Doctrine 2 as a library and autoloaded it in CodeIgniter. Within a page I instantiate doctrine entity manager in the following way:</p>
  
  <pre><code>private static $em = null;
  
  public function __construct() {
      parent::__construct();
      $this-&gt;em = $this-&gt;doctrine-&gt;em;
  }
  </code></pre>
  
  <p>And then I start to use the Entity Manager when needed. The issue I have is that in each page request Entity Manager takes some time to initialize (appr. 1 second). This causes the user to wait until the page is loaded. Below you can see some performance results I measured:</p>
  
  <pre><code>BENCHMARKS  
  Loading Time: Base Classes          0.0166
  Doctrine                            0.0486
  GetArticle                          1.0441
  Functions                           0.0068
  Controller Execution Time           1.1770
  Total Execution Time                1.1938
  </code></pre>
  
  <p>The GetArticle function basicly makes an EntityManager->find() call:</p>
  
  <pre><code>$currentart = $this-&gt;em-&gt;find('Entities\Article', $artid);
  </code></pre>
  
  <p>I have to wait that 1 second even if I use the EntityManager->createQuery() method. </p>
  
  <p>In every page, I have a time loss of approximately 1 second because of EntityManager's first request. </p>
  
  <p>Is this common? </p>
  
  <p>Does this 1 second come from the fact that EntityManager needs to establish a connection to the DB? The functions/requests after the first request are quite fast though. </p>