Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295027

Add a fast and simple way to get module name from the module handler

$
0
0

Problem/Motivation

By @pwolanin:

In the block manager and other places in core we have to use truly horrible code like this to get the human-readable name of a module:

<?php
function getModuleName($module) {
   
// Gather module data.
   
if (!isset($this->moduleData)) {
     
$this->moduleData = system_get_info('module');
    }
   
// If the module exists, return its human-readable name.
   
if (isset($this->moduleData[$module])) {
      return
$this->t($this->moduleData[$module]['name']);
    }
   
// Otherwise, return the machine name.
   
return $module;
  }
?>

Why is that so horrible? Well it requires calling out to a procedural function AND system_get_info() calls system_rebuild_module_data() and none of this is cached even statically.

This was also pretty bad in Drupal 7, but in the worst case you could get the module info out of the database. In 8, none of that seems to be available.

By @Berdir:

system_get_info() calls right into system_rebuild_module_data(), which parses all .info.yml files. And that's slow, even with the apcu file cache that I have applied already. Without it, it's much worse.

We used to have some pretty complicated and arcane caching there, but we removed it, as we no longer needed that function during bootstrap.

However, we still call it on some places, like /admin/people, to group the permission list by module. On a default D8 installation, 50%/200ms is spent in that function on that page.

Proposed resolution

Get module info from cache when it's being loaded in system_get_info() and add it to cache when we do a system_rebuild_module_data(). Stop loading system_rebuild_module_data()/system_get_info() if we can use the getName() method as well.

Remaining tasks

N/A

User interface changes

N/A

API changes

Not really an API change but in the current version of the patch ModuleHandler::getName() now returns the module name as it had been input in case it can't find the actual name, instead of giving an error.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue categoryBug because significant slowdown on certain pages
Issue priorityMajor because significant slowdown
Prioritized changesThe main goal of this issue is performance

Viewing all articles
Browse latest Browse all 295027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>