Skip to content

perf(cli): theme build keeps what its css-tree checks of a theme's keys find - #11961

Merged
josephfarina merged 7 commits into
mainfrom
speed/css-tree-answers-kept
Nov 16, 2026
Merged

josephfarina merged 7 commits into
mainfrom
speed/css-tree-answers-kept

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A theme build checks each pseudo-class key in a theme's part styles (':hover', '::before', ':is(.a, .b)') and each token name that does not start with two dashes (color-scheme) with css-tree. Loading css-tree takes about 30 ms, on every build, even when no key changed since the last build.

  • foundation/runtime/css-tree.mjs: keptCssTreeAnswer(kind, inputs, answer) keeps an answer worked out with css-tree as a summary beside the kept gathers (persistedSummary) and reads it back while all of these are unchanged:
    • the inputs;
    • where css-tree resolved;
    • the CLI's build id;
    • every file of css-tree's code that is loaded and each MDN data file it read, each by its full stamp. An answer is kept only when every one of those files last changed at least 2 s (the coarsest time step a file system keeps) before the process started, so the code that worked it out is the code they hold, however and whenever the process loaded css-tree; a process that loaded css-tree before a reinstall keeps nothing.
  • api/theme/build/style-keys.mjs: what pseudoKeyProblem and pseudoKeyNotes give each pseudo-class key of the theme. They read the key text, css-tree and its selector data, nothing else: no Core component docs, no build options, no environment.
  • api/theme/build/written-values.mjs: which of the theme's token names without two dashes are CSS properties' (key in cssTree().lexer.properties). That reads the name and css-tree's property data, nothing else. The check first finds the names it asks about, with a pass that takes none for a property: when it asks about none, that pass is the answer; otherwise a second pass uses css-tree's kept answer. So it asks about exactly the names the check judges: Core's own surface tokens (color-scheme on onDark and onLight) are not judged and not asked about.
  • A build whose keys and names are unchanged loads no css-tree. A theme that sets no pseudo-class key and no such token name of its own keeps nothing and loads no css-tree. A check that throws keeps nothing.
  • foundation/fs/loaded-files.mjs (new): loadedFiles(roots), the files of the CommonJS code a module loaded, and loadedFileStamps(files), their stamps and whether each last changed before the process started.
  • spec:AST-081 FR7, architecture:cli-surface INV10 and doctor's cache row name the new entry.

Evidence

Builds of two themes with pseudo-class keys or such token names in a project with one integration, a fresh process per call, warm, interleaved, n=15, median paired difference (95% CI):

Theme main → change Difference
First theme 634 → 604 ms −32 [−39, −23], −4.6%
Second theme 696 → 669 ms −25 [−32, −22], −3.8%
Second theme, --check 690 → 670 ms −23 [−25, −19], −3.0%
  • Identity: every run printed the same stdout and stderr, with the same exit code, as main, and the written output folders are byte-identical.
  • A 51-case battery over every command in both projects: all cases but these builds are within noise (weighted −0.8% and −0.1%). The only output difference is doctor's cache row, which names the new entry.

Tests

  • api/theme/build/css-checks.kept.test.mjs (new):
    • for pseudo-class keys (problems, a note and clean keys, on the page and on a surface): read back with no css-tree, equal to a fresh check;
    • a theme with no pseudo-class key keeps nothing and loads no css-tree;
    • a key added, edited or removed checks again and is read back on the next check; a changed stamp of one of css-tree's files checks again;
    • after a reinstall changes css-tree's files while a process runs, the process keeps nothing, also when css-tree was loaded another way before the first check (both fail when an answer is kept whatever the files' times);
    • a check that throws keeps nothing;
    • the stamps include css-tree's files and the selector data;
    • for token names: read back with no css-tree, equal to a fresh check, checked again for other names; tokens that are all custom properties keep nothing and load no css-tree; a surface that holds only Core's own tokens keeps nothing and loads no css-tree.
  • test/packed-gather-cache.records.test.mjs: doctor's cache row names the entry.
  • foundation/doc-compiler/doc-loads.test.mjs: the new require.cache reads are listed.
  • api/theme/build, foundation/runtime, the records, doc-loads and lazy-dependency tests pass.

