[TASK] Autoloader performance improvement
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 1 Jul 2012 10:59:18 +0000 (12:59 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Sun, 1 Jul 2012 13:20:49 +0000 (15:20 +0200)
If the autoload registry is read from cache, all class names are
already lowercased. The patch calls the lowercase logic only if
the registry files are not read from cache. The unit tests show
that nothing breaks with this patch.

Cachegrind shows ~22% of rendering time is spend in
loadCoreAndExtensionRegistry() on a fully cached page,
this is reduced to ~2% with the patch.

Change-Id: I07dc95b29bf05970061b5fb2f9a5d8a5ba194960
Resolves: #38498
Releases: 6.0
Reviewed-on: http://review.typo3.org/12494
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
t3lib/class.t3lib_autoloader.php

index f2ac8a9..564de46 100644 (file)
@@ -143,7 +143,7 @@ class t3lib_autoloader {
                        $classRegistry = $phpCodeCache->requireOnce(self::getAutoloadCacheIdentifier());
                } else {
                        self::$cacheUpdateRequired = TRUE;
-                       $classRegistry = self::createCoreAndExtensionRegistry();
+                       $classRegistry = self::lowerCaseClassRegistry(self::createCoreAndExtensionRegistry());
                }
 
                        // This can only happen if the autoloader was already registered
@@ -154,18 +154,11 @@ class t3lib_autoloader {
                        // switched to NullBackend for example to simplify development
                if (!is_array($classRegistry)) {
                        self::$cacheUpdateRequired = TRUE;
-                       $classRegistry = self::createCoreAndExtensionRegistry();
+                       $classRegistry = self::lowerCaseClassRegistry(self::createCoreAndExtensionRegistry());
                }
 
-                       // Lowercase all keys. We must use the multi byte safe version
-                       // of strtolower from t3lib_div here, so array_change_key_case()
-                       // can not be used
-               $lowerCasedClassRegistry = array();
-               foreach ($classRegistry as $className => $classFile) {
-                       $lowerCasedClassRegistry[t3lib_div::strtolower($className)] = $classFile;
-               }
 
-               self::$classNameToFileMapping = $lowerCasedClassRegistry;
+               self::$classNameToFileMapping = $classRegistry;
        }
 
        /**
@@ -391,5 +384,22 @@ class t3lib_autoloader {
                }
                return self::$autoloadCacheIdentifier;
        }
+
+       /**
+        * Lowercase all keys of the class registry.
+        *
+        * Use the multi byte safe version of strtolower from t3lib_div,
+        * so array_change_key_case() can not be used
+        *
+        * @param array $registry Given registry entries
+        * @return array with lower cased keys
+        */
+       protected static function lowerCaseClassRegistry($registry) {
+               $lowerCasedClassRegistry = array();
+               foreach ($registry as $className => $classFile) {
+                       $lowerCasedClassRegistry[t3lib_div::strtolower($className)] = $classFile;
+               }
+               return $lowerCasedClassRegistry;
+       }
 }
 ?>
\ No newline at end of file