Skip to content

Commit

Permalink
perf: add config Optimize and move $configCacheEnabled
Browse files Browse the repository at this point in the history
The Cache Config class that extends BaseConfig is very slow to instantiate..
See codeigniter4#8558 (comment)
  • Loading branch information
kenjis committed Mar 7, 2024
1 parent 6ef36bd commit a241659
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
9 changes: 0 additions & 9 deletions app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,4 @@ class Cache extends BaseConfig
* @var bool|list<string>
*/
public $cacheQueryString = false;

/**
* --------------------------------------------------------------------------
* Config Caching
* --------------------------------------------------------------------------
*
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
*/
public bool $configCacheEnabled = false;
}
23 changes: 23 additions & 0 deletions app/Config/Optimize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Config;

/**
* Optimization Configuration.
*
* NOTE: This class does not extend BaseConfig for performance reasons.
* So you cannot replace the property values with Environment Variables.
*
* @immutable
*/
class Optimize
{
/**
* --------------------------------------------------------------------------
* Config Caching
* --------------------------------------------------------------------------
*
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
*/
public bool $configCacheEnabled = false;
}
5 changes: 3 additions & 2 deletions system/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use CodeIgniter\Config\DotEnv;
use CodeIgniter\Exceptions\FrameworkException;
use Config\Autoload;
use Config\Cache;
use Config\Modules;
use Config\Optimize;
use Config\Paths;
use Config\Services;

Expand Down Expand Up @@ -54,7 +54,8 @@ public static function bootWeb(Paths $paths): int
static::checkMissingExtensions();
static::initializeKint();

$configCacheEnabled = (new Cache())->configCacheEnabled ?? false;
$configCacheEnabled = class_exists(Optimize::class)
&& (new Optimize())->configCacheEnabled;
if ($configCacheEnabled) {
$factoriesCache = static::loadConfigCache();
}
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/concepts/factories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ How to Enable Config Caching

.. versionadded:: 4.5.0

Set the following property to ``true`` in **app/Config/Cache.php**::
Set the following property to ``true`` in **app/Config/Optimize.php**::

public bool $configCacheEnabled = true;

Expand Down

0 comments on commit a241659

Please sign in to comment.