Repository navigation
perf(cli): read a project's lockfile only for an Astryx package it has not installed - #12911
josephfarina wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
dc5d5c8 to
6803d17
Compare
…s not installed readReleaseFacts parsed the whole lockfile for Core and again for the CLI whenever either was missing, even for the one the folder had installed, and the exec door's package-set check parsed it once per declared package. A run reads these facts several times, so a Core-only app with a large lockfile paid four full parses per command and 25 per doctor run. Both now ask the lockfile only for packages nothing is installed for, and read it once for all of them. [skip ci]
6803d17 to
efd0629
Compare
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, because the pull request is a draft and its commit message carries [skip ci], so the required checks still have to run on a head without that marker before merge.
The lockfile is now read only for Astryx packages that nothing is installed for, and every answer stays the same. Command output is byte-identical before and after, and the reported parse counts reproduce exactly (doctor drops from 25 to 0 with Core installed, and from 48 to 24 in a fresh clone). The new test and the updated expectation fail without the change and pass with it.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Changeset: the CLI reads the lockfile only for an Astryx package the project has not installed. verified:
project.mjs:489-494,locked-versions.mjs:63-64 - Changeset: it reads the lockfile once per lookup for all such packages. verified:
project.mjs:268-283reads the file once and parses an npm lockfile once - Changeset: with every declared Astryx package installed, no command parses the lockfile. verified:
lockedVersionsis the CLI's only lockfile parser, anddoctor,componentanddocsshow 0 parses - Changeset: this saves about 50 ms per command and about 200 ms per
doctorrun with a 2 MB lockfile. verified as consistent: 4 → 0 and 25 → 0 parses at about 9-11 ms each - Description: before, the release facts parsed the lockfile for Core and again for the CLI whenever either was missing. verified: base
project.mjs:448-469 - Description: before, the package-set check parsed the lockfile once for each declared package. verified: base
locked-versions.mjs:39-58 - Description: only
coreVersionOfandmatchedVersionOfread the locked Core and CLI fields, and only when that package is not installed. verified:choose.mjs:395-427; there is no other reader - Description:
qualifyingRootis the only caller ofprojectAstryxPins, and it readslockedonly for uninstalled pins. verified:package-set.mjs:75-82,:106-108 - Description:
lockedVersionsreads once, parses npm JSON once and scans pnpm, Yarn and Bun once per package;lockedVersionwraps it. verified:project.mjs:252-296 - Description: the field docs and the file header say when a locked version is read. verified:
project.mjs:53-56,locked-versions.mjs:3-7,:26-27 - Description: parse counts: 25 → 0, 4 → 0, 4 → 0 with Core installed; 48 → 24, 6 → 3, 6 → 3 in a fresh clone. verified: reproduced exactly on matching fixture apps
- Description: a parse of a 2 MB lockfile costs about 9 ms. verified: 9-11 ms on a 1.9 MB fixture
- Description: every answer stays the same. verified: output is byte-identical for six command runs, and the Core version, matched release and package-set choice are identical on five fixtures
- Description: the named release-facts, package-set, doctor, init, upgrade, render, theme add and handoff tests pass, and the one updated expectation is a pin nothing reads. verified: those suites pass at this head (52 files), apart from three
cache.test.mjsprocess-lock tests that fail identically without the change - Description: a Yarn Plug'n'Play app still reads
yarn.lockfor Core, as before. verified:findReadCorelooks only innode_modulesandpackages/core(project.mjs:114-132) - Description: a fresh clone still parses the lockfile about 24 times per
doctorrun. verified: 24 on the fresh-clone fixture at this head - Description: no public API, product behavior or visual change. verified: no exported entry, command or option reaches the changed modules
- Description: new test: Core 0.7.1 installed beside a lockfile that records 0.7.0 gives no locked Core, and the CLI keeps 0.6.8. verified:
project.test.mjs:271-290; it fails on the base - File
packages/cli/foundation/release/project.mjs: clear - File
packages/cli/foundation/runtime/locked-versions.mjs: clear - File
packages/cli/foundation/release/project.test.mjs: clear - File
packages/cli/foundation/runtime/package-set.test.mjs: clear - File
.changeset/lockfile-read-once.md: clear (matches the code and the description)
- #12921 fix(Table): useTableSortableState sorts an Invalid Date like null instead of throwing Author: @josephfarina - #12911 perf(cli): read a project's lockfile only for an Astryx package it has not installed Author: @josephfarina - #12388 fix(core): a theme radius of different corners reaches what a Card, a Dialog and a menu hand each corner to Author: @josephfarina
|
Landed in #12945. |
Maintainer impact
Every CLI command in a project with a large lockfile paid for parsing that lockfile, often several times, even when every answer came from the packages the project had installed:
readReleaseFactsparsed the whole lockfile for Core, and again for the CLI, whenever either one was missing. That included the one the folder had installed. A run reads these facts several times, so an app with Core installed and no CLI of its own (the usual app the global CLI answers) paid 4 full parses percomponentordocscall and 25 perdoctorrun.projectAstryxPins) parsed the lockfile once for each declared@astryxdesign/*package, installed or not.With a 2 MB
package-lock.json, each parse costs about 9 ms.Intended invariant
Every answer stays the same. Only the lockfile reads change.
coreVersionOfandmatchedVersionOf(foundation/release/choose.mjs) readlockedCoreVersiononly when no Core is installed, andlockedCliVersiononly when no CLI is installed. Those are the only readers of the two fields.qualifyingRootkeeps only the pins nothing is installed for, andholdsreadspin.lockedonly for those (foundation/runtime/package-set.mjs). This is the one caller ofprojectAstryxPins.The versions a project would install keep the meaning that
architecture:cli-surfaceINV30 gives them.Change
foundation/release/project.mjs: the newlockedVersions(lockfile, memberDir, wanted)reads a lockfile once for several packages and parses an npm lockfile once (pnpm, Yarn and Bun lockfiles are still scanned once per package, as before), andlockedVersionwraps it.readReleaseFactsasks it for Core only when no Core is installed, and for the CLI only when no CLI is installed.foundation/runtime/locked-versions.mjs:projectAstryxPinsasks the lockfile, once, only for the declared packages that nothing is installed for.Evidence
Lockfile parses per command. The test app has a 2 MB
package-lock.jsonwith 6,000 packages. A preload hook counts reads of the lockfile and times everyJSON.parseof more than 1 MB.doctorcomponent Buttondocs use-a-themedoctorcomponent Buttondocs use-a-themedoctorin the installed app went from 1,632 ms to 1,123 ms). The parse counts are the stable measure.A fresh clone still reads the facts about 24 times per
doctorrun. Reading them once per run is a separate change. A Yarn Plug'n'Play app has nonode_modules, so the release facts find no installed Core there and still readyarn.lockfor it, as before.Scope
Components: CLI (release facts, the exec door's package-set check)
Testing
dcdd9faca6aplus this change:vitest run --project nodeoverfoundation/release,foundation/runtime,foundation/discovery,foundation/integrations,clients/cli/lib,clients/cli/commands/doctor*andinit*,api/doctor,api/upgrade,api/render,api/theme/add,test/install-guidance-surfaces.test.mjs,test/handoff.e2e.test.mjsandtest/doc-loads.test.mjs: 141 files, 3088 passed, 2 expected failures, 3 skipped.project.test.mjs"reads the lockfile only for a package it does not find installed" (Core installed at 0.7.1 beside a lockfile that records 0.7.0: no locked Core version; the CLI, not installed, still takes its locked 0.6.8).package-set.test.mjsexpects no lockfile version for the installed CLI pin.preflight: pass efd0629