drupal_static and XHProf
You should use either static declaration or drupal_static(), but not both for the same variable. The issue here is that the reference is lost because references are not stored statically.

From https://www.drupal.org/node/619666#comment-2211696


  So unfortunately this is not possible (declarations of static variables don't accept expressions):


static $implementations = &amp;drupal_static(__FUNCTION__, array());



  An this neither (it'll lose the reference):


static $implementations;
if (!isset($implementations)) {
  $implementations = &amp;drupal_static(__FUNCTION__, array());
}



  But this is:


static $cache = array();
if (!isset($cache['implementations'])) {
  $cache['implementations'] = &amp;drupal_static(__FUNCTION__, array());
} 
$implementations = &amp;$cache['implementations'];


So you should do this:

static $cache;
if (!isset($cache)) {
  $cache['registry'] = &amp;drupal_static(__FUNCTION__, array());
}
$registry = &amp;$cache['registry'];