From cd07182e9cfe64dae86418275cec8aef602e796b Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 1 Apr 2013 12:05:49 -0700 Subject: [PATCH] Provide a local cache for PhabricatorEnv Summary: We hit some env config fairly often (~200 calls on the home page) and it's not especially cheap right now. This saves about 10ms on home, which is ~8% of the page weight on my machine. Test Plan: Clicked around, everything seemed fine. Unit tests. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D5512 --- src/__celerity_resource_map__.php | 80 +++++++++++------------ src/infrastructure/env/PhabricatorEnv.php | 20 ++++++ 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index df894106ee..9f20dac0bf 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -794,7 +794,7 @@ celerity_register_resource_map(array( ), 'aphront-panel-view-css' => array( - 'uri' => '/res/5600525c/rsrc/css/aphront/panel-view.css', + 'uri' => '/res/3d1420b3/rsrc/css/aphront/panel-view.css', 'type' => 'css', 'requires' => array( @@ -2975,7 +2975,7 @@ celerity_register_resource_map(array( ), 'phabricator-jump-nav' => array( - 'uri' => '/res/b33dd475/rsrc/css/application/directory/phabricator-jump-nav.css', + 'uri' => '/res/2e0e2211/rsrc/css/application/directory/phabricator-jump-nav.css', 'type' => 'css', 'requires' => array( @@ -3805,7 +3805,7 @@ celerity_register_resource_map(array( ), array( 'packages' => array( - '1f04085c' => + '4fc2a8f9' => array( 'name' => 'core.pkg.css', 'symbols' => @@ -3847,7 +3847,7 @@ celerity_register_resource_map(array( 34 => 'phabricator-object-item-list-view-css', 35 => 'global-drag-and-drop-css', ), - 'uri' => '/res/pkg/1f04085c/core.pkg.css', + 'uri' => '/res/pkg/4fc2a8f9/core.pkg.css', 'type' => 'css', ), 'def4c982' => @@ -4038,16 +4038,16 @@ celerity_register_resource_map(array( 'reverse' => array( 'aphront-attached-file-view-css' => '6b1fccc6', - 'aphront-dialog-view-css' => '1f04085c', - 'aphront-error-view-css' => '1f04085c', - 'aphront-form-view-css' => '1f04085c', - 'aphront-list-filter-view-css' => '1f04085c', - 'aphront-pager-view-css' => '1f04085c', - 'aphront-panel-view-css' => '1f04085c', - 'aphront-table-view-css' => '1f04085c', - 'aphront-tokenizer-control-css' => '1f04085c', - 'aphront-tooltip-css' => '1f04085c', - 'aphront-typeahead-control-css' => '1f04085c', + 'aphront-dialog-view-css' => '4fc2a8f9', + 'aphront-error-view-css' => '4fc2a8f9', + 'aphront-form-view-css' => '4fc2a8f9', + 'aphront-list-filter-view-css' => '4fc2a8f9', + 'aphront-pager-view-css' => '4fc2a8f9', + 'aphront-panel-view-css' => '4fc2a8f9', + 'aphront-table-view-css' => '4fc2a8f9', + 'aphront-tokenizer-control-css' => '4fc2a8f9', + 'aphront-tooltip-css' => '4fc2a8f9', + 'aphront-typeahead-control-css' => '4fc2a8f9', 'differential-changeset-view-css' => '8aaacd1b', 'differential-core-view-css' => '8aaacd1b', 'differential-inline-comment-editor' => '67ea27d0', @@ -4061,7 +4061,7 @@ celerity_register_resource_map(array( 'differential-table-of-contents-css' => '8aaacd1b', 'diffusion-commit-view-css' => 'c8ce2d88', 'diffusion-icons-css' => 'c8ce2d88', - 'global-drag-and-drop-css' => '1f04085c', + 'global-drag-and-drop-css' => '4fc2a8f9', 'inline-comment-summary-css' => '8aaacd1b', 'javelin-aphlict' => 'def4c982', 'javelin-behavior' => 'fe22443b', @@ -4133,48 +4133,48 @@ celerity_register_resource_map(array( 'javelin-util' => 'fe22443b', 'javelin-vector' => 'fe22443b', 'javelin-workflow' => 'fe22443b', - 'lightbox-attachment-css' => '1f04085c', + 'lightbox-attachment-css' => '4fc2a8f9', 'maniphest-task-summary-css' => '6b1fccc6', 'maniphest-transaction-detail-css' => '6b1fccc6', 'phabricator-busy' => 'def4c982', 'phabricator-content-source-view-css' => '8aaacd1b', - 'phabricator-core-buttons-css' => '1f04085c', - 'phabricator-core-css' => '1f04085c', - 'phabricator-crumbs-view-css' => '1f04085c', - 'phabricator-directory-css' => '1f04085c', + 'phabricator-core-buttons-css' => '4fc2a8f9', + 'phabricator-core-css' => '4fc2a8f9', + 'phabricator-crumbs-view-css' => '4fc2a8f9', + 'phabricator-directory-css' => '4fc2a8f9', 'phabricator-drag-and-drop-file-upload' => '67ea27d0', 'phabricator-dropdown-menu' => 'def4c982', 'phabricator-file-upload' => 'def4c982', - 'phabricator-filetree-view-css' => '1f04085c', - 'phabricator-flag-css' => '1f04085c', - 'phabricator-form-view-css' => '1f04085c', - 'phabricator-header-view-css' => '1f04085c', - 'phabricator-jump-nav' => '1f04085c', + 'phabricator-filetree-view-css' => '4fc2a8f9', + 'phabricator-flag-css' => '4fc2a8f9', + 'phabricator-form-view-css' => '4fc2a8f9', + 'phabricator-header-view-css' => '4fc2a8f9', + 'phabricator-jump-nav' => '4fc2a8f9', 'phabricator-keyboard-shortcut' => 'def4c982', 'phabricator-keyboard-shortcut-manager' => 'def4c982', - 'phabricator-main-menu-view' => '1f04085c', + 'phabricator-main-menu-view' => '4fc2a8f9', 'phabricator-menu-item' => 'def4c982', - 'phabricator-nav-view-css' => '1f04085c', + 'phabricator-nav-view-css' => '4fc2a8f9', 'phabricator-notification' => 'def4c982', - 'phabricator-notification-css' => '1f04085c', - 'phabricator-notification-menu-css' => '1f04085c', - 'phabricator-object-item-list-view-css' => '1f04085c', + 'phabricator-notification-css' => '4fc2a8f9', + 'phabricator-notification-menu-css' => '4fc2a8f9', + 'phabricator-object-item-list-view-css' => '4fc2a8f9', 'phabricator-object-selector-css' => '8aaacd1b', 'phabricator-paste-file-upload' => 'def4c982', 'phabricator-prefab' => 'def4c982', 'phabricator-project-tag-css' => '6b1fccc6', - 'phabricator-remarkup-css' => '1f04085c', + 'phabricator-remarkup-css' => '4fc2a8f9', 'phabricator-shaped-request' => '67ea27d0', - 'phabricator-side-menu-view-css' => '1f04085c', - 'phabricator-standard-page-view' => '1f04085c', + 'phabricator-side-menu-view-css' => '4fc2a8f9', + 'phabricator-standard-page-view' => '4fc2a8f9', 'phabricator-textareautils' => 'def4c982', 'phabricator-tooltip' => 'def4c982', - 'phabricator-transaction-view-css' => '1f04085c', - 'phabricator-zindex-css' => '1f04085c', - 'sprite-apps-large-css' => '1f04085c', - 'sprite-gradient-css' => '1f04085c', - 'sprite-icon-css' => '1f04085c', - 'sprite-menu-css' => '1f04085c', - 'syntax-highlighting-css' => '1f04085c', + 'phabricator-transaction-view-css' => '4fc2a8f9', + 'phabricator-zindex-css' => '4fc2a8f9', + 'sprite-apps-large-css' => '4fc2a8f9', + 'sprite-gradient-css' => '4fc2a8f9', + 'sprite-icon-css' => '4fc2a8f9', + 'sprite-menu-css' => '4fc2a8f9', + 'syntax-highlighting-css' => '4fc2a8f9', ), )); diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 27d5fcebb0..394f5e33a6 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -54,6 +54,7 @@ final class PhabricatorEnv { private static $repairSource; private static $overrideSource; private static $requestBaseURI; + private static $cache; /** * @phutil-external-symbol class PhabricatorStartup @@ -112,6 +113,8 @@ final class PhabricatorEnv { } private static function buildConfigurationSourceStack() { + self::dropConfigCache(); + $stack = new PhabricatorConfigStackSource(); self::$sourceStack = $stack; @@ -160,6 +163,7 @@ final class PhabricatorEnv { self::$sourceStack->pushSource(self::$repairSource); } self::$repairSource->setKeys(array($key => $value)); + self::dropConfigCache(); } public static function overrideConfig($key, $value) { @@ -169,6 +173,7 @@ final class PhabricatorEnv { self::$sourceStack->pushSource(self::$overrideSource); } self::$overrideSource->setKeys(array($key => $value)); + self::dropConfigCache(); } public static function getUnrepairedEnvConfig($key, $default = null) { @@ -220,8 +225,17 @@ final class PhabricatorEnv { * @task read */ public static function getEnvConfig($key) { + if (isset(self::$cache[$key])) { + return self::$cache[$key]; + } + + if (array_key_exists($key, self::$cache)) { + return self::$cache[$key]; + } + $result = self::$sourceStack->getKeys(array($key)); if (array_key_exists($key, $result)) { + self::$cache[$key] = $result[$key]; return $result[$key]; } else { throw new Exception("No config value specified for key '{$key}'."); @@ -335,6 +349,7 @@ final class PhabricatorEnv { * @task test */ private static function pushTestEnvironment() { + self::dropConfigCache(); $source = new PhabricatorConfigDictionarySource(array()); self::$sourceStack->pushSource($source); return spl_object_hash($source); @@ -345,6 +360,7 @@ final class PhabricatorEnv { * @task test */ public static function popTestEnvironment($key) { + self::dropConfigCache(); $source = self::$sourceStack->popSource(); $stack_key = spl_object_hash($source); if ($stack_key !== $key) { @@ -478,4 +494,8 @@ final class PhabricatorEnv { } } + private static function dropConfigCache() { + self::$cache = array(); + } + }