Problem/Motivation

\Drupal\Core\Composer\Composer::preAutoloadDump() contains a list of critical code that is required for all Drupal bootstraps. This was last updated for Symfony 4 and it is possible that Symfony 5/6 has added or removed things to this list.

Steps to reproduce

Proposed resolution

Analyse the classes required for bootstrap and update the list.
Figure out if there is a way of automating this or adding test coverage.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

longwave created an issue. See original summary.

alexpott’s picture

@longwave asked about testing thhis. I think we could add a module that records the loading classes in middleware which runs right after page cache and then ensures that they are in static classmap from composer. We might have to add some exceptions. Core modules are pita because we don’t get them via composer. Otherwise the db drivers could influence this in the regular composer way.

I also think we could consider adding a tool to core to use PHP’s class preloading feature to preload all the classes used up to a cached page response.

catch’s picture

Cross posting #2704571: Add an APCu classloader with a single entry - for recording early-bootstrap classes we'd probably want an caching autoloader with a killswitch so it stops lookup at an arbitrary point in the request.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new2.95 KB
new5.68 KB

We only need the classmap until the container is initialised, so to do this we can replace the container with a logging container that records the classes loaded up until that point.

The whole test feels like a bit of a hack and relies on some Composer internals, but hopefully these won't change too much in the future.

longwave’s picture

StatusFileSize
new2.97 KB
new5.71 KB
longwave’s picture

StatusFileSize
new2.63 KB
new5.37 KB
new1.25 KB

We don't need to rely on Composer internals, there is a public method we can use.

The last submitted patch, 5: 3293286-5.patch, failed testing. View results

The last submitted patch, 5: 3293286-5-test-only.patch, failed testing. View results

The last submitted patch, 6: 3293286-6-test-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 6: 3293286-6.patch, failed testing. View results

alexpott’s picture

I still think we should be adding all the classes that are used up to serving a cached page via middleware. Both Drupal and our dependencies. We should try to validate the classmap in core/composer.json too.

longwave’s picture

I thought sites that cared about performance would be using apcu which takes over at that point? The apcu prefix is set immediately after container init.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.