Skip to content

perf(cli): a run takes each kept list of reads once - #11877

Merged
josephfarina merged 1 commit into
mainfrom
speed/reused-states
Nov 15, 2026
Merged

josephfarina merged 1 commit into
mainfrom
speed/reused-states

Conversation

@josephfarina

Copy link
Copy Markdown
Contributor

Summary

A command that reuses kept data hands what each kept value read to the run's records, so a gather stored later in the run knows what it depends on. Two parts of that did work the run did not need:

  • foundation/fs/read-record.mjs: recordStates takes a list of states once per record. A run handed the same kept list in once for every step that reused it: a kept value reused by several loaders, or a base entry under several entries the run read back. A list does not change once handed in, and a record keeps each path's fullest state, so a second hand-in changed nothing. In a warm theme list in a project with a large integration, 12 hand-ins went over about 14,500 states, most of them already held.
  • foundation/fs/gather-cache.mjs: a hit leaves the states of the CLI's own files it depends on to be worked out when a derived value asks for them. Every hit merged them, and only a derived value after the hit reads them. The merge takes the common cases, a path not held yet and a state already held, without the rule.

Evidence

Warm wall time, a fresh process per call, base (main) and change interleaved, n=21, median of the paired difference (95% CI):

Command Large integration Core-only
component Button −11 [−12, −9], −2.1% +1 [−1, +4]
docs theme −4 [−6, −1], −0.9% −2 [−5, +0]
doctor −14 [−17, −8], −2.2% −3 [−7, +0]
search button −6 [−9, −2], −1.2% −1 [−4, +5]
template dashboard −5 [−10, +0], −1.2% −4 [−8, −0]
theme list −9 [−11, −7], −2.0% −1 [−4, +3]
theme list --json −7 [−10, −3], −1.7% −1 [−5, +0]

Identity: every timed run printed the same stdout and stderr, with the same exit code, as main.

Tests

  • foundation/fs/read-record.test.mjs: a list of states is taken once per record, however often a run hands it in, and in full by another record. The row fails with the skip removed.
  • foundation/fs and both packed kept-catalog suites: 18 files, 338 tests pass.

Scope

No output, flag or JSON shape changes.

@vercel

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

Request Review

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

astracat-bot Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 15, 2026, 1:43 PM UTC

@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 finished on this head yet.

Taking each kept list once per record and deferring the CLI-file merge on a gather hit leave every record and derived-value key the same: the new test row fails without the skip and passes with it, and random sequences of repeated hand-ins give identical records before and after. Nothing needs to change.

Claims and files checked

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

  • Claim (changeset): a command that reuses kept data hands each kept list to the run's records once, not once per reusing step. Verified: packages/cli/foundation/fs/read-record.mjs:378-384 and the new test row.
  • Claim (changeset): the CLI-file states a derived value keys on are worked out only when one is asked for. Verified: packages/cli/foundation/fs/gather-cache.mjs:955 and :1029.
  • Claim (changeset): component, docs, doctor, search, template and theme list finish 4 to 14 ms sooner in a project with a large integration. Unverified, not false: the author's paired timings; the work it removes is verified in code.
  • Claim (changeset and description): output, flags and JSON shape do not change. Verified: no command, command doc, formatter or export changes, and the records a run keeps are identical.
  • Claim (description): a handed-in list does not change and a record keeps each path's fullest state, so a second hand-in changes nothing. Verified: both callers hand in parsed, snapshot or finished lists (gather-cache.mjs:942, read-record.mjs:516), and keepState only strengthens a state (read-record.mjs:409-421).
  • Claim (description): 12 hand-ins over about 14,500 states in a warm theme list. Unverified, not false: the author's count.
  • Claim (description): only a derived value after a hit reads the CLI-file states. Verified: persistedDerived is the only reader (gather-cache.mjs:1028-1033).
  • Claim (description): the merge handles an absent path and an already-held state without the rule. Verified: gather-cache.mjs:706-710, equivalent to keepState.
  • Claim (description): the timing table, and every timed run printing the same output and exit code as main. Unverified, not false: the author's measurements; the identical records support the output part.
  • Claim (description): the new row fails with the skip removed. Verified: it fails on the base at read-record.test.mjs:488 and passes on the head.
  • Claim (description): the foundation/fs and packed kept-catalog suites pass. Verified: those suites and every other packed kept-catalog suite pass at the head (25 files, 395 passed, 4 skipped).
  • File .changeset/reused-states-once.md: clear.
  • File packages/cli/foundation/fs/gather-cache.mjs: clear.
  • File packages/cli/foundation/fs/read-record.mjs: clear.
  • File packages/cli/foundation/fs/read-record.test.mjs: clear.

Automated review (maintainer link)

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · e426bed

Storybook · Sandbox · built from this PR's head

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: unknown (base surface unavailable): richtext, theme-butter, theme-chocolate, theme-gothic, theme-matcha, theme-neutral, theme-stone, theme-y2k

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@josephfarina
josephfarina merged commit b317e8a into main Nov 15, 2026
83 checks passed
@github-actions
github-actions Bot deleted the speed/reused-states branch November 16, 2026 06:04

This branch was successfully deployed

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