Skip to content

perf(cli): store search's catalog at publish, used where the project adds nothing and the CLI and Core are unchanged - #11755

Merged
josephfarina merged 4 commits into
mainfrom
speed/first-call-stored-catalog
Nov 14, 2026
Merged

josephfarina merged 4 commits into
mainfrom
speed/first-call-stored-catalog

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

A machine's first search or build gathers search's whole catalog from the CLI's and Core's shipped files: every component, hook, doc topic and section, template and theme. In a project with no integrations that takes about 350 ms of work, and recording and keeping the gather costs about 100 ms more. A run on a fresh machine, such as a new container or CI job, pays all of it. Every input of that gather is a file the two packages ship, so the answer is known when the CLI is packed.

Intended invariant

Every run prints the same output. The stored catalog is used only when all of these are true:

  • The project adds nothing to a catalog. This is checked live on every run: the run is not hosted, no integration can load (mayHaveIntegrations), no installed package declares Astryx docs or blocks (discoverExternalPackages), and the project's local themes root holds no theme folder, valid or not (discoverLocalThemes).
  • Every file and folder of the CLI and of the installed Core that the gather read is in the state it had at publish. A file counts by its content, a folder by the names it holds, and package.json by the fields a packer keeps.

Docs spell install commands for the project's package manager, so the package manager is worked out live and picks the stored copy for it. Any mismatch gathers live, as before: an edited, added or removed file, another Core version, a checkout, or a project with an integration or a local theme.

Change

  • scripts/generate-search-catalog.mjs runs at prepack, after the stores the gather reads and before the build id. It installs exactly the files the CLI and Core publish into a probe project, and gathers the catalog once for each package manager docs spell commands for, each in its own process. It writes assets/search-catalog.generated.json in two lines. The header holds the state of every CLI and Core file and folder the gather read. The body holds the catalog in the encoding search's kept gather already uses, stored once:
    • The npm catalog is stored whole. Each other package manager stores only the values that differ from it, each with its path (36 doc candidates differ, in their install commands).
    • A string whose JSON text is already in another store the gather reads (the stored docs, the stored component list) is a reference to that byte range, where the reference is the shorter. Those files are inputs checked by their content, so a reference is read only when its file is unchanged.
    • The generator reads the text back and fails unless every package manager's catalog equals its gather. It also fails if the probe project would add to a catalog, or if the catalog beside any lockfile is not the stored copy for the package manager detected there.
    • It also fails if the gather reads or probes any path outside the two packages that the run's live steps (the kept key's real folder, the lookup of the project's Core, and the project check) do not read too. Loaded code is left out, and so are the per-user folders, where the gather only finds integrations installed for the computer. Those never load inside a project, and a packed case below shows it. Paths are recorded exactly (the path probed, not its folder). Without the local-theme check, this guard fails on the gather's probe of src/themes. The file is not committed, like the other stores.
  • foundation/discovery/stored-search-catalog.mjs: storedSearchCatalog(coreDir, cwd) does the live project check, checks every recorded input by content, then reads the body (references resolved in its text before one parse) and returns the catalog for the package manager. keptStoredCatalog(pm) reads it without the check.
  • api/search/_adapter.mjs: the adapter uses the store before it gathers. No command handler reads a file. When the store answers a gather, the kept gather keeps a reference to the store, not a copy of the catalog. The run's stamps already hold every file the content check read, so a warm run that finds them unchanged reads the store back without checking it again. A project with no integrations then keeps one 380 KB entry after its first search instead of six entries of 6.6 MB.
  • pack-cli.mjs, prepack/postpack and .gitignore include the new generator. doc-loads.test.mjs lists its spawn.

Declared difference

None in output.

