Problem/Motivation

The ConditionalFieldsHandlersManager bypasses plugin cache by passing raw discovery to the factory (line 35):

$this->factory = new ContainerFactory($this->getDiscovery());

Every createInstance() triggers full annotation discovery instead of using cache. Impact scales with number of modules installed * number of conditional field dependencies.

Execution time:

ConditionalFieldsFormHelper::getState     → 1,276,279 μs (29.9%)
  └─ StaticDiscoveryDecorator::getDefinition × 132 calls → 1,252,207 μs (29.4%)
      └─ AnnotatedClassDiscovery::getDefinitions → 1,019,607 μs (23.9%)
          └─ file_exists × 30,856 calls → 831,358 μs (19.5%)

Steps to reproduce

1. Set up a node type with x fields and conditional dependencies
2. Observe uncached definitions called repeatedly

Proposed resolution

Remove line 35. Parent class DefaultPluginManager creates a properly cached factory automatically.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

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

baikho created an issue. See original summary.

baikho’s picture

Issue summary: View changes
baikho’s picture

Issue summary: View changes
Status: Active » Needs review
baikho’s picture

Assigned: baikho » Unassigned
baikho’s picture

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

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

zerdiox’s picture

Checked this on multiple projects and works perfectly fine without that added line! Easy fix should be an easy merge :-D

benstallings’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, @zerdiox.

joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @baikho for the clear profile and the tidy one-line fix, and @zerdiox and @benstallings for the testing.

Confirmed the cause: StaticDiscoveryDecorator::getDefinition() re-runs $this->decorated->getDefinitions() on every call, so passing the raw discovery to the factory meant a full class scan per createInstance(). Letting DefaultPluginManager build its own factory routes lookups through the cached manager instead... ~280× faster on a bare kernel, and the gap grows with module count. Woo for performance improvement (tests are slow on this project for sure!)

Sent to the merge train 🚂 — thanks all!

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.

  • joelpittet committed ee44f5e8 on 4.x authored by baikho
    fix: #3573139 Plugin definitions not cached causing full annotation...