From 0747e96b9cdab9ce493cd13b1c2c407ef09bc28c Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 22 Aug 2016 23:49:46 +0200 Subject: [PATCH] Cache registered autoloaders This saves more than 20ms (!) on every request, the previous problem was that `\OC_App::registerAutoloading` calls `\OC\AppFramework\App::buildAppNamespace` which parses the appinfo.xml. Since that was also called multiple times (e.g. on cloud.nextcloud.com over 200 times) that had a significant performance impact. Also on simple PROPFIND requests. https://blackfire.io/profiles/compare/65a53e6e-7f35-4974-b559-4c81abd01c3b/graph shows the difference nicely. --- lib/private/legacy/app.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index ceb36449bf..955173fe17 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -66,6 +66,7 @@ class OC_App { static private $appTypes = array(); static private $loadedApps = array(); static private $altLogin = array(); + static private $alreadyRegistered = []; const officialApp = 200; /** @@ -167,6 +168,11 @@ class OC_App { * @param string $path */ public static function registerAutoloading($app, $path) { + $key = $app . '-' . $path; + if(isset(self::$alreadyRegistered[$key])) { + return; + } + self::$alreadyRegistered[$key] = true; // Register on PSR-4 composer autoloader $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true);