From: Alexander Ebert Date: Thu, 11 Apr 2024 13:33:14 +0000 (+0200) Subject: Cache the list of known HTML tag handlers X-Git-Tag: 6.1.0_Alpha_1~81^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6c5e52f67c7aa04d4838edbb6bd98f47de55e9aa;p=GitHub%2FWoltLab%2FWCF.git Cache the list of known HTML tag handlers The `\class_exists()` call for handlers that do not exist always go through the autoloaders. For large sets of documents this change improves the request latency by up to 2%. --- diff --git a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php index 17fca6196b..6ef44f7e32 100644 --- a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php @@ -320,6 +320,8 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor */ protected function invokeNodeHandlers($classNamePattern, array $skipTags = [], ?callable $callback = null) { + static $handlerClassExists = []; + $skipTags = \array_merge($skipTags, ['html', 'head', 'title', 'meta', 'body', 'link']); $tags = []; @@ -343,7 +345,15 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor return \ucfirst($matches[1]); }, $tagName); $className = $classNamePattern . \ucfirst($tagName); - if (\class_exists($className)) { + + // The `\class_exists()` call has to go through the autoloader which + // can become quite expensive when dealing with a lot of tags and + // messages within one request. + if (!isset($handlerClassExists[$className])) { + $handlerClassExists[$className] = \class_exists($className); + } + + if ($handlerClassExists[$className]) { if ($callback === null) { $this->invokeHtmlNode(new $className()); } else {