From 7da4f03a5becd455bdc44c86bc2e03a6ccb12018 Mon Sep 17 00:00:00 2001 From: Sam James Date: Wed, 15 Jul 2026 22:44:29 +0100 Subject: [PATCH] perf: skip pagebuilder preload regex scan for blocks with no preload image view_block_abstract_to_html_after fires for every block on every page (no block-type filter), so the 4-part chained-lazy-quantifier regex here was running against the full HTML of every block on every request, even though only a handful of PageBuilder image elements can ever match. Add a cheap str_contains() guard for the literal preload="Yes" marker before running the regex, ruling out the vast majority of blocks with effectively no cost. --- Observer/View/BlockToHtmlAfter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Observer/View/BlockToHtmlAfter.php b/Observer/View/BlockToHtmlAfter.php index e8c7403..2bd8d8b 100644 --- a/Observer/View/BlockToHtmlAfter.php +++ b/Observer/View/BlockToHtmlAfter.php @@ -25,12 +25,17 @@ public function execute(Observer $observer) /** @var DataObject */ $transport = $observer->getEvent()->getTransport(); + $html = $transport->getHtml(); + + if (!str_contains($html, 'preload="Yes"')) { + return; + } $matches = []; // @TODO: Only preload images with the `preload` attribute set preg_match_all( '//', - $transport->getHtml(), + $html, $matches );