Spec changes

spec:AST-081 FR7, architecture:cli-surface INV10 and doctor's cache row add "what theme build finds when it checks a theme's pseudo-class keys and token names" to the per-user cache's entries. This needs an engineering owner's /approve-spec.

Writing rubric results

For the FR7 and INV10 additions:

  • R1 narration: none; the phrase states what the per-user cache holds.
  • R2 research: none in the records; the measurements stay in this description.
  • R3 evidence: none cited.
  • R4 rejected alternatives: none.
  • R5 change references: none.
  • R6 open questions: none.
  • R7 project status: none.

Scope

No theme build output, flag or JSON shape changes; doctor's cache row names the new entry.

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 16, 2026 2:25am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@astracat-bot

astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 16, 2026, 2:34 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · d03ffe5

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 4.97 MB packed (+2.4 kB); no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.

Current run: CI concluded cancelled; parts of this report may be missing.


Generated by PR Enrichment workflow | View full report

…'s code and data last changed before the process started

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kept css-tree answers look correct: they are keyed on the sorted keys or names and the build id, checked again against css-tree's file stamps, and equal to fresh checks in the new tests.

Approval waits on a spec decision: the new per-user cache entry is not in spec:AST-081 FR7 or architecture:cli-surface INV10 on main, and this pull request amends both records. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

Required fix:

  • The description's Scope line says "No output, flag or JSON shape changes", but doctor's kept-cache row now names the new entry (packages/cli/api/doctor/doctor.mjs:2341), so reword it, for example "No theme build output, flag or JSON shape changes; doctor's cache row names the new entry."

