Repository navigation
perf(cli): discovery reads its listings; CLI tests warm up once - #9722
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
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.mdsaysintegrationTemplateConflicts()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 onlyintegrationComponentConflicts(),integrationDocConflicts(),integrationCheck()anddoctor integration components,doctor integration docsandintegration 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cd113e7 to
e66d3b2
Compare
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.
e66d3b2 to
b9c689d
Compare
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Maintainer impact
The CLI's integration tests time out on a busy machine and pass alone: the authoring checks,
integration check,doctor integration componentsand 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:
validateIntegrationon 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.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
doctor integration validatereport spawned a fresh CLI, and each spawn paid the whole cold start again (about 3–4 s of CPU). They now callrunCli, 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.mjsandexperimental-isolation.test.mjsstill spawn the real binary fordoctor integration validate.packages/cli/test-utils/warm-integration-checks.mjsruns oneintegrationCheck()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.discoverOwnedComponentsand the three exported authoring checks (integrationTemplateConflicts,integrationComponentConflicts,integrationDocConflicts) run insidewithListingCache, asbuildandsearchalready do. Each is read-only, and a nested call shares the outer cache.integrationCheckruns the three checks in one cache, so it lists Core once.existsCaseExactanswers from the folders' listings: a name that a listing lacks costs no call. A symbolic link still checks its target. The newfindEntryreads one listing per folder for the operation. Outside a cache,existsCaseExactis unchanged.findComponentSourcematches its candidate names against the listing it already holds, and skips the existence check for a folder it found in its parent's listing.existsCaseExactreads a plain path's segments straight off the string (an absolute root, then no empty,.or..segment); any other path still goes throughpath.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:
Whole files, the five test files in one run each time:
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):
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):
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
existsCaseExactor infindComponentSource, a case-insensitive match infindEntryor infindComponentSource, 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
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, thenpnpm test:node: 16,117 passed, 76 skipped, 0 failed (3,271 files).Earlier, at cd113e7 merged with main 2c53350:
listing-cache.test.mjs:findEntryandlistingCacheActive, andexistsCaseExactinside 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;pnpm build, thenpnpm 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:noderun 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.scripts/i18n-english-fallback.mjsand.github/scripts/lib/component-size.js, plus esbuild and TypeScript, and it bundles Core's builtdist.