Package growth: assets/search-catalog.generated.json is 1,655,594 bytes unpacked and 346,209 bytes with gzip -9. The CLI tarball grows from 5,705,949 to 6,059,755 bytes (+353,806, about 6%). A plain copy of the catalog would be 2,396,856 bytes (571,777 gzip). Storing only the values that differ per package manager saves 51 KB gzip, and referring to text the other stores already hold saves 175 KB gzip. Most of what is left is doc prose that no other store holds as is (it is derived from the docs' text), and the per-file content states (about 63 KB gzip).

Evidence

Packed CLI and Core from this branch's base, and from this branch. Each sample is a new machine: its own HOME, cache, config and temp folders, with CI=1. Median of 9, in ms. First is call 1, second is call 2, warm is the median of calls 3 to 5.

Project Command Before: first / second / warm After: first / second / warm
Core only search button --json 814 / 321 / 319 460 / 324 / 324
Core only build "<dashboard idea>" --json 1,224 / 646 / 646 930 / 644 / 643
Core only component Button 341 / 265 / 264 349 / 269 / 270
Core only docs 344 / 284 / 286 349 / 290 / 288
Core only template --list 322 / 265 / 264 324 / 262 / 265
Large TypeScript integration search button --json 1,857 / 411 / 411 1,794 / 401 / 401
Large TypeScript integration build "<dashboard idea>" --json 2,285 / 793 / 786 2,248 / 791 / 783
Large TypeScript integration component Button 1,254 / 387 / 388 1,274 / 392 / 391
Large TypeScript integration docs 1,171 / 399 / 397 1,199 / 407 / 401
Large TypeScript integration template --list 1,301 / 336 / 335 1,314 / 336 / 359
  • A one-off npx, Core only: a new npm cache and _npx folder each time (dependencies served from a warmed cache copy), the CLI installed from its tarball, then search button --json. Median of 7: 4,424 → 4,111 ms. The output is the same.
  • Warm A/B, interleaved, Core only: search button --json 321.4 → 324.5 (60 runs), search "date picker" 408.4 → 406.0 (60), build "<dashboard idea>" --json 649.6 → 646.0 (30), component Button 273.4 → 271.0, docs 285.8 → 286.8, template --list 264.2 → 264.4 (30 each). These are within ±3 ms.
  • With the integration the store is never used; those rows moved by noise only.
  • Cost of a store hit on the first call: about 7 ms for the live project check, 43 ms for the content check (2,223 inputs, 10.6 MB), and about 15 ms to read the body. The net numbers above include it.
  • Output is byte-identical (stdout, stderr and exit code) between the two packed CLIs. This holds on the first call and on the third (the kept reference), Core only and with the integration, for 17 asks: search as text, --json, --detail compact and --dense, doc, template, theme, hook and component searches, and build as text, --json and --detail compact.

Scope

Components: CLI search catalog (stored at publish)

  • 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

New test/packed-search-catalog.test.mjs, using the packed CLI and a project holding a copy of Core's published files. It fails on the base and passes here (11 cases):

  • the store ships;
  • the store answers, and 13 search and build asks in every output form are byte-identical to the checkout CLI, which gathers live;
  • beside a pnpm, yarn or bun lockfile the store still answers, and search install --json (which shows install commands) matches the live gather;
  • the kept gather holds a reference to the store and no candidates, and its warm read is byte-identical;
  • an Astryx config in the project, or an installed package that declares Astryx docs, turns the store off;
  • in a project where theme eject neutral src/themes/house wrote a local theme, the store is off, and search house --type theme --json finds the theme and matches the live gather (this case fails with the local-theme check taken out);
  • a project that is an integration itself (its own manifest), or declares a dependency that ships one, turns the store off, and search finds the integration's template as the live gather does;
  • a folder with installed packages and no package.json answers as the live gather does;
  • a declared packageManager field, and an npm_config_user_agent from another package manager, each answer as the live gather does;
  • inside a project, an integration installed beside a CLI installed for the computer (home folder and search path set to it) does not change the answer, which matches the live gather;
  • a same-size in-place edit with its mtime put back misses the store, for a shipped doc topic, a shipped template doc and an installed Core doc. Each shows the edit in the output, and the output equals the packed CLI's live gather. Restoring the file hits again.

The CLI suites for api/search, api/build, foundation/fs, foundation/discovery, the packed kept-gather, component-list and self-audit tests, and doc-loads pass (105 files, 1,955 tests).

…adds nothing and the CLI and Core are unchanged
@vercel

vercel Bot commented Nov 14, 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 14, 2026 4:26pm UTC

Request Review

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

astracat-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 14, 2026, 4:41 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.

Changes requested. Storing search's catalog at publish makes the first search and build calls clearly faster. Right now, though, the store also answers in a project that has a local theme, and astryx search then loses that theme.

  • In a project with a theme in src/themes and no integration, projectAddsToCatalog (packages/cli/foundation/discovery/stored-search-catalog.mjs:86-92) lets the store answer, so an open astryx search <slug> prints "No results" while theme list shows the theme and the live gather finds it (spec:AST-050 FR14). Please count a local themes root that holds a theme as adding to the catalog (or merge local themes in live), correct the header comment that calls the current checks the only ways a project adds to a catalog, and add a packed test with an ejected theme.
  • The changeset says the store is used only "in a project that adds nothing to a catalog" and that "Output is the same", but a project with a local theme contradicts both today. Once the check above is in, add local themes to the changeset's list of cases that gather live.

Next: fix the project check and the changeset, then push for another review.

Claims and files checked
  • Claim: the published CLI stores search's catalog at publish. Verified (package.json prepack, scripts/generate-search-catalog.mjs, test "ships in the package").
  • Claim: the store is used only where the project adds nothing and the CLI and Core files are unchanged. False for a local theme in src/themes (finding 1). The input-state part is verified (stored-search-catalog.mjs:103-115, in-place edit test).
  • Claim: an integration, a docs or blocks package, another Core version or an edited file gathers live. Verified (packed-search-catalog.test.mjs:222-288, Core input check).
  • Claim: output is the same, byte for byte, across the listed asks. Verified for the PR's 13 asks (test passes). False for a local-theme project (finding 2).
  • Claim: the first search is about 350 ms faster and the first build about 290 ms faster. Same direction here: a cold search button --json took 283 ms instead of 547 ms. build was not re-measured.
  • Claim: a file counts by its content, a folder by its names and package.json by its packer-kept fields. Verified (stored-self-audit.mjs:59-81).
  • Claim: the package manager is worked out live and picks the stored copy. Verified (stored-search-catalog.mjs:113-114, lockfile test).
  • Claim: the generator runs after the other stores and before the build id, once per package manager in its own process. Verified (package.json prepack, pack-cli.mjs stages, generate-search-catalog.mjs:83-109, :309-310).
  • Claim: npm's catalog is stored whole and the others store only differences (36 doc candidates). Verified: pnpm and bun differ in 36 candidates.
  • Claim: references are used only where shorter and only into files checked by content, and the generator reads the store back and checks the probe and each lockfile. Verified (generate-search-catalog.mjs:142-149, :188-200, :59, :314-325).
  • Claim: the kept gather keeps a reference, not a copy, and its warm read is the same. Verified (api/search/_adapter.mjs:178-182, :218-226, test at :204-220).
  • Claim: the store is about 1.65 MB unpacked and the tarball grows about 6%. The store measures 1,655,594 bytes at this head. The tarball was not re-measured.
  • Claim: no public API change. Verified (exports, bin, api/index.mjs and command docs unchanged).
  • Claim: the new test and the CLI suites pass. Verified: 6 of 6 new tests, and 27 files and 369 tests across api/search, doc-loads and the kept-gather tests.
  • File .changeset/stored-search-catalog.md: finding 2.
  • File packages/cli/.gitignore: clear.
  • File packages/cli/api/search/_adapter.mjs: answers from the store that finding 1 lets through, otherwise clear.
  • File packages/cli/foundation/discovery/stored-search-catalog.mjs: finding 1.
  • File packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear.
  • File packages/cli/package.json: clear.
  • File packages/cli/scripts/generate-search-catalog.mjs: its probe proves only an empty project (finding 1), otherwise clear.
  • File packages/cli/test-utils/pack-cli.mjs: clear.
  • File packages/cli/test/packed-search-catalog.test.mjs: no local-theme case (finding 1).

Automated review (maintainer link)

Comment thread .changeset/stored-search-catalog.md Resolved
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · c06b3c1

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 4.52 MB packed (+4.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

…oves every project path the gather reads is checked live
…atalog is checked live or misses the store, a packed case for each

@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.

Changes requested. The local-theme fix holds: a project with a theme in src/themes now gathers live, and an open astryx search finds the theme. One problem remains, in the new prepack generator.

  • Miss: packages/cli/scripts/generate-search-catalog.mjs creates its probe project under os.tmpdir() without resolving it (:306-312) but compares it with the real paths the gather reads (:79-90), so wherever the temp folder sits behind a symlink, as macOS's default /var/folders/... does, prepack and every packed CLI test fail with "the gather reads paths outside the packages that the live check does not"; resolving the stage and home with fs.realpathSync and testing containment with path.relative (as selfAuditInputs does) fixes it and also covers Windows separators.

Next: fix the generator's temp-folder paths, then push for another review.

Claims and files checked
  • Claim: the published CLI stores search's catalog at publish. Verified (package.json prepack, packed case "ships in the package").
  • Claim: the store is used only when the run is not hosted, no integration can load, no installed package declares docs or blocks, and the local themes root holds no theme folder, valid or broken. Verified (stored-search-catalog.mjs:93-121, packed cases for each, and a broken-folder probe).
  • Claim: every CLI and Core file and folder the gather read must be unchanged, a file by content, a folder by its names and package.json by packer-kept fields. Verified (stored-self-audit.mjs inputState, in-place edit case).
  • Claim: the package manager is worked out live and picks the stored copy. Verified (stored-search-catalog.mjs:142-144, lockfile, packageManager and user-agent cases).
  • Claim: the generator runs after the other stores and before the build id, once per package manager in its own process. Verified (package.json, pack-cli.mjs stages, generate-search-catalog.mjs:106-132, :330-333).
  • Claim: npm's catalog is stored whole and the others store only differences (36 doc candidates). Verified: pnpm and bun differ in 36 candidates, yarn in 27 and yarn-classic in 33.
  • Claim: references point into other stores only where shorter and are read only when that file is unchanged. Verified (only content-checked inputs are referenced, and the content check runs before the body is read).
  • Claim: the generator reads the store back for every package manager, fails if the probe project adds to a catalog, and checks the catalog beside each lockfile. Verified (generate-search-catalog.mjs:72, :212-222, :337-348).
  • Claim: the generator fails if the gather probes a project path the live steps do not read, and without the local-theme check it fails on src/themes. Verified on a resolved temp folder: the gather's project probes are covered, and only the local-theme check reads src/themes. Under a symlinked temp folder it also fails on every CLI and Core file (the finding above).
  • Claim: the store file is not committed. Verified (.gitignore).
  • Claim: storedSearchCatalog checks before it reads the body, and keptStoredCatalog reads without the check. Verified (stored-search-catalog.mjs:132-156).
  • Claim: the kept gather keeps one small reference instead of several large entries. Verified for the head: one 429 KB entry with no candidates. The "six entries of 6.6 MB" figure for the base was not reproduced: the base keeps two entries of 3.8 MB after the same first search here.
  • Claim: pack-cli.mjs, prepack/postpack, .gitignore and the runner list include the generator. Verified (doc-loads passes).
  • Claim: output is the same in every case. Verified for the 13 asks, each lockfile, a declared package manager, a user agent, integrations, a computer-wide integration, local and broken themes, and edited files.
  • Claim: the store is 1,655,594 bytes and the tarball grows about 6%. The store size matches exactly; the tarball and gzip savings were not re-measured.
  • Claim: the first search is about 350 ms faster and the first build about 290 ms faster. Same direction: 307 instead of 627 ms, and 781 instead of 1,045 ms here.
  • Claim: projects with an integration never use the store. Verified (mayHaveIntegrations gate).
  • Claim: a store hit content-checks 2,223 inputs. Verified (1,718 CLI and 505 Core inputs); the timings were not re-measured.
  • Claim: no public API, product behavior, visual or policy change. Verified (exports, bin and command docs unchanged, output identical).
  • Claim: the new test fails on the base and passes here (11 cases). Verified: 11 of 11 pass, and the base ships no store.
  • Claim: the CLI suites pass. Verified with a resolved temp folder (106 files, 1,977 tests). Under a symlinked temp folder the packed suites fail (the finding above).
  • File .changeset/stored-search-catalog.md: clear.
  • File packages/cli/.gitignore: clear.
  • File packages/cli/api/search/_adapter.mjs: clear.
  • File packages/cli/foundation/discovery/stored-search-catalog.mjs: clear.
  • File packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear.
  • File packages/cli/package.json: clear.
  • File packages/cli/scripts/generate-search-catalog.mjs: the finding above.
  • File packages/cli/test-utils/pack-cli.mjs: clear; it runs the generator, so the finding reaches every packed test.
  • File packages/cli/test/packed-search-catalog.test.mjs: clear.

Automated review (maintainer link)

@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: the required checks have not finished on this head yet.

The temp-folder fix holds: where the temp folder sits behind a symlink, as on macOS, the prepack generator now writes the store and the packed CLI tests pass. Every earlier finding is resolved, and nothing else blocks. Next: the merge guard merges once the required checks pass.

Claims and files checked
  • Claim: the published CLI stores search's catalog at publish and uses it where the project adds nothing and the CLI's and Core's files are unchanged. Verified (package.json prepack, stored-search-catalog.mjs:132-145, packed case "ships in the package").
  • Claim: a machine's first search answers about 350 ms sooner and its first build about 290 ms sooner. Same direction, larger here on a slower machine: 496 instead of 908 ms, and 1,117 instead of 1,848 ms.
  • Claim: the catalog is gathered live with an integration, a package that adds docs or blocks, a local theme, another Core version, or after a change to any file or folder the catalog reads. Verified (stored-search-catalog.mjs:93-121, :132-145, packed cases for each).
  • Claim: output is the same. Verified for the 13 asks, each lockfile, a declared package manager, a user agent, integrations, a computer-wide integration, a local theme and edited files.
  • Claim: the store is used only when the run is not hosted, no integration can load, no installed package declares docs or blocks, and the local themes root holds no theme folder, checked live on every run. Verified (stored-search-catalog.mjs:93-121).
  • Claim: every recorded CLI and Core file and folder must be unchanged: a file by content, a folder by its names, package.json by packer-kept fields. Verified (stored-self-audit.mjs inputState, in-place edit case).
  • Claim: the package manager is worked out live and picks the stored copy. Verified (stored-search-catalog.mjs:142-144, lockfile, packageManager and user-agent cases).
  • Claim: the generator runs at prepack after the stores it reads and before the build id, installs exactly the published files and gathers once per package manager in its own process. Verified (package.json, pack-cli.mjs stages, generate-search-catalog.mjs:111-141, :341-342).
  • Claim: npm's catalog is stored whole and the other package managers store only differences (36 doc candidates). Verified: pnpm and bun differ in 36 candidates, yarn in 27 and yarn-classic in 33; the store's size is unchanged since the last reviewed revision.
  • Claim: strings already held by another content-checked store are byte-range references, read only when that file is unchanged. Verified (generate-search-catalog.mjs:153-233; the content check runs before the body is read).
  • Claim: the generator reads the store back for every package manager, fails if the probe project adds to a catalog, and checks the catalog beside each lockfile. Verified (generate-search-catalog.mjs:64-72, :221-231, :346-357).
  • Claim: the generator fails if the gather probes a path outside the two packages that the live steps do not read. Verified (:80-91), now also under a temp folder behind a symlink.
  • Claim: the store file is not committed. Verified (packages/cli/.gitignore:47-50).
  • Claim: storedSearchCatalog checks before it reads the body, and keptStoredCatalog reads without the check. Verified (stored-search-catalog.mjs:132-156).
  • Claim: the adapter uses the store before it gathers, and the kept gather keeps a reference instead of a copy. Verified (api/search/_adapter.mjs:113-126, :178-182, :218-226, packed case).
  • Claim: a project with no integrations keeps one 380 KB entry after its first search instead of six entries of 6.6 MB. The head keeps one 429 KB entry here; the same first search on the live path keeps two entries of 3.8 MB here, so the saving holds but the base figure was not reproduced.
  • Claim: pack-cli.mjs, prepack/postpack, .gitignore and the runner list include the generator. Verified (doc-loads passes).
  • Claim: the store is 1,655,594 bytes unpacked and the tarball grows about 6%. The store size matches exactly; the tarball and gzip figures were not re-measured.
  • Claim: warm runs are unchanged within a few milliseconds, and a store hit costs about 65 ms of checks. Not re-measured; the first-call gains above include those checks.
  • Claim: output is byte-identical between the two packed CLIs for every ask, on the first and third call. Verified for the PR's 13 asks and the kept-reference case.
  • Claim: no public API, product behavior, visual or policy change. Verified (exports, bin and command docs unchanged; output identical).
  • Claim: the new packed test fails on the base and passes here (11 cases). Verified: 11 of 11 pass, and the base ships no store.
  • Claim: the CLI suites pass. Verified: 106 files and 1,977 tests here, and the packed suites also pass under a symlinked temp folder.
  • File .changeset/stored-search-catalog.md: clear.
  • File packages/cli/.gitignore: clear.
  • File packages/cli/api/search/_adapter.mjs: clear.
  • File packages/cli/foundation/discovery/stored-search-catalog.mjs: clear.
  • File packages/cli/foundation/doc-compiler/doc-loads.test.mjs: clear.
  • File packages/cli/package.json: clear.
  • File packages/cli/scripts/generate-search-catalog.mjs: clear; the temp-folder fix holds.
  • File packages/cli/test-utils/pack-cli.mjs: clear.
  • File packages/cli/test/packed-search-catalog.test.mjs: clear.

Automated review (maintainer link)

@josephfarina
josephfarina merged commit 3108201 into main Nov 14, 2026
76 checks passed
@github-actions
github-actions Bot deleted the speed/first-call-stored-catalog branch November 15, 2026 06:04

This branch was successfully deployed

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