Problem/Motivation

DrupalKernel::classLoaderAddMultiplePsr4() calls ClassLoader::addPsr4() without checking which paths have already been registered. Composer's loader appends the paths, so every boot and container rebuild adds another set. On persistent app servers (e.g., FrankenPHP worker mode), the loader grows with every request, and autoload misses get slower as the number of duplicates increases.

Steps to reproduce

  1. Call $kernel->boot(); $kernel->shutdown(); several times on one kernel, then boot it again.
  2. Print $autoloader->getPrefixesPsr4()['Drupal\\system\\']. The same path appears once per boot.

Proposed resolution

Pass addPsr4() only the paths that are not yet registered. Keep the existing order, including paths added outside the kernel.

Issue fork drupal-3625995

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

ptmkenny created an issue. See original summary.

ptmkenny’s picture

Status: Active » Needs review
daffie’s picture

Status: Needs review » Needs work
ptmkenny’s picture

Status: Needs work » Needs review

I fixed the review comment and added a few more points to the test as well as some clarifying comments.

daffie’s picture

Status: Needs review » Needs work

Back to NW, for the comment from @nicxvan.