Skip to content

perf(cli): the first how ask compiles only the lexicon patterns it can match - #13190

Merged
josephfarina merged 2 commits into
feature/theme-editorfrom
josephfarina/how-first-ask-warm-up
Nov 21, 2026
Merged

josephfarina merged 2 commits into
feature/theme-editorfrom
josephfarina/how-first-ask-warm-up

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Why

astryx experimental theme editor how runs every pattern in the editor's part lexicon for each ask, about 1,700 of them. V8 compiles a regular expression the first time it runs. So the first ask in a process compiled all of them, about 0.8 s of its 1.2 s. Users pay that on every CLI call that asks how, and every test file that asks it pays it once.

What changes

A lexicon pattern made from a part, group or piece name already records the word that every match of it holds. The lexicon's index uses that word to skip such patterns where they cannot match. That pattern is now a NeedRegExp, a RegExp whose exec returns null at once for a text without its word, without running or compiling the pattern. test, match, matchAll, replace, search and split all go through exec, so every call site that runs a lexicon pattern gets the same skip without changing.

  • Copies made from a lexicon pattern (a g copy, a pattern built around it) keep the word: lexCopy and lexAround replace new RegExp(re.source, …) at those sites.
  • A case-blind copy keeps no word.
  • Hand-written lexicon patterns carry no word and run as before.

Evidence

  • First ask in a fresh process (same machine, two runs each): 1,246 / 1,238 ms before, 456 / 447 ms after. The second ask is unchanged (109 / 108 → 109 / 105 ms).
  • Answers are byte-identical. Every how answer from the how and asks test files was dumped before and after, with 0 differences (1,949 calls on the current main).
  • New unit tests (theme-how-lexicon-need.test.mjs):
    • A made pattern answers like the plain one on every text, through each method and flag set.
    • A copy keeps its word.
    • A text without the word never reaches RegExp.prototype.exec.

Times-only record update, on top of the refreshed record: scripts/vitest-node-durations.json updates the times of 245 existing Node test files that this change moves (237 faster, 8 slower). Each entry is the refreshed value plus the measured change. Each change rests on two interleaved runs, before and after the change, on one machine. Both runs agree on the direction, and the change is scaled by the record-to-local ratio. No other entry changes, no file is set to zero, and none of the 245 files is touched by this change. The planned slowest Node leg goes from 11.45 to 11.28 minutes.

Testing

  • CI=1 vitest run --project node packages/cli/api/theme-edit/theme-how-lexicon-need.test.mjs
  • All theme-editor and theme tests (6,711), before and after, twice each, 12 workers. They all pass. Summed test time is 3,805 → 3,490 s, then 3,616 → 3,544 s.

preflight: pass 5d6c171

@vercel

vercel Bot commented Nov 21, 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 21, 2026 5:45am UTC

Request Review

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

astracat-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔄 In progress (for maintainers only) Nov 21, 2026, 5:34 AM UTC

…n match

An ask runs every pattern in the part lexicon, and the first run of a
pattern compiles it, so a process's first ask compiled about 1,700
patterns. A pattern made from a part, group or piece name already records
the word every match of it holds. It is now a RegExp whose exec answers
at once for a text without that word, and its copies keep the word, so
such patterns are never compiled for an ask that cannot match them.
Answers do not change.
…on [skip ci]

Times only, on the refreshed record: 245 Node test files whose time the
change measurably moves, in two interleaved same-machine runs that agree
on the direction (237 faster, 8 slower), each entry the refreshed value
plus the measured change. No other entry changes.

@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 lexicon speedup itself looks correct and keeps every answer the same, but this head cannot merge and its release note miscounts.

  • scripts/vitest-node-durations.json conflicts with the refreshed record now on main (19 hunks), and 9 of the 236 entries here are rescaled from values main has since re-measured (for example theme-readers-part-named-color.test.mjs is 157.5 on main and 69.8 here), so drop the times-only commit and let the scheduled refresh re-measure, or rebase and rescale those entries from main's values.
  • The Changeset and description say the first ask compiled "about 1,700 patterns", but the part lexicon on this head holds 5,343 entries (5,053 made patterns), so correct the count or drop it.

Answers to 2,806 questions taken from the how and ask tests are byte-identical before and after this change, and the first ask is markedly faster while the second is unchanged.

Claims and files checked

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