Optional: the loaded-files.mjs and css-tree.mjs headers lag the code, and the cache key could name where css-tree resolved (details inline).

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claims:
    • Changeset: a repeat build of a theme with pseudo-class keys or plain token names finishes about 25 to 35 ms sooner: verified by mechanism (css-tree's load is skipped; the read-back checks about 135 file stamps); end-to-end timing not repeated.
    • Changeset: the answers are kept beside the kept gathers and read back while the keys and css-tree's files are unchanged, so such a build loads no css-tree: verified (foundation/runtime/css-tree.mjs:67-112; the new tests; theme build reaches css-tree only through the two checks).
    • Changeset: warnings, errors and written files do not change: verified (kept answers equal fresh checks; the theme build test suite passes).
    • Description: loading css-tree costs every build of such a theme: verified (the base loads it in both checks).
    • Description: stamps are taken as the process first finds each file loaded, so a process that loaded css-tree before a reinstall keeps nothing: verified (css-tree.mjs:79-84 and its test).
    • Description: the pseudo-key checks read only the key, css-tree and its selector data: verified (api/theme/build/style-keys.mjs:50-357).
    • Description: the token-name check reads only the name and css-tree's property data: verified (api/theme/build/written-values.mjs:205-213).
    • Description: a theme with nothing to ask keeps nothing and loads no css-tree, and a check that throws keeps nothing: verified (tests).
    • Description: the new helper lists the files of loaded CommonJS code: verified (foundation/fs/loaded-files.mjs).
    • Description: FR7, INV10 and doctor's cache row name the new entry: verified.
    • Description: timing table and command battery: author measurements, not repeated.
    • Description: the listed tests exist and pass: verified.
    • Description: no output, flag or JSON shape changes: false (doctor's row text changes).
  • Files:
    • .changeset/theme-build-css-checks-kept.md: clear
    • docs/architecture/cli-surface.md: waits on the spec decision
    • docs/specs/AST-081-global-mode/spec.md: waits on the spec decision
    • packages/cli/api/doctor/doctor.mjs: clear
    • packages/cli/api/theme/build/css-checks.kept.test.mjs: clear
    • packages/cli/api/theme/build/style-keys.mjs: clear
    • packages/cli/api/theme/build/written-values.mjs: clear
    • packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear
    • packages/cli/foundation/fs/gather-cache.mjs: clear
    • packages/cli/foundation/fs/loaded-files.mjs: optional header note
    • packages/cli/foundation/runtime/css-tree.mjs: optional header and key notes
    • packages/cli/test/packed-gather-cache.records.test.mjs: clear

Automated review (maintainer link)

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 078e394

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 16, 2026
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec c1dcd1f

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec b481167

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested: the kept css-tree answers look correct, and the spec:AST-081 FR7 and architecture:cli-surface INV10 amendment is approved at this head, but two claims in the description are false and need correcting.

  • The Scope line says "No output, flag or JSON shape changes", but doctor's kept-cache row now names the new entry (packages/cli/api/doctor/doctor.mjs:2341), so reword it, for example "No theme build output, flag or JSON shape changes; doctor's cache row names the new entry."
  • The description says "The theme build's kept JavaScript uses the same file" about foundation/fs/loaded-files.mjs, but only foundation/runtime/css-tree.mjs imports it at this head, so drop that sentence or name css-tree's kept answers as its only user.

Optional: the start-time check in loaded-files.mjs could allow for coarse file times (inline), and the earlier header, cache-key and release-note notes still apply.

Claims and files checked

Review mode: incremental; reason: none

  • Claims:
    • Release note: a repeat build of such a theme finishes about 25 to 35 ms sooner: close to the author's 23 to 32 ms medians; "about 20 to 30 ms" fits better (optional).
    • Release note: the answers are kept and read back while the keys and css-tree's files are unchanged, so such a build loads no css-tree: verified (foundation/runtime/css-tree.mjs:66-100; the new tests).
    • Release note: warnings, errors and written files do not change: verified (kept answers equal fresh checks; the theme build tests pass).
    • Description: css-tree loads on every build of such a theme today: verified (the base checks call it on every run).
    • Description: a kept answer is read back while its inputs, the build id and every loaded css-tree code and data file keep their stamps: verified (css-tree.mjs:66-100, foundation/fs/gather-cache.mjs:1175-1222).
    • Description: an answer is kept only when every such file last changed before the process started, so a process that loaded css-tree before a reinstall keeps nothing: verified (foundation/fs/loaded-files.mjs:49-58 and its tests), with the optional coarse-time note.
    • Description: the pseudo-key checks read only the key, css-tree and its selector data: verified (api/theme/build/style-keys.mjs:57-400).
    • Description: the token-name check reads only the name and css-tree's property data, asks about exactly the names it judges, and skips Core's own surface tokens: verified (api/theme/build/written-values.mjs:271-287, :385-410).
    • Description: unchanged keys load no css-tree; a theme with nothing to ask, or a check that throws, keeps nothing: verified (tests).
    • Description: the new helper lists a module's loaded CommonJS files and their stamps: verified (loaded-files.mjs).
    • Description: the theme build's kept JavaScript uses the same file: false (only css-tree.mjs imports it).
    • Description: FR7, INV10 and doctor's cache row name the new entry, pending an engineering owner's approval: verified; the approval is recorded at this head.
    • Description: timing table, output identity and command battery: author measurements, not repeated.
    • Description: the listed tests exist and pass: verified.
    • Description: writing rubric results: verified; the added phrase only states what the per-user cache holds.
    • Description: no output, flag or JSON shape changes: false (doctor's row text changes).
  • Files:
    • .changeset/theme-build-css-checks-kept.md: optional wording note
    • docs/architecture/cli-surface.md: clear (approved amendment)
    • docs/specs/AST-081-global-mode/spec.md: clear (approved amendment)
    • packages/cli/api/doctor/doctor.mjs: clear
    • packages/cli/api/theme/build/css-checks.kept.test.mjs: clear
    • packages/cli/api/theme/build/style-keys.mjs: clear
    • packages/cli/api/theme/build/written-values.mjs: clear
    • packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear
    • packages/cli/foundation/fs/gather-cache.mjs: clear
    • packages/cli/foundation/fs/loaded-files.mjs: optional coarse-time and header notes
    • packages/cli/foundation/runtime/css-tree.mjs: optional header and cache-key notes
    • packages/cli/test/packed-gather-cache.records.test.mjs: clear

Automated review (maintainer link)

…holds where css-tree resolved; header + release note
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 41978cd

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: some required checks have not finished on this head yet.

The kept css-tree answers are keyed on the inputs, css-tree's location and the build id, are served only while every loaded css-tree file keeps its stamp, and are stored only when those files changed more than 2 s before the process started; the spec:AST-081 FR7 and architecture:cli-surface INV10 amendment is approved at this head, and both description claims flagged earlier now match the code.

Optional: the test comment at css-checks.kept.test.mjs:54-55 still describes the reinstall stamps as after the process start, though line 61 now sets them 1 s before it (inline).

Claims and files checked

Review mode: incremental; reason: none

  • Claims:
    • Release note: a repeat build of such a theme finishes about 20 to 30 ms sooner: consistent with the author's 23 to 32 ms medians (author measurement, not repeated).
    • Release note: the answers are kept and read back while the keys and css-tree's files are unchanged, so such a build loads no css-tree: verified (css-tree.mjs:67-102; css-checks.kept.test.mjs:185-196).
    • Release note: warnings, errors and written files do not change: verified (kept answers equal fresh checks; the seven published themes build identical theme.css from base and head).
    • Description: css-tree loads on every build of such a theme today: verified on the base code path; the 30 ms figure is the author's.
    • Description: a kept answer is read back while its inputs, css-tree's location, the build id and every loaded css-tree code and MDN data file keep their full stamps: verified (css-tree.mjs:69-75, :93-102; gather-cache.mjs:1175-1208).
    • Description: an answer is kept only when those files last changed at least 2 s before the process started, so a process that loaded css-tree before a reinstall keeps nothing: verified (loaded-files.mjs:53-59; css-checks.kept.test.mjs:248-267).
    • Description: the pseudo-key checks read only the key, css-tree and its selector data: verified (style-keys.mjs:57-394).
    • Description: the token-name check reads only the name and css-tree's property data, asks about exactly the names it judges, and skips Core's own surface tokens: verified (written-values.mjs:271-289, :388-393; css-checks.kept.test.mjs:361-370).
    • Description: unchanged keys load no css-tree; a theme with nothing to ask, or a check that throws, keeps nothing: verified (css-checks.kept.test.mjs:185-273, :354-370).
    • Description: the new helper lists a module's loaded CommonJS files and their stamps: verified (loaded-files.mjs:26-62).
    • Description: FR7, INV10 and doctor's cache row name the new entry, pending an engineering owner's approval: verified; the approval is recorded at this head.
    • Description: timing table, output identity and command battery: author measurements, not repeated; output identity is consistent with the identical theme builds.
    • Description: the listed tests exist and pass: verified (the new test file's 10 tests, the records, doc-loads, lazy-dependency and theme build tests).
    • Description: writing rubric results: verified; the added phrase only states what the per-user cache holds.
    • Description: no theme build output, flag or JSON shape changes, and doctor's cache row names the new entry: verified (doctor.mjs:2341).
  • Files:
    • .changeset/theme-build-css-checks-kept.md: clear
    • docs/architecture/cli-surface.md: clear (approved amendment)
    • docs/specs/AST-081-global-mode/spec.md: clear (approved amendment)
    • packages/cli/api/doctor/doctor.mjs: clear
    • packages/cli/api/theme/build/css-checks.kept.test.mjs: optional stale-comment note (inline)
    • packages/cli/api/theme/build/style-keys.mjs: clear
    • packages/cli/api/theme/build/written-values.mjs: clear
    • packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear
    • packages/cli/foundation/fs/gather-cache.mjs: clear
    • packages/cli/foundation/fs/loaded-files.mjs: clear
    • packages/cli/foundation/runtime/css-tree.mjs: clear
    • packages/cli/test/packed-gather-cache.records.test.mjs: clear

Automated review (maintainer link)

Comment on lines +54 to +55
// A reinstall rewrites css-tree's files: their times are after this
// process started.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this comment says the reinstalled files' times are after this process started, but line 61 now sets them 1 s before the start, the coarse-time case the 2 s margin in loadedFileStamps covers. Suggested: // A reinstall rewrites css-tree's files; a coarse file system can record their times up to 2 s before this process started.

@josephfarina
josephfarina merged commit 06db887 into main Nov 16, 2026
85 checks passed
@github-actions
github-actions Bot deleted the speed/css-tree-answers-kept branch November 16, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 41978cd3 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant