ClassPublisher fold proof re-parses every selector per fold group (dominates compose; deadline failures after all pages compile)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- php
- Domain
- performance
Research direction
Start in ClassPublisher::publish(), then trace folds(), foldPreservesCascade(), and selector parsing through cascadeSelectors() and CssSelectorMatcher::parse(). Compare the published output and profiling results against the captured 5-page and 50-page plans; done means the output stays byte-identical while repeated selector parsing is reduced. The issue reports that 52 relevant unit test files pass, but names no specific test command.
Written by the indexing model from the issue text.
Description
Summary
ClassPublisher::publish() dominates compose time on real imports. It is the main reason production imports finish compiling every page and then run past the 3,600 s capture deadline with no further progress (capture_deadline_exceeded). That was 64 failures last week, most with pages_built == pages_to_build.
Local profile of a 50-page Shopify import (SSI 1.39.38, compose split with extra StepTimer marks):
| compose step | time |
|---|---|
ClassPublisher::publish |
277 s of 384 s total compose |
| everything else | 107 s |
Cause
folds() calls foldPreservesCascade($sheets, $map) once per candidate fold group. Each call:
- re-splits every stylesheet (
cssPieces+CssValueSplitter::splitTopLevel); - runs
renamedPrelude()on every selector; and - parses every selector twice with
CssSelectorMatcher::parse()(before and after). This includes selectors that name none of the folded classes, whose text and weight cannot change.
Measured on the pre-publish plans, which have 39k–43k selectors: 2–40 fold groups mean up to about 3.4M selector parses. Some of those are long :where()/:is() lists, where parseCompound/matchingClose dominate.
Fix (prototyped, output byte-identical)
- Read the selectors once per publish (
cascadeSelectors()): each selector's text and the class tokens it names. - In
foldPreservesCascade(), skip selectors whose classes don't intersect the map. Only rename and re-weigh the ones that do. - Weigh specificity lazily, memoized per selector. The full weight list is only needed when a fold changes specificity, which is the existing conservative pairwise proof and stays unchanged.
Offline ClassPublisher::publish() on the two captured pre-publish plans, current trunk versus the patch:
| plan | trunk | patch | output |
|---|---|---|---|
| 5-page site | 75 s | 4.2 s | sha256(serialize($published)) identical |
| 50-page site | 67 s | 19 s | identical |
All 52 tests/unit files touching ClassPublisher, class namespaces or folds pass.
- Dominant language
- PHP
- Stars
- 31
- Forks
- 7
- Avg merge
- 5h 48m
- Merged PRs (30d)
- 796
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Automattic/blocks-engine
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/blocks-engine#4943 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Automattic/blocks-engine#4942 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Automattic/blocks-engine#4921 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Automattic/blocks-engine#775 ·
Maintainers usually reply within 1 day
-
perf: a full CSS syntax memo stops memoizing, so per-route stylesheet passes re-split the same selectors (asset_writes, 56-page import)Possibly taken @chubes4 claimed this today. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Automattic/blocks-engine#7655 ·
Maintainers usually reply within 1 day
All issues in Automattic/blocks-engine
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Codeinwp/optimole-wp#1259 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Sylius/SyliusResourceBundle#1179 ·
-
repo:ckeditor
Difficulty 1/5 Under an hour Newbie friendliness 78/100
craftcms/ckeditor#682 · 1 comment ·
Maintainers usually reply within 1 day