Problem
When a user selects the outermost container of a page in the display builder, the contextual form panel takes up to 90+ seconds to load on a page with a deep component tree. The same request on a page with few components takes 5–7s, and the cost scales linearly with the number of components below the selected one — even though the user only selected the container itself.
How to reproduce
Build a page whose slot tree nests ~35 components under one container (components inside slots, slots inside those components, etc.).
Select the outermost container in the canvas.
The builder fires GET /api/display-builder/{instance}/_node/{node_id} to rebuild the islands. On our site (DDEV, PHP 8.4, xhprof profiling) this request takes 92.8s and allocates ~1.7 GB over its lifetime.
Root cause (from an xhprof profile of the 92.8s request)
94% of the request (~87s) is spent in ComponentFormBase::getSourceDefinitions():
ContextualFormPanel::buildForm()
→ settingsFormPropsOnly() (the selected container's form)
→ ComponentSlotForm::buildSourceRow() ×98 (the container's slot entries)
→ ComponentFormBase::getSourcePluginForm()
→ ComponentSource::settingsForm() (upstream)
→ '#type' => 'component_form' ×35 (one per descendant!)
→ ComponentForm::buildComponentForm()
├─ ComponentPropForm::buildClosedState() ×173
└─ ComponentSlotForm::buildSourceRow() → recursion into grandchildren
Two compounding problems:
Structural (this issue): a component source stored in a parent's slot embeds the full component_form of the child in the parent's form (Drupal\ui_patterns\Plugin\UiPatterns\Source\ComponentSource::settingsForm()). Because the tree nests, one selection rebuilds the configuration form of the entire subtree: 35 component_form elements, 173 closed-state prop rows and 98 slot source rows for a click on one container. Note that settingsFormPropsOnly() sets #render_slots => FALSE, but that only maps to #access, which hides the elements without preventing their build cost.
Per-row cost amplifier (see the companion ui_patterns issue): every prop/slot row resolves its source-plugin candidates through SourcePluginManager::getDefinitionsForPropType(), which passes its prop-type-filtered definitions as $input_definitions to getDefinitionsMatchingContextsAndTags() — and that static cache is only used when $input_definitions === NULL. So each of the 271 rows re-runs ContextHandler::filterPluginDefinitionsByContexts() over every source plugin definition (293k checkRequirements() calls, 2.4M ContextDefinition::isSatisfiedBy() calls).
Proposed fix
A nested component in a parent's form does not need its configuration form at all: display builder already provides the interaction to configure a child — select it on the canvas, which fires its own contextual form request for that child only.
Override in Drupal\display_builder\Plugin\UiPatterns\Source\ComponentSource:
settingsForm() becomes a lazy summary for a stored component: the component_id hidden field (so the stored settings shape is unchanged) plus a read-only hint that the component is configured in its own panel.
The full upstream form (chooser + component_form) is kept for the not-yet-configured case (empty component_id), moved into a private buildFullSettingsForm().
settingsFormPropsOnly() — the selected component's own panel — now calls buildFullSettingsForm() instead of settingsForm(), so its behavior (props form of the selected component, slots hidden) is unchanged.
LayoutSource is untouched: the heavy recursion measured in the profile is entirely component sources.
Result
Same request, same node, xhprof on both runs:
Metric Before After
Total request time 92.8 s 9.7 s / 5.7 s
component_form elements built 35 6
getSourceDefinitions() calls 271 66
Issue fork display_builder-3631254
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 #2
prince.wangComment #4
prince.wangComment #7
mogtofu33 commentedThanks for the profiling, it pointed right at the cause.
The tree owns the slots and writes them back on save, so the Config panel does not need them.
Dropping them from the form's default value in
ComponentSource::settingsFormPropsOnly()skips the forms of every nested component.On a container with 135 nodes below, the panel now builds 1 component form instead of 13 and takes 104 ms instead of 670.
MR !480 gets to 148 ms on the same container with a much larger change, so I would go with this smaller fix and its kernel test.
Comment #9
mogtofu33 commentedComment #11
pdureau commented