Repository navigation
Conversation
GromNaN
reviewed
Nov 14, 2026
| { | ||
| $context += $this->env->getGlobals(); | ||
| $blocks = array_merge($this->blocks, $blocks); | ||
| $blocks = $blocks ? ($this->blocks ? array_merge($this->blocks, $blocks) : $blocks) : $this->blocks; |
Contributor
There was a problem hiding this comment.
Even if PHP optimizes the empty-argument case (php/php-src#24404), this change remains better: the PHP shortcut only avoids the copy, which copy-on-write already makes unnecessary, while this check also skips the function call and the linear scan of the $this->blocks keys.
`Template::yield()` runs once per render, include and embed. It called `array_merge($this->blocks, $blocks)` even when one side is empty, and `Environment::getGlobals()` re-checked that the extensions are initialized before returning the already resolved globals. The merge is now skipped when one side is empty (block names are never numeric, so the result is the same). `getGlobals()` returns `$this->resolvedGlobals` first when it is set. `yield()` of a small template goes from 554-564 -> 486-497 ns, and `getGlobals()` from 86-89 -> 43-44 ns.
Kocal
force-pushed
the
perf/render-prologue
branch
from
November 15, 2026 08:05
99436fe to
0bd0581
Compare
nicolas-grekas
approved these changes
Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Template::yield()runs once per render, include and embed. It calledarray_merge($this->blocks, $blocks)even when one side is empty, andEnvironment::getGlobals()re-checked that the extensions are initialized before returning the already resolved globals.The merge is now skipped when one side is empty (block names are never numeric, so the result is the same).
getGlobals()returns$this->resolvedGlobalsfirst when it is set.yield()of a small template goes from 554-564 -> 486-497 ns, andgetGlobals()from 86-89 -> 43-44 ns.