Skip to content

fix(cli): searchCore reuses the gathered candidates, as search does - #8512

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/search-core-reuse
Nov 4, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:uikit/search-core-reuse

Conversation

@vjeux

@vjeux vjeux commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

User impact

searchCore, the lexical ranker that astryx build ranks with, gathered every candidate again on every query: about 0.75 s of listing and reading every domain. search reads the same candidates through a reuse that checks each input for changes, so a long-running caller paid the gather once there but on every query here. _main-searcher.test.mjs compares the two query by query. Its whole-name case takes about 2.8 s alone and fails its 30 s limit on a busy machine.

Problem and solution fit

Expected behavior and authority

The reuse contract in gatherCandidatesReused: a later search in the same folder, for the same type, ranks the candidates an earlier search gathered while none of their inputs changed. The lexical ranker answers the same either way.

Smallest restoration

searchCoreRead reads through gatherCandidatesReused. One line plus its JSDoc.

Evidence

  • Reproduction before the change: a new _adapter.test.mjs case holds the inputs unchanged and counts Project.load calls during a second searchCore('Button') in the repository: 5 on main.
  • Result after the change: 0 calls, and the second answer equals the first.
    • _main-searcher.test.mjs alone, 2 runs per side: "answers a whole-name query exactly as the lexical ranker does" takes 2.87 s and 2.77 s on main, 0.67 s twice with the fix. "never returns more results or more bytes than the lexical ranker" goes from 6.69 s and 6.57 s to 2.48 s and 2.51 s.
    • On a busy machine (one CPU for the run beside 8 busy loops), main fails the whole-name case at 36.0 s and 36.1 s, over its 30 s limit. With the fix it takes 7.1 s and 8.0 s, and the file passes both runs.
    • The file's first case pays its one cold gather either way, 28.7–32.2 s on main and 29.2–29.9 s with the fix at that load. This change does not touch that cost.
  • Which calls reuse the gather (local probe, not part of the diff: Project.load calls made by the second of two queries in one process, in the repository): searchCore after searchCore, searchCore after search, and search after searchCore load the project 5 times each on main and 0 times here. search after search loads it 0 times on both.
  • Representative unchanged path: the _main-searcher cases still compare both rankers query by query, and the existing reuse cases (an edited input, another folder or type, a linked package) pass.
  • Regression test: that Project.load count.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

At cfad6d6 on main 8516fb5. The head, 712626c, changes only the changeset's wording; there api/search/_adapter.test.mjs passes 6 of 6:

  • vitest run --project node on api/search and api/build: 21 files, 273 tests pass.
  • The loaded runs come from a one-off script that is not part of this change. One user systemd scope with CPUQuota=100% holds the vitest run and 8 node -e 'for(;;){}' loops. Sides alternate first and last, with pnpm install --frozen-lockfile at each revision (exit 0). Times are vitest's per-case durations.
  • eslint (CI=true), pnpm lint and Prettier pass on the changed files. pnpm review:pre: 0 findings.

@vercel

vercel Bot commented Oct 26, 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 4, 2026 11:59am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 4, 2026, 12:08 PM UTC

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 70f0fe8

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 3.34 MB packed (+115 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 8 rows, theme-butter 1 row, theme-chocolate 1 row, theme-gothic 1 row, theme-matcha 1 row, theme-neutral 1 row, theme-stone 1 row, theme-y2k 1 row; run pnpm api:report.

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

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

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

Recommended for approval: searchCore now ranks the catalog search already reuses, its answers are unchanged, and the new test fails before the change and passes after it. Worth one line in the changeset or description: each one-shot astryx build now records every read of its single gather, which measured about 9% (roughly 200 ms) slower per invocation, the same cost one-shot astryx search already pays in exchange for a much faster repeated build in a long-running process.

[Automated review]

@vjeux
vjeux marked this pull request as draft October 29, 2026 22:37
@vjeux
vjeux force-pushed the uikit/search-core-reuse branch from 7db035e to cfad6d6 Compare November 4, 2026 05:54
@vjeux vjeux changed the title fix(cli): the lexical ranker reuses the gathered candidates, as search does fix(cli): searchCore reuses the gathered candidates, as search does Nov 4, 2026

@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 code change is sound and its answers are unchanged, but one sentence of the changeset needs rewording before approval.

  • Newly live check: .changeset/cli-search-core-reuse.md says a long-running caller that "builds or searches repeatedly" no longer re-reads every catalog, but search already reused its gather before this change, so name only what changed, for example "A long-running caller that builds repeatedly, or builds after a search in the same folder, no longer reads every component, hook, doc, template and theme again for each build."

CI has not run on this head yet: mark the pull request ready for review, and a maintainer adds the ci:run label so CI runs.

[Automated review]

Comment thread .changeset/cli-search-core-reuse.md Outdated
'@astryxdesign/cli': patch
---

[fix] The lexical ranker behind `astryx build`'s search ranks the candidates search gathers, reused the same way. A later query in the same folder gathers again only when an input changed. A long-running caller that builds or searches repeatedly no longer reads every component, hook, doc, template and theme again for each query. Results are unchanged.

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.

Newly live check: search already reused its gather before this change (a second search loads nothing either way), so "builds or searches repeatedly" claims a change for search callers that did not happen. Suggested wording: "A long-running caller that builds repeatedly, or builds after a search in the same folder, no longer reads every component, hook, doc, template and theme again for each build."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 712626c, worded to what changed. A probe counting Project.load in the second of two queries shows three pairs go from 5 to 0: a build after a build, a build after a search, and a search after a build (build's gather now fills the shared reuse). A search after a search stays at 0, so the changeset no longer claims it.

searchCore, the ranker astryx build ranks with, called gatherCandidates
on every query: about 0.75 s of listing and reading every domain.
search reads the same candidates through gatherCandidatesReused, which
checks every input for changes. searchCore now reads through the same
reuse, and rankLexical only reads the catalog, so answers are
unchanged. A second searchCore in the same folder with unchanged inputs
loads the project 0 times instead of 5.

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

searchCore now ranks the catalog search already reuses, its answers are unchanged, the new test fails without the change, and the reworded changeset names only what changes. Next, mark the pull request ready for review, and a maintainer adds the ci:run label so CI runs.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 4, 2026 06:38
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 4, 2026
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 07:45
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 07:45
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 10:12
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 10:13
@cixzhang
cixzhang marked this pull request as draft November 4, 2026 11:53
@cixzhang
cixzhang marked this pull request as ready for review November 4, 2026 11:53

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

searchCore now ranks the catalog search already reuses, so a repeated build, or a search after a build, in the same folder stops gathering every domain again. Its answers are unchanged, the new test fails without the change, and the changeset names only what changes.

[Automated review]

@cixzhang
cixzhang merged commit d0a3106 into meta:main Nov 4, 2026
68 of 106 checks passed
@vjeux
vjeux deleted the uikit/search-core-reuse branch November 4, 2026 12:35
This was referenced Nov 6, 2026

This branch was successfully deployed

1 active deployment
Preview — 70f0fe8c Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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.

2 participants