Skip to content

perf(cli): discovery reads its listings; CLI tests warm up once - #9722

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:perf/cli-discovery-listings
Nov 3, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:perf/cli-discovery-listings

Conversation

@vjeux

@vjeux vjeux commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

The CLI's integration tests time out on a busy machine and pass alone: the authoring checks, integration check, doctor integration components and the validate gaps cases. On one loaded full run, cases that take about 1 s alone took 6–35 s, and eleven crossed the 30 s test limit.

The cause is work that lands inside a test's own time and grows with load:

  1. Each test file's cold start. The first check in a test file parses TypeScript's lib files, and the first in a worker also loads TypeScript. validateIntegration on a small package costs 2.6 s of CPU cold and 0.15 s warm. That start lands inside whichever heavy test runs first, so four workers starting together on a busy machine push those tests over the limit.
  2. Programs over the whole repository. A fixture inside the repository with no TypeScript config of its own gets the root config, so the props comparison compiles every file in the repository. test(cli): doctor-integration, validate-integration and check-failures fixtures check their own files #9496 gives those fixtures a scoped config.
  3. Repeated parses. Each program parsed the lib files again. perf(cli): doc types and props checks reuse parsed files (TS 5.3+) #9517 keeps parsed files for the process.
  4. Discovery by probe. Each integration authoring check rediscovered Core's components with a probe of the disk for every candidate path: about 98,000 file system calls per discovery, 72,600 of them access() probes and 64,000 of those misses. Work made of that many calls slows with the number of workers walking the same tree.

This PR fixes 1 and 4, splits one test and moves four spawned CLI runs in process (below). #9496 fixed 2 and #9517 fixed 3; both are merged, so with this PR all four are fixed.

Intended invariant

