perf: a full CSS syntax memo stops memoizing, so per-route stylesheet passes re-split the same selectors (asset_writes, 56-page import)

已关闭
#7,655 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #7659 来自 @chubes4 —— 已合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
css, php

调研方向

Inspect CssRuleTreeCache::memo() and the callers CssStylesheetTransformer::splitSelectorList() and CssSelectorTokenizer::tokenize(). The relevant flow is compose.site_plan.asset_writes, SitePlanRun::finalStylesheets(), and RouteStylesheetDeliveries::specialize(); verify the cache generation reset preserves the budget and output. Run the parity fixtures and the contract test described in the issue, checking that a full memo still stores the next source without exceeding its limit.

由索引模型根据 Issue 内容生成。

描述

Problem

CssRuleTreeCache::memo() backs the compiler's flat CSS syntax memos: CssStylesheetTransformer::splitSelectorList(), CssSelectorTokenizer::tokenize() and others. Once its budget is full (65,536 entries, 524,288 scalars or 16 MiB), it stops storing new results and keeps the entries that filled it.

Those first entries come from early compose steps. Later steps work on different selectors. In compose.site_plan.asset_writes, SitePlanRun::finalStylesheets() and RouteStylesheetDeliveries::specialize() run several passes over every stylesheet, and specialize() repeats those passes for each route's copy of a stylesheet. By then the memo is full, so every pass splits and tokenizes the same selector lists again. Each split is a byte scan of a long projected selector list.

Evidence: Wix site, 56 pages, php-transformer v0.52.42 (2f89a38)

I ran a standalone ArtifactCompiler::compose() on the retained Static Site Importer shared plan and 56 compiled receipts, profiled with excimer:

  • compose.site_plan.asset_writes took 233 s of a 1,543 s compose. finalStylesheets took 117 s and specialize took 85 s. Inputs at that point: 1,005 CSS assets (34.5 MB).
  • RouteStylesheetDeliveries::specialize() alone, on its captured inputs, made 1,839,645 splitSelectorList() calls over 42,239 distinct preludes. 729,899 of them missed the memo and re-split 164 MB of selector text. The memo held only 19,243 entries: their 16 MiB byte budget was full.
  • Across the whole compose, memo misses (CssRuleTreeCache::memo inclusive) cost 937 s of 3,266 s on a loaded host. splitSelectorListUncached took 499 s and tokenizeUncached took 207 s.

Fix (generic, output-preserving)

When an entry would exceed the budget, clear the memo and start a new generation, instead of refusing the entry. The memo stays bounded by the same budgets, and the entries it keeps are the recent ones that later passes read again. Results are pure functions of the variant and source bytes, so output cannot change.

Prototype on the real inputs: specialize misses drop from 729,899 to 66,813. The composed result JSON is byte-identical (sha256 c78816ce…f4290).

Acceptance

  • The composed output is identical on real inputs, and the parity fixtures are unchanged.
  • A contract test shows that a memo filled to its entry budget still memoizes the next source, and that it never holds more than the budget.

Not in scope: CssSyntaxScanner::matchingClose() walks a group one byte at a time through consume(), where matchingBrace() skips inert runs with inertEnd(). That cost is separate (~80 s of asset_writes here).

AI disclosure: Claude (Anthropic) via Pi/Roadie subagent profiled this and drafted the issue for Chris Huber.

主要语言
PHP
星标
31
派生
7
平均合并
7 小时 50 分钟
30 天内合并 PR
822

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Automattic/blocks-engine 的其他 Issue

查看 Automattic/blocks-engine 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。