Skip to content

perf(cli): a template's component line resolves its names in one pass, not one full lookup per name - #12680

Closed
josephfarina wants to merge 3 commits into
mainfrom
perf/template-components-one-pass
Closed

josephfarina wants to merge 3 commits into
mainfrom
perf/template-components-one-pass

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

Since "name a template's components for one component read" (#12389), every astryx template answer names the components the template uses, and works them out by looking up every owner of each imported name in full: Core's docs, each integration's component folders and every integration doc, once per name. Nothing is shared between the names or kept. In a project with an integration, a dashboard template's 15 components and its chart-library imports cost about 0.5 s on every call, and a larger template about 0.9 s.

Intended invariant

  • Every command prints exactly what it printed: the same line, receipt and JSON for every template, in a project with no integration and in one with integrations.
  • A template names a component exactly when the package its import names documents it, in first-use order, each once, qualified as before. Only how the answer is found changes:
    • a name the component list holds under Core or a configured integration needs no lookup, since a lookup of the name finds that package as an owner (a package with component docs of the older kind, astryx.docs, is an owner only when neither Core nor an integration documents the name, so it is still looked up);
    • a package that cannot own a component (a chart library: not Core, not a configured integration, not an installed package with component docs) documents none, so no lookup is needed;
    • every other name is looked up in full, as before (Core's SideNav that an integration replaces, a part only a family doc documents).
  • The full lookups of one template share one listing of each folder and one read of each integration doc.

Change

  • api/template/_adapter.mjs: loadComponentLookup also returns documents(package, name), answered as above.
  • foundation/discovery/template-adapter.mjs: answeredComponentsInSource asks documents when given (else ownersOf, as the tests' lookups do), and runs its lookups in one listing-cache operation.
  • foundation/discovery/component-discovery.mjs: inside an operation, the docs an integration's components folder records are read once (not once per name), and a same-stem probe skips a folder whose listing has no entry of that name in any case (only for ASCII names in folders whose entry names are all ASCII). Outside an operation nothing changes.
  • api/template/template.components-lookup.test.mjs: the lookup names what a lookup of every owner names, in first-use order; a component of a package with docs of the older kind, under a name Core documents too, is not named, as before; names the list holds and chart-library imports read none of an integration's docs; full lookups do not read more as the names grow. On the base, the last two fail.
  • api/template/copy/copy.components.test.mjs passes unchanged.

Evidence

  • Timing: the packed CLI before and after this change, both projects in sibling folders of the same path length, warm runs interleaved after a warm-up, 11 each; median difference after − before, 95% confidence interval:
template ask project before after difference
template dashboard --type page with an integration 846 ms 409 ms −433 ms (−52%)
a second page template with an integration 843 ms 397 ms −450 ms [−452, −443] (−53%)
template table-filter --json with an integration 1,212 ms 446 ms −764 ms [−793, −751] (−63%)
a block template with an integration 723 ms 389 ms −325 ms [−345, −320] (−46%)
a template with no components to name with an integration 317 ms 313 ms −3 ms [−13, +12]
template dashboard --type page Core only 417 ms 372 ms −42 ms [−57, −39] (−11%)
a second page template Core only 414 ms 365 ms −46 ms [−59, −42] (−12%)
template table-filter --json Core only 456 ms 434 ms −23 ms [−37, −12] (−5%)
a block template Core only 373 ms 365 ms −6 ms [−19, +6]
  • What the line still costs, measured against the CLI before it existed: parsing the template source (about 60 ms), and in a project with no integration, gathering the component list (about 28 ms; such a project keeps nothing between runs) and finding the installed packages with component docs for a chart library's imports (about 14 ms). Those are the line's own work; this change removes the per-name lookups.

  • Product/runtime behavior verified unchanged: every template the CLI lists, as template <name>, template <name> --json, and a copy with and without --json (the printed receipt and the written file), matched byte for byte before and after: 785 templates (3,140 cases) in a Core-only project and 856 templates (3,424 cases) in a project with an integration.

  • CI impact: none (no workflow, action or CI script changes).

Scope

Components: cli (template, component lookups)

  • 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

  • The template, component and search APIs, foundation/discovery, the listing cache, build, the template and component commands, the golden outputs and the installed packed kept-catalog file pass (200 files, 2,351 tests), as do the strict type check and the command-structure check.

@vercel

vercel Bot commented Nov 18, 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 18, 2026 9:28pm UTC

Request Review

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

astracat-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 18, 2026, 9:34 PM UTC

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 6aa0d28

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · dafca32

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded cancelled. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 10c14c4

@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: one release-note sentence needs correcting; the code change itself keeps every template answer the same.

  • The changeset says "a name the component list holds needs no lookup", but in a project with an integration a name the list holds under a package with component docs of the older kind (astryx.docs) is still looked up in full (packages/cli/api/template/_adapter.mjs lines 139–151, and the new test for that case), so please reword it to "a name the component list holds under Core or a configured integration needs no lookup", as the description says.

The components named match the base for every template source in a Core-only project and in a project with an integration, and the two new read-count tests fail on the base and pass here. CI has not run on this head yet.

Claims and files checked

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

  • Claims
    • Every command prints what it printed for every template, with and without an integration: verified (base and head name identical components for 790 template sources; the copy component tests pass).
    • A component is named exactly when the importing package documents it, in first-use order, each once, qualified as before: verified (answeredName in template-adapter.mjs; first new test).
    • A name the list holds under Core or a configured integration needs no lookup: verified (_adapter.mjs lines 135–138; read-count test).
    • A package with component docs of the older kind is still looked up: verified (_adapter.mjs lines 139–151; the new test for that case).
    • A package that cannot own a component needs no lookup: verified (ownersOf only returns Core, a configured integration or an installed package with component docs).
    • Other names, such as a Core component an integration replaces or a part a family doc documents, are looked up in full: verified (the list files a replacement under its integration).
    • The full lookups of one template share each folder listing and doc read: verified (one listing-cache operation and per-operation recorded docs; second read-count test).
    • Outside an operation discovery behaves as before: verified (both new helpers compute fresh or return nothing outside an operation).
    • On the base, the last two new tests fail: verified (2 failed, 2 passed with the new test file on the base).
    • The copy component tests pass unchanged: verified (20 passed; file unchanged).
    • Timing table and remaining-cost figures: not re-measured; the review's own run is faster in the same direction.
    • Byte-for-byte comparison of 3,140 and 3,424 cases: not re-run; corroborated by the 790-source comparison above.
    • No CI impact: verified (no workflow, action or CI script changes).
    • No public API or behavior change: verified (the changed functions are not exported from the package).
    • Changeset, "a name the component list holds needs no lookup": false (finding above).
    • Changeset, chart-library imports need no lookup, looked-up names share listings and doc reads, every answer unchanged: verified.
    • Changeset, about 0.3–0.7 s faster with an integration: not re-measured; in line with the description's table.
  • Files
    • .changeset/template-components-one-pass.md: finding above
    • packages/cli/api/template/_adapter.mjs: clear
    • packages/cli/api/template/copy/copy.mjs: clear
    • packages/cli/api/template/show/show.mjs: clear
    • packages/cli/api/template/template.components-lookup.test.mjs: clear
    • packages/cli/foundation/discovery/component-discovery.mjs: clear
    • packages/cli/foundation/discovery/template-adapter.mjs: clear

Automated review (maintainer link)

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec dafca32

@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: CI has not run on this head yet.

The changeset now says that a name the component list holds under Core or a configured integration needs no lookup, which matches the code, so the earlier request is resolved. The component line still names the same components: the new documents check agrees with a full owner lookup for every name probed in a project with an integration, and the two read-count tests fail on the base and pass here.

Claims and files checked

Review mode: incremental; reason: none

  • Changed rules since the last review (0): none
  • Claims
    • Every command prints what it printed for every template, with and without an integration: verified (documents matches a full owner lookup for every probed name; 790 template sources are named identically on base and head; the copy component tests pass).
    • A component is named exactly when the importing package documents it, in first-use order, each once, qualified as before: verified (answeredName in template-adapter.mjs; first new test).
    • A name the list holds under Core or a configured integration needs no lookup: verified (_adapter.mjs lines 135–138; read-count test).
    • A package with component docs of the older kind is still looked up: verified (_adapter.mjs lines 139–151; second new test).
    • A package that cannot own a component needs no lookup: verified (_adapter.mjs lines 139–149; a full lookup only ever names Core, a configured integration or an installed package with component docs).
    • Every other name is looked up in full, as before: verified (_adapter.mjs line 151).
    • The full lookups of one template share each folder listing and one walk of the integration docs: verified (one listing-cache operation in template-adapter.mjs; per-operation recorded docs; a name found by its own doc reads that doc's metadata once more, as the new test states).
    • Outside an operation discovery behaves as before, and the probe skip applies only to ASCII names in all-ASCII folders: verified (component-discovery.mjs lines 1838–1845 and 1864).
    • On the base, the last two new tests fail: verified (2 failed, 2 passed with the new test file on the base).
    • The copy component tests pass unchanged: verified (20 passed; file unchanged).
    • Timing table and remaining-cost figures: not reproduced as stated; the repository's own CLI is faster on two templates in a smaller project with an integration.
    • Byte-for-byte comparison of every template command: not re-run; corroborated by the comparisons above.
    • No CI impact: verified (no workflow, action or CI script changes).
    • No public API, product behavior or policy change, and no internal context in public text: verified (the changed functions are not exported; output unchanged; no internal references in the added lines, commits or description).
    • The listed test suites, type check and command-structure check pass: partly verified (the template, component, discovery and listing-cache suites and the command-structure check pass; the full suite and type check were not re-run).
    • Changeset, [perf] patch for the CLI: verified (the changeset check passes).
    • Changeset, names held under Core or a configured integration and chart-library imports need no lookup, looked-up names share listings and doc reads, every answer unchanged: verified.
    • Changeset, about 0.3–0.7 s faster with an integration: not re-measured; within the description's table.
  • Files
    • .changeset/template-components-one-pass.md: clear (earlier finding fixed)
    • packages/cli/api/template/_adapter.mjs: clear
    • packages/cli/api/template/copy/copy.mjs: clear
    • packages/cli/api/template/show/show.mjs: clear
    • packages/cli/api/template/template.components-lookup.test.mjs: clear
    • packages/cli/foundation/discovery/component-discovery.mjs: clear
    • packages/cli/foundation/discovery/template-adapter.mjs: clear

Automated review (maintainer link)

@josephfarina
josephfarina marked this pull request as ready for review November 18, 2026 22:48
josephfarina added a commit that referenced this pull request Nov 19, 2026
…s in one pass, not one full lookup per name
josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12680 perf(cli): a template's component line resolves its names in one pass, not one full lookup per name
  Author: Joey <[email protected]>
- #12180 fix(core): Calendar weekday names widen their column instead of overlapping
  Author: Joey <[email protected]>
- #12159 feat(cli): make an icon set inside your own app
  Author: Joey Farina <[email protected]>
- #12383 fix(Grid): a responsive column shrinks to a container narrower than minWidth
  Author: Joey Farina <[email protected]>
- #12374 [fix] Icon: a glyph given as name renders and warns, instead of crashing
  Author: Joey Farina <[email protected]>
- #12453 fix(charts): line, area and band default to straight segments
  Author: josephfarina <[email protected]>
- #12296 fix(core): a neutral Badge in a primary or destructive Button meets 4.5:1 on its fill
  Author: Joey Farina <[email protected]>
- #12395 fix(CodeBlock): without a code string, CodeBlock names the prop and the fix in development
  Author: Joey Farina <[email protected]>
- #12260 fix(cli): `astryx component Flex` names Stack first
  Author: Joey Farina <[email protected]>
- #12391 fix(core): a two-lane Toolbar wraps instead of squeezing its start lane
  Author: Joey Farina <[email protected]>
- #12427 fix(core): checkbox and radio marks keep their share of the box a theme sizes
  Author: josephfarina <[email protected]>
- #12725 [experimental] cli: with no icon set, experimental icon names the discover search where it lists packs
  Author: Joey Farina <[email protected]>
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12738.

@github-actions
github-actions Bot deleted the perf/template-components-one-pass branch November 19, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — dafca32d Deployed Nov 18, 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