No behavior change. Discovery returns the same records, in the same order, from the same files. An operation that does not change the files it reads may answer from one listing of each folder; outside such an operation every helper reads the disk as before (the listing cache's contract). No test's budget, bound or assertion changes.

Change

  • One test split in two (tests only). "Integration diagnostics are read-only" ran all 8 full diagnostic calls in one test: validate and the three conflict checks, on a local and on an installed package (about 2.3 s of CPU after the warm-up). On a quarter of a physical core that cannot fit the 30 s limit. "Leaves the local package byte-for-byte unchanged" and "leaves the installed package byte-for-byte unchanged" are now two tests. Each builds its own fixture, makes its own 4 calls and keeps every assertion of its half. No timeout, retry or skip changes. The local test keeps test(cli): doctor-integration, validate-integration and check-failures fixtures check their own files #9496's scoped TypeScript config.
  • Four printing tests run the CLI in process (tests only). validate-integration-gaps' four tests that check the printed doctor integration validate report spawned a fresh CLI, and each spawn paid the whole cold start again (about 3–4 s of CPU). They now call runCli, the repository's in-process harness, which drives the real program; their assertions on the printed lines and the exit status are unchanged. module-loader.stdout.test.mjs and experimental-isolation.test.mjs still spawn the real binary for doctor integration validate.
  • Warm-ups (tests only). packages/cli/test-utils/warm-integration-checks.mjs runs one integrationCheck() on a tiny component package, laid out like the calling file's fixtures. The five test files await it at their top level, while vitest collects the file, which it does not time. It throws when the checks do not run in full, so a broken warm-up fails the file.
  • Discovery reads listings. discoverOwnedComponents and the three exported authoring checks (integrationTemplateConflicts, integrationComponentConflicts, integrationDocConflicts) run inside withListingCache, as build and search already do. Each is read-only, and a nested call shares the outer cache. integrationCheck runs the three checks in one cache, so it lists Core once.
    • Inside a listing cache, existsCaseExact answers from the folders' listings: a name that a listing lacks costs no call. A symbolic link still checks its target. The new findEntry reads one listing per folder for the operation. Outside a cache, existsCaseExact is unchanged.
    • findComponentSource matches its candidate names against the listing it already holds, and skips the existence check for a folder it found in its parent's listing.
    • existsCaseExact reads a plain path's segments straight off the string (an absolute root, then no empty, . or .. segment); any other path still goes through path.relative. A discovery makes about 72,000 such probes, and normalizing both paths on each was half its time.

Evidence

Profile: a 2-thread pin (one physical core), two busy loops beside it, 4 workers; the busy loops at normal priority and the tests at nice 10. The eleven tests that crossed the limit:

One run each, the eleven tests filtered Red
main 10/11
this PR's discovery change only 10/11
with #9496 and #9517 5/11: each the first test of its file, carrying the cold start
with #9496 and #9517, and this PR's warm-up: the read-only test alone, three runs 3/3 pass (3/3 fail without the warm-up, 39–43 s)

Whole files, the five test files in one run each time:

Runs Tests Slowest test
main 3 263/285, 260/285, 263/285 (22 to 25 timeouts each) 157 s
with #9496, #9517 and this PR 10 286/286 each 24.7 s

On main, 10 of the eleven tests above fail in at least one of the three runs, and 7 fail in all three.

  • Failure before the change: the main rows above.

  • Success after the change: the rows with test(cli): doctor-integration, validate-integration and check-failures fixtures check their own files #9496, perf(cli): doc types and props checks reuse parsed files (TS 5.3+) #9517 and this PR above.

  • Calls per discovery (strace, one discovery of Core from this repository):

    access() getdents64 openat statx
    Before 72,570 16,188 8,569 792
    After 564 596 773 797
  • Calls at once on the same tree (copies of one discovery loop started together, each pinned to its own core, so no copy waits for a processor; median warm call):

    Copies Before After
    1 325 ms 217 ms
    16 709 ms (p90 1,026 ms) 397 ms (p90 461 ms)
    32 1,203 ms (p90 1,371 ms) 397 ms (p90 419 ms)
  • CPU per discovery (warm, one process): 324 ms before, 130–139 ms after.

  • Same records: discovery's records from main and from this change are byte-identical (49,611 bytes of JSON), called alone or inside an outer cache.

  • A broken warm-up fails the file: with the warm-up package's manifest pointing at a missing folder, both kinds of file fail while collected, with "warmIntegrationChecks: the checks did not run in full".

  • Mutations: each fails a new test: a dropped symbolic-link check in existsCaseExact or in findComponentSource, a case-insensitive match in findEntry or in findComponentSource, and the string fast path taken for a path that is not plain.

  • Product/runtime behavior verified unchanged: the records above, and the CLI tests listed under Testing.

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

Scope

  • 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

Local gates at b9c689d (this head: the change rebased onto main ab90555 after #9496 merged; its diff from main is byte-identical to the earlier head's), merged with main e68774f (it also merges with main 14550c0, which adds #9517, without a conflict):

  • pnpm review:pre: no findings;
  • pnpm build, then pnpm test:node: 16,117 passed, 76 skipped, 0 failed (3,271 files).

Earlier, at cd113e7 merged with main 2c53350:

  • Prettier and strict ESLint on the changed files; the CLI's strict typecheck; changeset coverage;
  • listing-cache.test.mjs: findEntry and listingCacheActive, and existsCaseExact inside a cache equal to outside on ten cases (exact name, case variants, a link to a file, a link to a missing file, a path through a file, a missing path, and three paths that are not plain), plus a root written with a trailing separator;
  • component-discovery.test.mjs: the prefixed source before the bare one in a nested folder; a case variant and a link to a missing file passed over; a live link followed;
  • the five test files: 286/286, and ×10 on the profile above (with perf(cli): doc types and props checks reuse parsed files (TS 5.3+) #9517);
  • pnpm build, then pnpm test:node: 16,075 passed, 76 skipped, 0 failed (3,256 files).

A known load red on main, not from this change. One loaded test:node run at this head, merged with main ab90555, timed out once: scripts/i18n-english-fallback.test.mjs › "bundles only the English a component names, not the whole catalog" (31.2 s). Its cause is the component size measurement's writes to the system temp directory, which #9441 fixes; the maintainers re-land #9441 after the v0.7.7 release.

  • The test reads none of this PR's files: its import closure is the test, scripts/i18n-english-fallback.mjs and .github/scripts/lib/component-size.js, plus esbuild and TypeScript, and it bundles Core's built dist.
  • Main without this PR timed out on the same test in 4 of 10 runs under temp-directory load (ci: component size writes no temp file and measures the import's chunk #9441's comparison).

@vercel

vercel Bot commented Nov 3, 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 3, 2026 9:26am UTC

Request Review

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

astracat-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 9:32 AM UTC

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · b9c689d

Storybook · Sandbox · built from this PR's head

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

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


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.

Requesting changes for one wording fix in the changeset. The listing-cache change keeps discovery's results identical while cutting its file system calls sharply.

  • .changeset/cli-discovery-listing-reads.md says integrationTemplateConflicts() and the commands that run it now find Core's components with far fewer file system calls, but the template check never reads Core's components and its call count is essentially unchanged, so please list only integrationComponentConflicts(), integrationDocConflicts(), integrationCheck() and doctor integration components, doctor integration docs and integration check.

A small correction to the description: the doctor integration validate cases in outside-project.test.mjs run in process through runCli; the real binary is still spawned for that command in module-loader.stdout.test.mjs and experimental-isolation.test.mjs.

[Automated review]

'@astryxdesign/cli': patch
---

[perf] `integrationTemplateConflicts()`, `integrationComponentConflicts()`, `integrationDocConflicts()` and `integrationCheck()` from `@astryxdesign/cli/api`, and the commands that run them, find Core's components from the folder listings they already read, with far fewer file system calls. Their results are unchanged.

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.

integrationTemplateConflicts() (and doctor integration templates) never reads Core's components: it reads only templates, through discoverCoreTemplates and discoverIntegrationTemplatesForOne, and its file system calls are essentially unchanged by this PR. Suggested wording:

[perf] `integrationComponentConflicts()`, `integrationDocConflicts()` and `integrationCheck()` from `@astryxdesign/cli/api`, and `doctor integration components`, `doctor integration docs` and `integration check`, find Core's components from the folder listings they already read, with far fewer file system calls. Their results are unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e66d3b2 with your wording: the changeset names integrationComponentConflicts(), integrationDocConflicts() and integrationCheck(), and doctor integration components, doctor integration docs and integration check. The description now says the real binary still runs for doctor integration validate in module-loader.stdout.test.mjs and experimental-isolation.test.mjs.

The CLI's integration tests timed out on a busy machine. The cause was
work inside a test's own time that grows with load.

The first check in each test file parses TypeScript's lib files, and
the first in a worker also loads TypeScript: 2.6 s of CPU cold, 0.15 s
warm. That start landed inside the first heavy test. A helper now runs
one integrationCheck on a tiny package while each file is collected,
which vitest does not time. It throws when the checks do not run in
full.

Each integration authoring check also rediscovered Core's components
with a probe of the disk for every candidate path: about 98,000 file
system calls per discovery, 72,600 of them access() probes. The three
checks, and discoverOwnedComponents itself, now run in the read-only
listing cache, and integrationCheck runs the three in one cache.
Inside a cache, existsCaseExact answers from the folder listings, and
findComponentSource matches candidates against the listing it holds.
existsCaseExact reads a plain path's segments off the string instead of
normalizing both paths on every probe. One discovery makes about 2,700
calls and about 140 ms of CPU instead of 320 ms, with the same records.

The read-only test made 8 full diagnostic calls in one test. The local
and installed packages are now two tests, each with its own 4 calls and
its own asserts. Four printing tests spawned a fresh CLI, which paid the
whole cold start again; they now run it in process with runCli.

No behavior change.

@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 looks ready to merge once it leaves draft. The listing cache keeps discovery's records and every integration check's result identical while cutting their existence probes by about 35 times, and the changeset now names only the checks that read Core's components.

One optional follow-up, not blocking: inside a listing cache, existsCaseExact returns true for a file path written with a trailing separator, where the uncached branch returns false; no current caller passes such a path (see the inline note).

[Automated review]

? `${folder}${segment}`
: `${folder}${path.sep}${segment}`;
}
return !entry?.isSymbolicLink() || pathExists(targetPath);

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: for a regular file written with a trailing separator (…/Button/Button.tsx/), this branch returns true, while the uncached branch returns false because fs.existsSync rejects a file path ending in a separator. relativeInside falls back to path.relative, which drops the separator, so the walk finds the file's entry. No current caller passes such a path. Sending a target that is not a plain path through the disk branch, or adding the case to the equivalence test in listing-cache.test.mjs, would keep inside and outside equal.

@vjeux
vjeux marked this pull request as ready for review November 3, 2026 12:31
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 3, 2026
@cixzhang
cixzhang marked this pull request as draft November 3, 2026 12:35
@cixzhang
cixzhang marked this pull request as ready for review November 3, 2026 12:35
@cixzhang
cixzhang merged commit c40d382 into meta:main Nov 3, 2026
139 of 144 checks passed
@vjeux
vjeux deleted the perf/cli-discovery-listings branch November 3, 2026 13:33

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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.

2 participants