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
Issue category | Bug because significant slowdown on certain pages |
---|---|
Issue priority | Major because significant slowdown |
Prioritized changes | The main goal of this issue is performance |