Skip to content

perf(cli): read a project's lockfile only for an Astryx package it has not installed - #12911

Closed
josephfarina wants to merge 1 commit into
mainfrom
josephfarina/lockfile-read-once
Closed

josephfarina wants to merge 1 commit into
mainfrom
josephfarina/lockfile-read-once

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • readReleaseFacts parsed 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 per component or docs call and 25 per doctor run.
  • The exec door's package-set check (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.

  • coreVersionOf and matchedVersionOf (foundation/release/choose.mjs) read lockedCoreVersion only when no Core is installed, and lockedCliVersion only when no CLI is installed. Those are the only readers of the two fields.
  • qualifyingRoot keeps only the pins nothing is installed for, and holds reads pin.locked only for those (foundation/runtime/package-set.mjs). This is the one caller of projectAstryxPins.

The versions a project would install keep the meaning that architecture:cli-surface INV30 gives them.

Change

  • foundation/release/project.mjs: the new lockedVersions(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), and lockedVersion wraps it. readReleaseFacts asks it for Core only when no Core is installed, and for the CLI only when no CLI is installed.
  • foundation/runtime/locked-versions.mjs: projectAstryxPins asks the lockfile, once, only for the declared packages that nothing is installed for.
  • The field docs and the file header say when a locked version is read.

Evidence

Lockfile parses per command. The test app has a 2 MB package-lock.json with 6,000 packages. A preload hook counts reads of the lockfile and times every JSON.parse of more than 1 MB.

App Command Before (main) After
Core 0.7.10 installed, no CLI doctor 25 parses, about 216 ms 0
Core 0.7.10 installed, no CLI component Button 4, about 45 ms 0
Core 0.7.10 installed, no CLI docs use-a-theme 4, about 44 ms 0
Fresh clone (Core and CLI declared, nothing installed) doctor 48, about 417 ms 24, about 210 ms
Fresh clone component Button 6 3
Fresh clone docs use-a-theme 6 3
  • Failure before the change: the counts in the Before column.
  • Success after the change: the counts in the After column. Wall time on a shared box fell too (doctor in the installed app went from 1,632 ms to 1,123 ms). The parse counts are the stable measure.
  • Product/runtime behavior verified unchanged: the release-facts, package-set, doctor, init, upgrade, render, theme add and handoff tests pass unchanged. The one updated expectation is a pin for an installed CLI, which now has no lockfile version. Nothing reads that value.

A fresh clone still reads the facts about 24 times per doctor run. Reading them once per run is a separate change. A Yarn Plug'n'Play app has no node_modules, so the release facts find no installed Core there and still read yarn.lock for it, as before.

Scope

Components: CLI (release facts, the exec door's package-set check)

  • 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

  • With CI=1 on main dcdd9faca6a plus this change: vitest run --project node over foundation/release, foundation/runtime, foundation/discovery, foundation/integrations, clients/cli/lib, clients/cli/commands/doctor* and init*, api/doctor, api/upgrade, api/render, api/theme/add, test/install-guidance-surfaces.test.mjs, test/handoff.e2e.test.mjs and test/doc-loads.test.mjs: 141 files, 3088 passed, 2 expected failures, 3 skipped.
  • New test: 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).
  • Updated test: package-set.test.mjs expects no lockfile version for the installed CLI pin.
  • The parse counts in Evidence come from running the CLI from a checkout of main and from a checkout of this change, in the same two apps on the same box.

preflight: pass efd0629

@vercel

vercel Bot commented Nov 19, 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 19, 2026 2:15pm UTC

Request Review

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

astracat-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 19, 2026, 2:22 PM UTC

@josephfarina
josephfarina force-pushed the josephfarina/lockfile-read-once branch from dc5d5c8 to 6803d17 Compare November 19, 2026 13:51
…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]

@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, 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-283 reads the file once and parses an npm lockfile once
  • Changeset: with every declared Astryx package installed, no command parses the lockfile. verified: lockedVersions is the CLI's only lockfile parser, and doctor, component and docs show 0 parses
  • Changeset: this saves about 50 ms per command and about 200 ms per doctor run 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 coreVersionOf and matchedVersionOf read 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: qualifyingRoot is the only caller of projectAstryxPins, and it reads locked only for uninstalled pins. verified: package-set.mjs:75-82, :106-108
  • Description: lockedVersions reads once, parses npm JSON once and scans pnpm, Yarn and Bun once per package; lockedVersion wraps 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.mjs process-lock tests that fail identically without the change
  • Description: a Yarn Plug'n'Play app still reads yarn.lock for Core, as before. verified: findReadCore looks only in node_modules and packages/core (project.mjs:114-132)
  • Description: a fresh clone still parses the lockfile about 24 times per doctor run. 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)

Automated review (maintainer link)

@josephfarina
josephfarina marked this pull request as ready for review November 19, 2026 15:26
josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
- #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
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12945.

@github-actions
github-actions Bot deleted the josephfarina/lockfile-read-once branch November 20, 2026 06:06

This branch was successfully deployed

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