From 2d30592f72408508e74ae649adce875ad6994036 Mon Sep 17 00:00:00 2001 From: Cam Spiers Date: Mon, 8 Jul 2013 20:41:46 +1200 Subject: [PATCH] Improve memory performance when generating config static and class caches --- core/manifest/ClassManifest.php | 13 ++++++++++++- core/manifest/ConfigStaticManifest.php | 2 +- tests/core/manifest/ClassManifestTest.php | 13 ++++++++----- .../manifest/NamespacedClassManifestTest.php | 19 +++++++++++-------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/core/manifest/ClassManifest.php b/core/manifest/ClassManifest.php index ded2f4839..042871f21 100644 --- a/core/manifest/ClassManifest.php +++ b/core/manifest/ClassManifest.php @@ -273,6 +273,15 @@ class SS_ClassManifest { return $modules; } + /** + * Used to set up files that we want to exclude from parsing for performance reasons. + */ + protected function setDefaults() + { + $this->classes['sstemplateparser'] = FRAMEWORK_PATH.'/view/SSTemplateParser.php'; + $this->classes['sstemplateparseexception'] = FRAMEWORK_PATH.'/view/SSTemplateParser.php'; + } + /** * Completely regenerates the manifest file. * @@ -289,10 +298,12 @@ class SS_ClassManifest { $this->$reset = array(); } + $this->setDefaults(); + $finder = new ManifestFileFinder(); $finder->setOptions(array( 'name_regex' => '/^(_config.php|[^_].*\.php)$/', - 'ignore_files' => array('index.php', 'main.php', 'cli-script.php'), + 'ignore_files' => array('index.php', 'main.php', 'cli-script.php', 'SSTemplateParser.php'), 'ignore_tests' => !$this->tests, 'file_callback' => array($this, 'handleFile'), 'dir_callback' => array($this, 'handleDir') diff --git a/core/manifest/ConfigStaticManifest.php b/core/manifest/ConfigStaticManifest.php index 5dddd9266..4f3776816 100644 --- a/core/manifest/ConfigStaticManifest.php +++ b/core/manifest/ConfigStaticManifest.php @@ -100,7 +100,7 @@ class SS_ConfigStaticManifest { $finder = new ManifestFileFinder(); $finder->setOptions(array( 'name_regex' => '/^([^_].*\.php)$/', - 'ignore_files' => array('index.php', 'main.php', 'cli-script.php'), + 'ignore_files' => array('index.php', 'main.php', 'cli-script.php', 'SSTemplateParser.php'), 'ignore_tests' => !$this->tests, 'file_callback' => array($this, 'handleFile') )); diff --git a/tests/core/manifest/ClassManifestTest.php b/tests/core/manifest/ClassManifestTest.php index 64fd0a1a4..fa82e8d12 100644 --- a/tests/core/manifest/ClassManifestTest.php +++ b/tests/core/manifest/ClassManifestTest.php @@ -36,17 +36,20 @@ class ClassManifestTest extends SapphireTest { public function testGetClasses() { $expect = array( - 'classa' => "{$this->base}/module/classes/ClassA.php", - 'classb' => "{$this->base}/module/classes/ClassB.php", - 'classc' => "{$this->base}/module/classes/ClassC.php", - 'classd' => "{$this->base}/module/classes/ClassD.php" + 'classb' => "{$this->base}/module/classes/ClassB.php", + 'classa' => "{$this->base}/module/classes/ClassA.php", + 'classb' => "{$this->base}/module/classes/ClassB.php", + 'classc' => "{$this->base}/module/classes/ClassC.php", + 'classd' => "{$this->base}/module/classes/ClassD.php", + 'sstemplateparser' => FRAMEWORK_PATH."/view/SSTemplateParser.php", + 'sstemplateparseexception' => FRAMEWORK_PATH."/view/SSTemplateParser.php" ); $this->assertEquals($expect, $this->manifest->getClasses()); } public function testGetClassNames() { $this->assertEquals( - array('classa', 'classb', 'classc', 'classd'), + array('sstemplateparser', 'sstemplateparseexception', 'classa', 'classb', 'classc', 'classd'), $this->manifest->getClassNames()); } diff --git a/tests/core/manifest/NamespacedClassManifestTest.php b/tests/core/manifest/NamespacedClassManifestTest.php index 7cc2df39d..c87dea4e4 100644 --- a/tests/core/manifest/NamespacedClassManifestTest.php +++ b/tests/core/manifest/NamespacedClassManifestTest.php @@ -12,7 +12,7 @@ class NamespacedClassManifestTest extends SapphireTest { public function setUp() { parent::setUp(); - + $this->base = dirname(__FILE__) . '/fixtures/namespaced_classmanifest'; $this->manifest = new SS_ClassManifest($this->base, false, true, false); } @@ -41,17 +41,20 @@ class NamespacedClassManifestTest extends SapphireTest { 'silverstripe\test\classe' => "{$this->base}/module/classes/ClassE.php", 'silverstripe\test\classf' => "{$this->base}/module/classes/ClassF.php", 'silverstripe\test\classg' => "{$this->base}/module/classes/ClassG.php", - 'silverstripe\test\classh' => "{$this->base}/module/classes/ClassH.php" + 'silverstripe\test\classh' => "{$this->base}/module/classes/ClassH.php", + 'sstemplateparser' => FRAMEWORK_PATH."/view/SSTemplateParser.php", + 'sstemplateparseexception' => FRAMEWORK_PATH."/view/SSTemplateParser.php" ); - + $this->assertEquals($expect, $this->manifest->getClasses()); } public function testGetClassNames() { $this->assertEquals( - array('silverstripe\test\classa', 'silverstripe\test\classb', 'silverstripe\test\classc', - 'silverstripe\test\classd', 'silverstripe\test\classe', 'silverstripe\test\classf', - 'silverstripe\test\classg', 'silverstripe\test\classh'), + array('sstemplateparser', 'sstemplateparseexception', 'silverstripe\test\classa', + 'silverstripe\test\classb', 'silverstripe\test\classc', 'silverstripe\test\classd', + 'silverstripe\test\classe', 'silverstripe\test\classf', 'silverstripe\test\classg', + 'silverstripe\test\classh'), $this->manifest->getClassNames()); } @@ -59,7 +62,7 @@ class NamespacedClassManifestTest extends SapphireTest { $expect = array( 'silverstripe\test\classa' => array('silverstripe\test\ClassB', 'silverstripe\test\ClassH'), ); - + $this->assertEquals($expect, $this->manifest->getDescendants()); } @@ -109,7 +112,7 @@ class NamespacedClassManifestTest extends SapphireTest { $expect = array("{$this->base}/module/_config.php"); $this->assertEquals($expect, $this->manifest->getConfigs()); } - + public function testGetModules() { $expect = array( "module" => "{$this->base}/module",