Skip to content

perf(cli): keep each shipped doc's parse, and build doc schemas on first parse - #12166

Merged
josephfarina merged 4 commits into
mainfrom
speed/doc-parses-kept
Nov 17, 2026
Merged

josephfarina merged 4 commits into
mainfrom
speed/doc-parses-kept

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

Every command that reads a doc paid twice for zod in each run. Each doc parser built all of its schemas when the CLI loaded it, and most runs never call most parsers. component then parsed the same shipped Core doc again on every run, although its result depends only on the doc's text. In a project with an integration, a warm component run spent about 20 ms on this.

Intended invariant

Every command prints exactly what it printed: the same output, error output, exit code and JSON. A doc parse that fails throws the same error in the same words on every run, because it is never kept. A kept parse is used only for a doc whose exports come from the shipped stored docs, so the doc's text and the CLI build decide it. It is kept only in a run that already keeps catalogs, so a project with no integration keeps nothing, as before.

Change

  • The doc parse modules (authoring/doctypes/_schema.mjs, the template, theme, icon-set and icon-definition parsers, and the config and codemod parsers) build their schemas the first time they parse, not when they load. Each module keeps one builder and reads its schemas through it. The schemas, their checks and their error messages are the same as before; they are only built later.
  • persistedValue in foundation/fs/gather-cache.mjs keeps a value that depends only on its key and the CLI build. It writes the value's text only when that text reads back as an equal value (the rule the stored parses already use), with a digest of the text, so an entry changed after it was written is a miss. The build id and the CLI folder are in its key, as in every kept entry.
  • keptParse in foundation/doc-compiler/stored-docs.mjs keeps the parse of a stored doc's export through persistedValue, keyed by the doc's text, the export name and the version of the zod copy the doc parsers load (read once per run, from where the parsers resolve it). The build id names the CLI's own code, not its dependencies, and a reinstall can put another zod beside the same build. When the zod version cannot be read, nothing is kept. parseReadableDoc uses the stored parse first, then the kept one, then parses as before.
  • The parses the stored docs ship with are made at publish time with one zod release and served under whichever zod an install resolves. They rest on the assumption that a valid doc parses the same under every zod release in the CLI's range; a separate follow-up checks it.
  • spec:AST-081 FR7 and architecture:cli-surface INV10: the lists of what the per-user catalogs folder keeps name each stored doc's checked contents, keyed by its text.

Evidence

Same machine, the packed CLI before and after this change, both projects in sibling folders of the same path length, each case run interleaved after a warm-up, 11 runs each (95% confidence interval on the difference):

cases before after difference
component, ten lookups, a project with an integration 377–402 ms 361–381 ms −12 to −22 ms, every interval below 0
template (5), theme build (5), upgrade (2), with an integration 301–623 ms 289–612 ms −5 to −18 ms; ten of twelve intervals below 0, the rest hold 0
search, twelve requests, with an integration 429–728 ms 417–721 ms −1 to −28 ms; nine of twelve intervals below 0, the rest hold 0
build (6), docs (6), doctor (2), hook (2), with an integration 288–994 ms 290–985 ms −16 to +10 ms, each interval holds 0
hook, theme build, doctor, template and upgrade, a Core-only project 178–296 ms 160–280 ms −5 to −20 ms, each interval below 0
search (12) and build (6), a Core-only project 314–701 ms 312–694 ms −4 to −18 ms; thirteen of eighteen intervals below 0, the rest hold 0
component (10) and docs (6), a Core-only project 246–332 ms 244–334 ms −6 to +0 ms, mostly holding 0: a Core-only project keeps no catalogs, so its reads still parse their docs

Weighted over the battery's commands: 381 → 367 ms (−3.6%) with an integration, 270 → 262 ms (−2.9%) in a Core-only project.

First runs, on a fresh cache folder (the code compile cache warm), 41 each, interleaved:

case before after difference
component, integration with a JavaScript manifest 1001 ms 1003 ms −2 ms [−10, +10]
component, integration with a TypeScript manifest 1381 ms 1392 ms +9 ms [+1, +36]
build, integration with a TypeScript manifest 2194 ms 2212 ms +17 ms [−3, +52]

With an older integration release that ships a TypeScript manifest, a first component run costs about 9 ms more (interval +1 to +36 ms); with a compiled (JavaScript) manifest, which current integration releases ship, first runs are unchanged. Most runs are warm, so across typical use this change is net faster.

  • Product/runtime behavior verified unchanged: every battery case's output, error output and exit code matched before and after, in both projects. Every exported value of the shipped and installed doc, config and codemod files, run through all seven parsers before and after (14,616 parses, 11,908 of them errors) on this branch's base, gave the same JSON text or the same error message.
  • Failure before the change: not applicable (no failure; a speed change).
  • CI impact: none (no workflow, action or CI script changes).

