diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 26a75f6..2d53a1b 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -208,10 +208,23 @@ function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) {
  *   The filename of the requested item or NULL if the item is not found.
  */
 function drupal_get_filename($type, $name, $filename = NULL) {
+  // Return NULL right away if $type or $name is empty.
+  if (empty($type) || empty($name)) {
+    return NULL;
+  }
+
   // The location of files will not change during the request, so do not use
   // drupal_static().
   static $files = array();
 
+  // We use drupal static for the missing records so we can test it.
+  // Drupal static fast pattern is used as this function may be called often.
+  static $drupal_static_fast;
+  if (!isset($drupal_static_fast)) {
+    $drupal_static_fast['missing'] = &drupal_static(__FUNCTION__ . ':missing');
+  }
+  $missing = &$drupal_static_fast['missing'];
+
   // Type 'core' only exists to simplify application-level logic; it always maps
   // to the /core directory, whereas $name is ignored. It is only requested via
   // drupal_get_path(). /core/core.info.yml does not exist, but is required
@@ -251,13 +264,24 @@ function drupal_get_filename($type, $name, $filename = NULL) {
     }
     // If still unknown, perform a filesystem scan.
     if (!isset($files[$type][$name])) {
-      $listing = new ExtensionDiscovery(DRUPAL_ROOT);
-      // Prevent an infinite recursion by this legacy function.
-      if ($original_type == 'profile') {
-        $listing->setProfileDirectories(array());
+      if (is_null($missing)) {
+        $missing = array();
+        if (\Drupal::hasService('cache.bootstrap')) {
+          $cache = \Drupal::cache('bootstrap')->get('drupal_get_filename:missing', TRUE);
+          if ($cache && $cache->data) {
+            $missing = $cache->data;
+          }
+        }
       }
-      foreach ($listing->scan($original_type) as $extension_name => $file) {
-        $files[$type][$extension_name] = $file->getPathname();
+      if (!isset($missing[$type][$name])) {
+        $listing = new ExtensionDiscovery(DRUPAL_ROOT);
+        // Prevent an infinite recursion by this legacy function.
+        if ($original_type == 'profile') {
+          $listing->setProfileDirectories(array());
+        }
+        foreach ($listing->scan($original_type) as $extension_name => $file) {
+          $files[$type][$extension_name] = $file->getPathname();
+        }
       }
     }
   }
@@ -265,6 +289,18 @@ function drupal_get_filename($type, $name, $filename = NULL) {
   if (isset($files[$type][$name])) {
     return $files[$type][$name];
   }
+  elseif (!isset($missing[$type][$name])) {
+    // Add the missing file to a temporary cache and throw an alert. This cache
+    // will be cleared on cron runs as well as when visiting the module and
+    // theme list pages.
+    $missing[$type][$name] = TRUE;
+    if (\Drupal::hasService('cache.bootstrap')) {
+      \Drupal::cache('bootstrap')->set('drupal_get_filename:missing', $missing, REQUEST_TIME);
+    }
+    if (\Drupal::hasService('logger.factory')) {
+      \Drupal::logger('system')->error('The following @type is missing from the file system: @name', array('@type' => $type, '@name' => $name));
+    }
+  }
 }
 
 /**
diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php
index 73180a0..b2b647b 100644
--- a/core/modules/system/src/Controller/SystemController.php
+++ b/core/modules/system/src/Controller/SystemController.php
@@ -186,6 +186,12 @@ public function systemAdminMenuBlockPage() {
    * @todo Move into ThemeController.
    */
   public function themesPage() {
+    //  Clean up the bootstrap "missing files" cache when listing themes.
+    if (\Drupal::hasService('cache.bootstrap')) {
+      \Drupal::cache('bootstrap')->invalidate('drupal_get_filename:missing');
+      drupal_static_reset('drupal_get_filename:missing');
+    }
+
     $config = $this->config('system.theme');
     // Get all available themes.
     $themes = $this->themeHandler->rebuildThemeData();
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index eb894f6..3d43c6c 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -174,6 +174,12 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     // Include system.admin.inc so we can use the sort callbacks.
     $this->moduleHandler->loadInclude('system', 'inc', 'system.admin');
 
+    //  Clean up the "missing files" cache when listing modules.
+    if (\Drupal::hasService('cache.bootstrap')) {
+      \Drupal::cache('bootstrap')->invalidate('drupal_get_filename:missing');
+      drupal_static_reset('drupal_get_filename:missing');
+    }
+
     $form['filters'] = array(
       '#type' => 'container',
       '#attributes' => array(
diff --git a/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php b/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php
index f867045..9eed74a 100644
--- a/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php
+++ b/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php
@@ -70,7 +70,16 @@ function testDrupalGetFilename() {
     // a fixed location and naming.
     $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'core/profiles/standard/standard.info.yml');
 
+    // Generate a non-existing module name.
+    $non_existing_module = uniqid("", TRUE);
+
     // Searching for an item that does not exist returns NULL.
-    $this->assertNull(drupal_get_filename('module', uniqid("", TRUE)), 'Searching for an item that does not exist returns NULL.');
+    $this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for an item that does not exist returns NULL.');
+
+    // Get the missing records static from drupal_get_filename.
+    $missing = &drupal_static('drupal_get_filename:missing');
+
+    // Searching for an item that does not exist creates a static record in drupal_get_filename.
+    $this->assertTrue($missing['module'][$non_existing_module], 'Searching for an item that does not exist creates a static record in drupal_get_filename.');
   }
 }
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index d2bda7f..597393e 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -1201,6 +1201,12 @@ function system_cron() {
     $cache_backend->garbageCollection();
   }
 
+  // Clean up the bootstrap "missing files" cache when running cron.
+  if (\Drupal::hasService('cache.bootstrap')) {
+    \Drupal::cache('bootstrap')->invalidate('drupal_get_filename:missing');
+    drupal_static_reset('drupal_get_filename:missing');
+  }
+
   // Clean up the expirable key value database store.
   if (\Drupal::service('keyvalue.expirable.database') instanceof KeyValueDatabaseExpirableFactory) {
     \Drupal::service('keyvalue.expirable.database')->garbageCollection();
