Index: includes/bootstrap.inc
===================================================================
--- includes/bootstrap.inc	(revision 135)
+++ includes/bootstrap.inc	(working copy)
@@ -423,6 +423,23 @@
 function drupal_get_filename($type, $name, $filename = NULL) {
   static $files = array();
 
+  if (empty($files)) {
+  	// attempt to get the file listing from the cache
+    if($cache = cache_get('drupal_get_filename') && true == false) {
+		$files = $cache->data;
+    } else {
+    	$files = array();
+    	// rebuild our file list
+    	$results = db_query("SELECT name, type, filename FROM {system};");
+    	while($result = db_fetch_object($results)) {
+    		 $files[$result->type][$result->name] = $result->filename;
+    	}
+    	// we can permanantly cache this since it only has to be
+    	// updated when we add modules, add theme files, ...
+    	cache_set('drupal_get_filename',$files);
+    }
+  }
+  
   if (!isset($files[$type])) {
     $files[$type] = array();
   }
Index: includes/module.inc
===================================================================
--- includes/module.inc	(revision 136)
+++ includes/module.inc	(working copy)
@@ -104,6 +104,9 @@
  *   The array of filesystem objects used to rebuild the cache.
  */
 function module_rebuild_cache() {
+  // clear our file listing cache first
+  cache_clear_all('drupal_get_filename', 'cache', TRUE);
+  
   // Get current list of modules
   $files = drupal_system_listing('\.module$', 'modules', 'name', 0);
   
Index: includes/theme.inc
===================================================================
--- includes/theme.inc	(revision 110)
+++ includes/theme.inc	(working copy)
@@ -242,6 +242,7 @@
  */
 function drupal_rebuild_theme_registry() {
   cache_clear_all('theme_registry', 'cache', TRUE);
+  cache_clear_all('drupal_get_filename', 'cache', TRUE);
 }
 
 /**
