So this may be treading back towards the registry, but currently it's impossible for Token module to easily tell the module hook system that it has the menu, profile, and field implementations for tokens. Currently with module_implements we cache discovered implementations like this:

$implementations[hook][module] = FALSE; // Means the hook is located in the module file. Since all module files are loaded on full bootstrap, we don't care where the hook is located.
$implementations[hook][module] = 'group' // Means the hook is located in module.group.inc inside the module's root directory. This group values is taken from hook_hook_info().

Now if we stored the actual file location instead of 'group', it could allow modules to easily add core module support for hooks. In the case of token.module, we'd want to do something like this:

function token_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'tokens' || $hook == 'token_info') {
    $modules = array('menu', 'profile', 'field');
    foreach ($modules as $module) {
      if (module_exists($module) && $file = module_load_include('inc', 'token', $module . '.tokens')) {
        $implementations[$module] = $file;
        // Ensure this gets cached since we made changes.
        $implementations['#write_cache'] = TRUE;
      }
    }
  }
}

Comments

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new1.84 KB

Patch attached for review.

Status: Needs review » Needs work

The last submitted patch, 825854-module-implements-file-D7.patch, failed testing.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new2.91 KB

Revised to fix the one test failure that was anticipating the group name.

dave reid’s picture

Issue tags: +token, +pathauto

Adding tags for the D7 modules this would make life easier for.

damienmckenna’s picture

The logic makes sense, the code is simple & clean. +1
How many reviews are needed for it to be RBTC?

retester2010’s picture

Issue tags: -token, -pathauto

Status: Needs review » Needs work
Issue tags: +token, +pathauto

The last submitted patch, 825854-module-implements-file-D7.patch, failed testing.

sun’s picture

Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new2.88 KB

Straight re-roll against HEAD. Didn't verify the changes, but overall, they make sense to me.

Status: Needs review » Needs work

The last submitted patch, drupal.module-implements-file.8.patch, failed testing.

catch’s picture

Someone needs to profile this patch with xhprof, with a lot of modules enabled, to see if there's any noticeable memory impact from storing the file path. I would hope there isn't but let's not find out after this gets in.

dave reid’s picture

Status: Needs work » Needs review
Issue tags: -token, -pathauto

Status: Needs review » Needs work
Issue tags: +token, +pathauto

The last submitted patch, drupal.module-implements-file.8.patch, failed testing.

dave reid’s picture

Version: 7.x-dev » 8.x-dev
Category: task » feature

I don't think I'm in a position to be able to do that. I can apache ab it if that will help?

catch’s picture

ab won't tell you memory usage. You could var_export() the cache entry and compare file size maybe - but it needs to be on a large site with lots of hook implementations to be meaningful.

dave reid’s picture

Yeah the problem is that core does not use hook_hook_info() very much, so that will be kinda hard to do.

catch’s picture

This isn't about hook_hook_info(), it's just about how much the array grows when you store filename for every module instead of FALSE. So the memory issue is going to be most apparent when hook_hook_info() isn't used.

My concern here is that to save memory from loading files, we are increasing the metadata loaded into memory on every request - so if there are only a few core hooks being implemented here, then it is likely that the extra memory from the cache size is going to outweigh any gains.

This will especially be the case if you don't have contrib modules installed doing the hook_module_implements_alter() trick (or not many) - because that memory cost is going to hit you whether or not that gets used or not.

dave reid’s picture

The size of this cache will only increase if hook_hook_info() is used and the module's hook is located in module-name.hook-group.inc. If the hook is located in the main .module file, then the value stored will not change (will still be FALSE).

catch’s picture

Title: Module_implements should cache the file path and not TRUE/group value » Module_implements should cache the file path and not TRUE/group value for hooks that specify group in hook_hook_info()

Ah OK.

Just made the title of the issue a bit longer to reflect this.

Reviewing the code I see that's what you're doing, and that should have minimal impact, so this is probably fine.

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes
Status: Needs work » Postponed

This would probably need to wait for at least 8.1.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed » Closed (duplicate)

Closing as it appears hook_info is being deprecated in https://www.drupal.org/project/drupal/issues/2233261