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
Issue fork conditional_fields-3573139
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
Comment #3
baikho commentedComment #4
baikho commentedComment #5
baikho commentedComment #6
baikho commentedComment #9
zerdiox commentedChecked this on multiple projects and works perfectly fine without that added line! Easy fix should be an easy merge :-D
Comment #10
benstallings commentedThanks, @zerdiox.
Comment #11
joelpittetThanks @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 percreateInstance(). LettingDefaultPluginManagerbuild 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!