Writing rubric results

The two record edits each add one item to a list of per-user writes: spec:AST-081 FR7 and architecture:cli-surface INV10.

R1 narration: none; each edit adds one present-tense list item.
R2 research: none in the records; the measurements live in this description.
R3 evidence: no evidence or verification cell changes.
R4 rejected alternatives: none.
R5 change references: none added.
R6 open questions: none.
R7 project status: none.

Scope

Components: cli (doc parsers, kept catalogs)

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • foundation/fs/gather-cache.value.test.mjs (new): a value is kept in a run that keeps catalogs and read back with its key order; outside such a run nothing is kept; a computation that throws keeps nothing and throws again; a value that does not read back exactly (an undefined property, a date, NaN, −0) is never kept; a changed entry is a miss and is stored over; another CLI build is a miss. Removing the digest check fails the changed-entry case; removing the run check fails the outside-a-run case.
  • test/packed-gather-cache.doc-parses.test.mjs (new, packed CLI): a run that reads a kept parse prints the same output and error output as a fresh parse, in text and JSON, and keeps nothing new; with a zod copy that names another version, the run parses and keeps every doc again and prints the same (leaving zod out of the key fails this case); every module that imports zod loads one copy of it, in the run that keeps a parse and in the one that reads it back.
  • foundation/doc-compiler/parse-quiet.test.mjs (new): parsing every doc the CLI and Core ship prints nothing, so a kept parse cannot hide a warning. A doc parse returns a value or throws (parseReadableDoc → parseDoc → the kind's parser → safeParse, then formatZodError and throw); none of these modules writes to the console or an output stream. Adding a warning to the legacy parser fails this test.
  • test/packed-gather-cache.malformed.test.mjs: the kept kinds include the doc parses, and every damaged entry is a miss that is stored over.
  • test/packed-gather-cache.records.test.mjs still holds: a project with no integration keeps nothing.
  • The typechecks pass, the drift locks included.
  • The Node test project passes but for 14 tests in six api/theme-edit files, which fail the same way on main on the test machine.

@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 11:53pm 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
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review 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, 11:55 PM UTC

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

@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.

This pull request needs an engineering owner's spec decision and two small additions before it can be approved.

An engineering owner records the decision on the spec:AST-081 FR7 change, which lets the per-user catalogs folder keep each stored doc's parse keyed by its text, by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

  • docs/architecture/cli-surface.md INV10 (lines 285-289) still lists the per-user writes without the new doc-parse entry, so add the same item there that FR7 gains.
  • The description has no ## Writing rubric results for the record edits, which the knowledge-record rules require before review.

The code checked out: output stayed byte-identical across fresh, keeping and reading runs, a failing parse is never kept, and the drift locks still catch schema drift inside the new builders.

Claims and files checked

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

  • Changeset: commands that keep catalogs keep each shipped doc's parse by its text: verified, limited to plain-data shipped docs without a publish-time parse (stored-docs.mjs:187-195)
  • Changeset: parsers build their schemas on first parse: verified (eight modules, whitespace-insensitive diff)
  • Changeset and description: output, error output and exit codes unchanged: verified (packed round-trip test; byte-identical probe runs)
  • Description: schemas used to be built at load, and Core docs were parsed again on every run: verified (base modules; publish-time parses cover only the CLI's own docs)
  • Description: a failing parse is never kept: verified (gather-cache.mjs:1173; value-store test)
  • Description: only docs read from the shipped store are kept: verified (stored-docs.mjs:189-190)
  • Description: kept only in runs that keep catalogs, and a project with no integration keeps none: verified (gather-cache.mjs:1144; Core-only probe)
  • Description: digest check, read-back rule, build and folder in the key: verified (gather-cache.mjs:1143-1199, :626-637)
  • Description: stored, then kept, then fresh parse: verified (parse-readable.mjs:32)
  • Description: the global-mode spec's catalogs list gains the item: verified (spec.md:420-421)
  • Description: schemas, checks and messages unchanged: verified (whitespace-insensitive diff)
  • Description: timing tables and the 14,616-parse comparison: not reproduced (measurements)
  • Description: no CI change and no public API change: verified (no workflow files; exported modules keep their names)
  • Description: the listed tests, including the two removal claims for the value store: verified (read, and all pass here)
  • Description: typechecks pass with the drift locks: verified (authoring contract typecheck clean; a seeded drift still fails on head as on base)
  • Description: 14 theme-edit test failures also occur on main: not reproduced
  • .changeset/doc-parses-kept-per-user.md: clear (claims checked above)
  • docs/specs/AST-081-global-mode/spec.md: waits on the owner decision; its companion list in docs/architecture/cli-surface.md INV10 is not updated; rubric results missing
  • packages/cli/authoring/doctypes/_schema.mjs: clear (wrap only; drift locks still checked)
  • packages/cli/authoring/codemod/parse.mjs, packages/cli/authoring/config/parse.mjs: clear (wrap only)
  • packages/cli/authoring/doctypes/{template,theme,icon-set,icon-definition}/parse.mjs: clear (wrap only)
  • packages/cli/authoring/doctypes/{command,component,enum,hook,namespace,reference,schema}/parse.mjs, packages/cli/authoring/doctypes/legacy.mjs: clear (read schemas through docSchemas())
  • packages/cli/foundation/doc-compiler/parse-readable.mjs: clear
  • packages/cli/foundation/doc-compiler/stored-docs.mjs: non-blocking note (installed zod version not in the key)
  • packages/cli/foundation/fs/gather-cache.mjs: clear
  • packages/cli/foundation/fs/gather-cache.value.test.mjs, packages/cli/foundation/doc-compiler/parse-quiet.test.mjs, packages/cli/test/packed-gather-cache.doc-parses.test.mjs, packages/cli/test/packed-gather-cache.malformed.test.mjs: clear (pass)
  • packages/cli/authoring/doctypes/load-contract.test.mjs, packages/cli/test/authoring-types.test.mjs, packages/cli/test-utils/kept-entry.mjs: clear

Automated review (maintainer link)

Comment thread docs/specs/AST-081-global-mode/spec.md Resolved
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c4db41b

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 5.22 MB packed (−529 B); no new dependencies.

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


Generated by PR Enrichment workflow | View full report

@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.

This pull request needs an engineering owner's spec decision before it can be approved; the code itself checks out.

An engineering owner records the decision on the spec:AST-081 FR7 and architecture:cli-surface INV10 changes, which let the per-user catalogs folder keep each stored doc's parse keyed by its text, by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

  • Regression (non-blocking): the header of packages/cli/foundation/fs/gather-cache.mjs (lines 40-43) still says the doc's text and the build are all a kept parse depends on, so name the zod release the parsers load there too.

The INV10 list item, the writing rubric results and the zod version in the key are now in place, and output stayed identical across fresh, keeping and reading runs.

Claims and files checked

Review mode: full; reason: spec-record

  • Changeset: commands that keep catalogs keep each shipped doc's parse by its text: verified, limited to stored docs without a publish-time parse (stored-docs.mjs:220-231)
  • Changeset: parsers build their schemas on first parse: verified (seven builder modules; whitespace-insensitive diff)
  • Changeset and description: output, error output and exit codes unchanged: verified (packed round-trip tests; string and regex literals identical)
  • Description: schemas used to be built at load, and Core docs were parsed again on every run: verified (base modules; publish-time parses cover only the CLI's own docs)
  • Description: a failing parse is never kept: verified (gather-cache.mjs:1173; value-store test)
  • Description: only docs read from the shipped store are kept, and only in runs that keep catalogs, so a project with no integration keeps none: verified (stored-docs.mjs:222-223, gather-cache.mjs:1144; records test)
  • Description: read-back rule, digest check, build and folder in the key: verified (gather-cache.mjs:1143-1195, :626-637)
  • Description: the zod version the parsers load is in the key, read once per run, and nothing is kept when it cannot be read: verified (stored-docs.mjs:189-206, :224-227)
  • Description: stored, then kept, then fresh parse: verified (parse-readable.mjs:32)
  • Description: publish-time parses are served under any installed zod: verified (the stored parse is not keyed by zod)
  • Description: both record lists gain the item, and each edit passes the writing rubric: verified (spec.md:420-421, cli-surface.md:289; knowledge check clean)
  • Description: timing tables and the 14,616-parse comparison: not reproduced (measurements)
  • Description: no CI change and no public API change: verified (no workflow files; exported entry points keep their names)
  • Description: the listed tests and their removal claims (digest check, run check, zod key): verified (all pass; each removal fails its case)
  • Description: typechecks pass with the drift locks: verified (authoring contract typecheck clean; a seeded drift still fails)
  • Description: 14 theme-edit test failures also occur on main: not reproduced
  • .changeset/doc-parses-kept-per-user.md: clear
  • docs/specs/AST-081-global-mode/spec.md, docs/architecture/cli-surface.md: wait on the engineering-owner decision; the two lists now agree
  • packages/cli/foundation/fs/gather-cache.mjs: non-blocking note (header, lines 40-43)
  • packages/cli/foundation/doc-compiler/stored-docs.mjs, packages/cli/foundation/doc-compiler/parse-readable.mjs: clear
  • packages/cli/authoring/doctypes/_schema.mjs, packages/cli/authoring/codemod/parse.mjs, packages/cli/authoring/config/parse.mjs: clear (wrap only; drift locks still checked)
  • packages/cli/authoring/doctypes/{template,theme,icon-set,icon-definition}/parse.mjs: clear (wrap only)
  • packages/cli/authoring/doctypes/{command,component,enum,hook,namespace,reference,schema}/parse.mjs, packages/cli/authoring/doctypes/legacy.mjs: clear (read schemas through docSchemas())
  • packages/cli/foundation/fs/gather-cache.value.test.mjs, packages/cli/foundation/doc-compiler/parse-quiet.test.mjs, packages/cli/test/packed-gather-cache.doc-parses.test.mjs, packages/cli/test/packed-gather-cache.malformed.test.mjs: clear (pass)
  • packages/cli/authoring/doctypes/load-contract.test.mjs, packages/cli/test/authoring-types.test.mjs, packages/cli/test-utils/kept-entry.mjs: clear

Automated review (maintainer link)

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 78dbb91

@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 c4db41b

@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. The two per-user write list edits (spec:AST-081 FR7 and architecture:cli-surface INV10) carry an engineering owner's approval for this head, and the header comment now names the zod release, which resolves the last open note. Lint and the CLI smoke test pass, but the main CI run was cancelled because CI was full, so it needs a re-run on this head before merge.

Claims and files checked

Review mode: incremental; reason: none

  • Changed rules (0): none.
  • Claim: the doc parsers build their schemas on first parse, not at load. Verified in all seven builder modules.
  • Claim: a run that keeps catalogs keeps each shipped doc's parse by the doc's text. Verified, for shipped docs with no publish-time parse; the key also holds the zod release and the CLI build.
  • Claim: output, error output and exit codes are unchanged. Verified by the packed-CLI test across fresh, keeping and reading runs, in text and JSON.
  • Claim: a failing parse is never kept. Verified by the value test.
  • Claim: nothing is kept outside a run that keeps catalogs, or in a project with no integration. Verified by the value test and the records suite.
  • Claim: the store writes only text that reads back equal, checks a digest, and keys by build and CLI folder. Verified in the store code and its tests.
  • Claim: the zod release is read once per run from where the parsers resolve it, and nothing is kept when it cannot be read. Verified.
  • Claim: the stored parse comes first, then the kept one, then a fresh parse. Verified.
  • Claim: the publish-time parses rest on the same zod assumption. Accurate as stated.
  • Claim: the two per-user write lists gain the new item. Verified.
  • Claim: no public API change, no CI impact, no internal context. Verified.
  • Claim: the new tests fail without the digest check, the run check and the zod release in the key. Verified by removing each.
  • Claim: parsing every shipped doc prints nothing. Verified; the test watches the console and both output streams.
  • Claim: the typechecks pass, the drift locks included. Verified for the authoring-contract, JSON API and declaration builds.
  • Claim: the speed tables, the 14,616-parse comparison and the 14 failing theme-edit tests on main. These are the author's measurements and were not reproduced.
  • Files, each clear: .changeset/doc-parses-kept-per-user.md, docs/architecture/cli-surface.md, docs/specs/AST-081-global-mode/spec.md.
  • Files, each clear: packages/cli/authoring/doctypes/_schema.mjs, packages/cli/authoring/codemod/parse.mjs, packages/cli/authoring/config/parse.mjs, and the icon-definition, icon-set, template and theme parsers under packages/cli/authoring/doctypes/.
  • Files, each clear: the command, component, enum, hook, namespace, reference and schema parsers under packages/cli/authoring/doctypes/, and packages/cli/authoring/doctypes/legacy.mjs.
  • Files, each clear: packages/cli/foundation/doc-compiler/parse-readable.mjs, packages/cli/foundation/doc-compiler/stored-docs.mjs, packages/cli/foundation/fs/gather-cache.mjs.
  • Files, each clear: packages/cli/foundation/doc-compiler/parse-quiet.test.mjs, packages/cli/foundation/fs/gather-cache.value.test.mjs, packages/cli/test/packed-gather-cache.doc-parses.test.mjs, packages/cli/test/packed-gather-cache.malformed.test.mjs, packages/cli/authoring/doctypes/load-contract.test.mjs, packages/cli/test/authoring-types.test.mjs, packages/cli/test-utils/kept-entry.mjs.

Automated review (maintainer link)

@josephfarina
josephfarina merged commit d6f6295 into main Nov 17, 2026
136 of 142 checks passed
@github-actions
github-actions Bot deleted the speed/doc-parses-kept branch November 17, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — c4db41b9 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant