From 8a9a040d380e96818c657009dba7f9a094017f4a Mon Sep 17 00:00:00 2001 From: Mateus de Lima Oliveira Date: Thu, 15 Sep 2022 14:42:15 -0300 Subject: [PATCH 1/4] Create a checksum of the config file in memory. This fixes a massive performance bug when opcache is enabled. I have tested it on the stable version. I copy-pasted the changes on the master branch. Please test it on the master branch and tell me if it worked. Signed-off-by: Mateus de Lima Oliveira --- lib/private/Config.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/private/Config.php b/lib/private/Config.php index e338d3f2332b2..e90f36360638e 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -59,6 +59,8 @@ class Config { protected $configFileName; /** @var bool */ protected $isReadOnly; + /** @var int */ + protected $lastChecksum : int; /** * @param string $configDir Path to the config dir, needs to end with '/' @@ -259,10 +261,23 @@ private function writeData() { throw new HintException(sprintf('Configuration was not read or initialized correctly, not overwriting %s', $this->configFilePath)); } + /* This creates a checksum of the config file in memory. + * The config file opcache code is only invalidated if the + * config file data has been changed therefore all the other + * code that depend on the the config file opcode will not + * be recompiled. */ + $data = var_export($this->cache, true); + $currentChecksum = crc32($data); + + if ($this->getLastChecksum() == $currentChecksum) + return; + + $this->lastChecksum = $currentChecksum; + // Create a php file ... $content = "cache, true); + $content .= $data; $content .= ";\n"; // tmpfile must be in the same filesystem for the rename() to be atomic @@ -316,4 +331,12 @@ private function checkReadOnly(): void { 'Unset "config_is_read_only" to allow changes to the config file.'); } } + + private function getLastChecksum(): int { + if ($this->lastChecksum == null) { + $data = file_get_contents($this->configFilePath); + $this->lastChecksum = crc32($data); + } + return $this->lastChecksum; + } } From 42a7d5fcb0bc01336bd632bcbffb3d4ca3c41180 Mon Sep 17 00:00:00 2001 From: Mateus de Lima Oliveira Date: Thu, 15 Sep 2022 16:15:58 -0300 Subject: [PATCH 2/4] Removed static typing Removed static typing. It caused some build tests to fail. Co-authored-by: Daniel Signed-off-by: Mateus de Lima Oliveira --- lib/private/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Config.php b/lib/private/Config.php index e90f36360638e..772e56e37f05e 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -60,7 +60,7 @@ class Config { /** @var bool */ protected $isReadOnly; /** @var int */ - protected $lastChecksum : int; + protected $lastChecksum; /** * @param string $configDir Path to the config dir, needs to end with '/' From 1a20ac7a36b4464b79fb35f375bec2974395d8ed Mon Sep 17 00:00:00 2001 From: Mateus de Lima Oliveira Date: Fri, 16 Sep 2022 11:43:54 -0300 Subject: [PATCH 3/4] Fixed opcache reset performance bug opcache must only be reset if there needs upgrade AND maintenance is true. Signed-off-by: Mateus de Lima Oliveira --- lib/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/base.php b/lib/base.php index 055cc6786f02e..47ee2b262ba26 100644 --- a/lib/base.php +++ b/lib/base.php @@ -990,10 +990,10 @@ public static function handleRequest() { self::checkMaintenanceMode($systemConfig); if (\OCP\Util::needUpgrade()) { - if (function_exists('opcache_reset')) { - opcache_reset(); - } if (!((bool) $systemConfig->getValue('maintenance', false))) { + if (function_exists('opcache_reset')) { + opcache_reset(); + } self::printUpgradePage($systemConfig); exit(); } From 263c83ea7e8853ac198849d9c7a7122edb6b5cfa Mon Sep 17 00:00:00 2001 From: Mateus de Lima Oliveira Date: Fri, 16 Sep 2022 20:10:36 -0300 Subject: [PATCH 4/4] Disabled updates of the same value Disabled updates on the configuration of the same values with diferent types. Signed-off-by: Mateus de Lima Oliveira --- lib/private/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Config.php b/lib/private/Config.php index 772e56e37f05e..48ca3d3dc7936 100644 --- a/lib/private/Config.php +++ b/lib/private/Config.php @@ -157,7 +157,7 @@ public function setValue($key, $value) { protected function set($key, $value) { $this->checkReadOnly(); - if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) { + if (!isset($this->cache[$key]) || $this->cache[$key] != $value) { // Add change $this->cache[$key] = $value; return true;