Drupal calling "is_dir" over 4000 times? After having troubles on loading time of a very important Site I installed XHPROF and looked over the statistics to see where I can improve my code.

I found something interesting that i don´t understand. Drupal calls "is_dir" over 4000 time on nearly every request and this takes about 800ms to execute. Why is that and is there a way to speed that up?



By a loading time of two to four seconds is 800ms take a big part.
When you uninstall a module, you need to disable it first in Drupal module admin. You should then uninstall it via the "Uninstall" tab there.

The same goes for themes, disable in theme admin first.

If you for example, delete the module folder on the file system without disabling the module, Drupal will continue to search for the module in the file system, which can result, among other errors, in the issue you are experiencing.

See also: Avoid re-scanning module directory when multiple modules are missing

In answer to MPD's comment, you will need to do something like

SELECT name, filename FROM system WHERE status = 1;


and cross reference that with the modules on your file system. All enabled modules, and themes too, should be present.

There's also a function ( slightly adapted ) Martin_Dresden posted here:

https://drupal.org/node/1080330#comment-6520842

function MYMODULE_init() {

    $startingtime = microtime(true); 
    $o = '&lt;p&gt;Checking for dead modules ...&lt;/p&gt;';
    $result = db_select('system')
      -&gt;fields('system', array('filename'))
      -&gt;condition('status', '1', '=')
      -&gt;execute();
      $n = 1;
      $m = 0;
    foreach ($result as $row) {
      $path = DRUPAL_ROOT.'/'.$row-&gt;filename;
      If (!file_exists($path)) { 
          $o .= "#$n $path&lt;br&gt;";
          $m++;
      }
      $n++;
    }
    $timedif =  round(microtime(true) - $startingtime,3);
    $o .= "Total of $n active modules registered in database. $m dead entries found.&lt;br&gt;";
    $o .= 'Query Time: '.$timedif.' seconds';

    drupal_set_message($o);

}


That may help debug.