Problem/Motivation
\Drupal\Core\Plugin\Context\ContextHandler::checkRequirements()
is a low-level part of the plugin and context systems. Given a set of requirements (in the form of context definitions), it checks a provided set of candidate contexts to see if the requirements are met.
Internally ::checkRequirements()
uses ::getMatchingContexts()
to find the full set of matching contexts, and then checks to see if the set it empty.
With this being called within several nested loops, this means that ContextDefinition::isSatisfiedBy()
will be called once for each requirement and each candidate context, once per section storage, once per entity rendered.
With a view of 8 entities all rendered by Layout Builder, this means 512 calls per page.
With this patch, the calls drops to 112.
Steps to reproduce
Add step debugging in \Drupal\Core\Plugin\Context\ContextDefinition::isSatisfiedBy()
and note how many calls are made in a given request on a page built with Layout Builder.
Proposed resolution
Return once the first matching context is found.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet