Discover and cache hook implementations
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3276804. -->
Reported by: [dpi](https://www.drupal.org/user/81431)
Related to !3
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>In most cases a service doesn't need to be instantiated, along with all if its dependencies, in order to determine which hooks it implements. Reflection can be used directly with a hooks class. Discovery should be optimized to not always directly get instantiated services from the container.</p>
<p>Results of discovery can be cached and utilized on production environments. Discovery caches should use fastchained, as these caches will be used for most requests.</p>
<p>Caching should be opt in. Not opting in won't have a significant performance penalty.</p>
<p>Provide documentation and guidance on how to use caches and add a hook_requirements to warn site builders.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<ul>
<li>Separate hooks discovery + make results serializable.</li>
<li>Update docs</li>
<li>Create d.o guide and optimized docs.</li>
</ul>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>New line item always present on Drupal's status page.</p>
<h3 id="summary-api-changes">API changes</h3>
<p>Internal API changes</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>New serialized cache<br>
New container parameter</p>
issue