`GlobalRuntimeState::$interpolatedVariables` is never reset, so long-running Antlers renders slow down without bound
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 领域
- backend, performance
调研方向
Read GlobalRuntimeState::resetGlobalState() and the append in DocumentParser.php (the issue gives line numbers for several branches). Check the existing runtime state reset tests, then verify that resetting clears interpolatedVariables and that repeated renders no longer accumulate entries. Issue #15815 is an open linked pull request, so check its status before starting.
由索引模型根据 Issue 内容生成。
描述
Bug description
DocumentParser appends to GlobalRuntimeState::$interpolatedVariables every time it parses a template with an interpolated region (DocumentParser.php line 1071 in 5.x, 1242 on master, 1462 in 6.39.0):
GlobalRuntimeState::$interpolatedVariables[] = $results[2];
Environment::getValue() then checks every StringValueNode in every condition against the whole list:
if (Str::contains($val->value, GlobalRuntimeState::$interpolatedVariables)) {
Nothing ever empties the list. GlobalRuntimeState::resetGlobalState(), called per request through StateManager::resetState() by the ClearState listener on RequestHandled and ResponseCreated, resets every other piece of runtime state (templateFileStack, yieldStacks, layoutVariables and so on) but not $interpolatedVariables.
Under PHP-FPM each request is a fresh process, so this goes unnoticed. In any long-lived process that renders many views (statamic/ssg with workers, queue workers rendering views, Octane), the list grows with every request and every condition gets slower.
Measured
Static site generation (statamic/ssg, --workers=4) of a ~3,900-page site, rendering in one PHP process:
- The list grew by about 118 entries per page (about 95 unique), reaching 23,718 entries after 200 pages.
- Mean render time per page rose from about 0.7s to 1.5 to 1.7s over 500 pages.
- A sampling profile of early against late pages attributed the growth to
Str::containsunderEnvironment::getValue(about 56ms to 659ms per page). - Clearing the list after each request kept render time flat. 500 pages took 274s instead of 512s, and a full build roughly halved. Page output was byte-identical, apart from per-render
uniqid()values.
How to reproduce
Render the same Antlers view many times in one process, with a template that has an interpolated tag parameter (for example {{ partial:card :title="{title}" }} or {{ link to="/x/{slug}" }}), and dispatch RequestHandled between renders as the HTTP kernel does. count(GlobalRuntimeState::$interpolatedVariables) grows on every iteration, and the cost of conditions grows with it.
Suggested fix
Clear it with the rest of the runtime state:
public static function resetGlobalState()
{
self::$templateFileStack = [];
// ...
self::$interpolatedVariables = [];
// ...
}
Optionally, de-duplicate on append, or store it as a set keyed by value, so even a single long request can't grow it with duplicates.
Environment
- Statamic 5.73.22 (also unchanged in 5.74.7, 6.40.0 and master as of 2026-11-07)
- statamic/ssg 3.1.1, Laravel 10, PHP 8.3
- Antlers runtime parser (
'version' => 'runtime')
- 主要语言
- PHP
- 星标
- 4.9k
- 派生
- 647
- 平均合并
- 21 小时 3 分钟
- 30 天内合并 PR
- 128
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
statamic/cms 的其他 Issue
-
Passing `null` to `bool_string` modifier returns nothing instead of `false`可能已有人在做 @shadetheory 于 4 天前认领。 未关闭modifiers
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
accessibility
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
antlers
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
`please` cannot run app commands from app/Console/Commands on Laravel 13.36+可能已有人在做 @lazerg 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
维护者通常 1 天内回复
-
Command palette doesn’t index non published items可能已有人在做 @lazerg 于 1 天前认领。 未关闭search
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
Automattic/blocks-engine#5003 ·
维护者通常 1 天内回复
-
from-cloud mythic tracked
难度 1/5 1 小时以内 新手友好度 86/100
MythicalLTD/FeatherPanel#459 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: PostgreSQL backend: Queue.remove() / Job.remove() never emit the QueueEvents "removed" event可能已有人在做 @1AbdullahButt 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
taskforcesh/bullmq#5085 ·
维护者通常 1 天内回复
-
area:mesi area:php-extension good first issue priority:low type:chore
难度 2/5 1-3 小时 新手友好度 85/100
crazy-goat/go-mesi#652 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
shukiv/jabali-panel#2423 ·
维护者通常 1 天内回复