Claims:

  • An ask runs every part-lexicon pattern, and V8 compiles each one on its first run: verified (the lexicon loop; the base's first ask runs 8,033 distinct patterns).
  • The lexicon holds about 1,700 patterns: false (5,343 entries on this head).
  • A pattern made from a part, group or piece name records a word every match holds, and the index uses it to skip: verified (the needing call sites and mayMatch).
  • Such a pattern is now a NeedRegExp whose exec returns null for a text without its word, without running or compiling: verified (NeedRegExp.exec; the new unit test spies on the built-in exec).
  • test, match, matchAll, replace, search and split all go through exec: verified (unit test across three flag sets).
  • Copies keep the word through lexCopy and lexAround, a case-blind copy keeps none, and hand-written patterns run as before: verified (constructor and every converted call site; no lexicon copy is left on plain new RegExp).
  • The first ask is about 0.8 s sooner and the second is unchanged: verified in direction (first ask 997–1,133 ms to 561–625 ms on a slower machine; second ask 170–192 ms on both).
  • Answers are byte-identical: verified (2,806 questions, identical output).
  • The new unit tests cover equivalence, copies and the no-run path: verified (3 tests pass).
  • The times update changes 236 existing entries (229 faster, 7 slower), no other entry, sets none to zero and touches none of the changed files: verified against the merge base; the file conflicts with main.
  • The change is an [experimental] patch for @astryxdesign/cli: verified.

Files:

  • .changeset/how-first-ask-compiles-less.md: false lexicon count.
  • packages/cli/api/theme-edit/_how-question.mjs: clear.
  • packages/cli/api/theme-edit/theme-how-lexicon-need.test.mjs: clear.
  • scripts/vitest-node-durations.json: conflicts with main.

Automated review (maintainer link)

Comment thread scripts/vitest-node-durations.json Outdated
"packages/cli/api/theme-edit/theme-readers-joined-drops-alone.test.mjs": 3.9,
"packages/cli/api/theme-edit/theme-readers-look-request-list.test.mjs": 14.6,
"packages/cli/api/theme-edit/theme-readers-mediums-color-ground.test.mjs": 8.8,
"packages/cli/api/theme-edit/theme-readers-part-named-color.test.mjs": 69.8,

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.

This file conflicts with main: the scheduled times refresh (#13178) re-measured 9 of the entries this pull request rescales. This one is 157.5 on main, while 69.8 here is scaled from the old 73.5. Dropping the times-only commit (the refresh job re-measures) or rebasing and rescaling from main's values fixes it.

'@astryxdesign/cli': patch
---

[experimental] `astryx experimental theme editor how` answers its first question in a process about 0.8 s sooner. An ask runs every pattern in the editor's part lexicon, and the first run of a pattern compiles it, so the first ask compiled about 1,700 patterns. A pattern made from a part, group or piece name now answers at once for a text without its word, without being compiled, as its match must hold that word. Answers do not change.

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.

"about 1,700 patterns" undercounts: on this head the part lexicon holds 5,343 entries, built from 5,053 made patterns. Suggest "about 5,000 patterns", or drop the count.

@josephfarina
josephfarina force-pushed the josephfarina/how-first-ask-warm-up branch from 860af5a to 5d6c171 Compare November 21, 2026 05:34
@josephfarina
josephfarina changed the base branch from main to feature/theme-editor November 21, 2026 05:35
@josephfarina
josephfarina merged commit b0630bb into feature/theme-editor Nov 21, 2026
8 of 9 checks passed
@github-actions
github-actions Bot deleted the josephfarina/how-first-ask-warm-up branch November 21, 2026 06:04
@josephfarina

Copy link
Copy Markdown
Contributor Author

Taken out of landing #13226 because the review of the combined head flagged a line this change made. It stays on the working branch and rides the next landing together with its fix: open the fix as a new pull request (base main or the working branch) whose description names #13190.

josephfarina added a commit that referenced this pull request Nov 21, 2026
…n match (#13190)

Reviewed pull request #13190, merged into the theme working branch. It reaches main with the branch's next landing.
josephfarina added a commit that referenced this pull request Nov 21, 2026
Reviewed pull request #13248, merged into the theme working branch. It reaches main with the branch's next landing.
josephfarina added a commit that referenced this pull request Nov 21, 2026
…n match (#13190)

Reviewed pull request #13190, merged into the theme working branch. It reaches main with the branch's next landing.
josephfarina added a commit that referenced this pull request Nov 21, 2026
Reviewed pull request #13248, merged into the theme working branch. It reaches main with the branch's next landing.
josephfarina added a commit that referenced this pull request Nov 21, 2026
- #13190 perf(cli): the first how ask compiles only the lexicon patterns it can match
- #13167 how: no rounding anywhere squares the pill radius too
- #13234 set: a text size for a part with several text pieces goes to its largest
- #13248 docs(changeset): #13190's release note states no pattern count
- #13039 fix(cli): experimental theme editor - controls share one height at each size
- #13040 feat(cli): experimental theme editor - a badges setting styles the status and category badges in the theme's colors
- #13285 set: a part that holds other parts has no main text for a size
- #13260 how: no rounding anywhere reads its scope word on the corner ask alone
- #12723 experimental theme how: a mood said beside an ask is named as not used, never dropped
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed on main in #13315.

This branch was successfully deployed

1 active deployment
Preview — 5d6c1718 Deployed Nov 21, 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