Problem/Motivation

#[HookDependsOnModule('help')] is a new attribute that prevents hooks from being picked up if this attribute is available and the module does not exist.

Steps to reproduce

Proposed resolution

Add #[HookDependsOnModule('help')] to all hook_help implementations except the help module itself.

Remaining tasks

Review

User interface changes

N/A

Introduced terminology

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3600994

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nicxvan created an issue. See original summary.

nicxvan’s picture

Status: Active » Needs work

Got another test fail.

nicxvan’s picture

Issue summary: View changes
Status: Needs work » Needs review

Had to fix two tests that explicitly checked for help hooks existing.

This is ready!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Applied the MR and all help hooks appear to be updated. Very neat feature.

berdir’s picture

Status: Reviewed & tested by the community » Needs review

I plan to run some checks on the impact of this, I want to have an understanding of the impact of this and how it actually benefits us in practice before RTBC.

nicxvan’s picture

Works for me! This isn't a huge priority.

berdir’s picture

Testing with core umami, with help module uninstalled:

HEAD:
container cache length: 526985
hook_list length: 46700

MR:
cache container length: 525295
hook_list length: 43724

that means the container cache size reduction is just 0.2%, which makes sense as this only impacts the container if this allows us to skip the service for it completely, we'd need to move the help hooks to their own services for this to have a benefit for the container.

hook_list is better, that's an improvement of around 6%, but it will be much smaller on sites with lots of contrib projects, it will be the same reduction of 3k (or less if they use fewer core modules) and for my distrubtion, hook_list is 100k, so twice as large already.

So, unsure if this is worth it.

mstrelan’s picture

I'm also wondering if this is worth it. What makes hook_help special? In theory we should do the same for all hooks where the provider of the hook is not a dependency of the module implementing the hook.

If it is indeed worthwhile, it seems like this could be automated somehow, e.g. with a registry of hooks and what modules they belong to.

berdir’s picture

Help is special in that it is by far the most common hook that almost all modules implement in core and contrib.

We have no information on who calls a hook, even for help, it is possible that someone else calls it, such as a help2 module in contrib.

So yes, this might be a won't fix as the gains might not outweigh the complexity and risks.

We have some ideas around caching to use some sort of cache collector, so if nobody ever calls hook help, it won't end up in the active cache. But the cost of that is slower cache warmup, stampedes and so on.

smustgrave’s picture

Would it be good at class level instead? Like if all the hooks are views related on the class say HookDependsOnModule('views')

berdir’s picture

You can do that, but the performance gains are tiny for a single class too. The main reason for adding this for me wasn't performance but DX.

https://git.drupalcode.org/project/drupal/-/commit/3e6179a621d37ce18d1da... is a good example (FileViewsHooks). That actually is a views hooks class, if you have optional hooks for a given module, you might also depend on services from that module, with this change, you can actually require the parameter no because the service will only be registered if the module is there.

nicxvan’s picture

We can close this, I only did it since it was one of the original stated reasons for it.

nicxvan’s picture

Status: Needs review » Closed (won't fix)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.