Problem/Motivation

SourcePluginBase::setDefinedContextValues and DerivableContextPluginBase::setDefinedContextValues unconditionally calls getAvailableContexts() + getRuntimeContexts() on every source plugin instantiation, even when getContextDefinitions() returns empty (21 of 28 bundled source plugins). This wastes ~75% of context resolution calls.

This is primarily a correctness issue: skipping work that has no effect.
It also yields a small performance improvement of a few ms per page in my testing.

Also, the $gatheredContexts property is set in setDefinedContextValues() but never read anywhere in ui_patterns. It should either be removed or documented as an extension point (if that is the case?).

Steps to reproduce

Profile any page that renders UI Patterns components with xhprof.

Proposed resolution

- Move getContextDefinitions() to the top of setDefinedContextValues() and return early if empty.
- Remove the dead $this->gatheredContexts assignment which is currently unused.

Remaining tasks

?

User interface changes

None

API changes

None

Data model changes

None

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

herved created an issue. See original summary.

herved’s picture

Status: Active » Needs review
pdureau’s picture

Assigned: Unassigned » just_like_good_vibes

Thank you Hervé.

For information, we have an ambitious simplification goal for Context management this summer: #3540247: Map source contexts with enums which seems fitting well with your proposal.

just_like_good_vibes made their first commit to this issue’s fork.

just_like_good_vibes’s picture

Hello there, i have Rebased on 2.0.x and added some tests.

Two notes on the previous comments:
- The count was 15 of 28 i think, not 21.
- yes, Nothing reads gatheredContexts (since #3461277: [2.0.0-beta1] Sources don't support required - #title missing?)

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs review » Fixed

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.