Problem/Motivation

Drupal includes some files in the autoload classmap section of core/composer.json that we know are loaded on every request - this avoids having to locate the files and cache them in APCu.

We haven't updated this list for a while, and it definitely doesn't include Symfony runtime and related files recently added which are some of the first classes to be loaded during any bootstrap.

Steps to reproduce

Proposed resolution

On a page cache hit, see which files go via the classloader findFile method and add them to the classmap.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

catch created an issue.

berdir’s picture

I automated this in a CI step for the php preload feature.

Using this patch:

diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php
index 7824d8f7ea..0a2ac4a847 100644
--- a/vendor/composer/ClassLoader.php
+++ b/vendor/composer/ClassLoader.php
@@ -423,6 +423,10 @@ public function unregister()
     public function loadClass($class)
     {
         if ($file = $this->findFile($class)) {
+            if (!str_contains($file, 'RequestTraceEventSubscriber.php') && !str_contains($file, 'TransportFactoryInterface.php') && !str_contains($file, 'LogsMessagesTrait.php')) {
+              $preload_filename = str_replace(dirname(getcwd()) . '/', '', realpath($file));
+              file_put_contents('../preload.php',  "opcache_compile_file('$preload_filename');\n", FILE_APPEND);
+            }
             $includeFile = self::$includeFile;
             $includeFile($file);

(the excludes are from opentelemetry, had errors from those, so excluding)

And then CI steps include warming the cache, then adding a new preload.php, applying the patch and adding those files to the preload list (dynamic page cache hit in my case).

This could possibly be adjusted for core.