Skip to content

perf(cli): theme how makes its every-word check's patterns once per lexicon - #13309

Merged
josephfarina merged 2 commits into
feature/theme-editorfrom
perf/how-gate-patterns-once
Nov 21, 2026
Merged

josephfarina merged 2 commits into
feature/theme-editorfrom
perf/how-gate-patterns-once

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

astryx experimental theme editor how checks that every word of a clause was read. Before it looks for state words, it blanks each part name out of the clause. For every clause, it made a global copy of every part pattern in the lexicon and a copy of every state-word pattern, then ran each copy through replace. A theme's lexicon does not change while it is read, so this work was the same each time.

Now the copies are made once for each lexicon and kept with it. A made pattern whose word the clause does not hold matches nothing there, so it is not run on that clause.

In user terms: how reads long questions faster, and every answer is unchanged.

Intended invariant

  • Every answer is unchanged: the same lines, notes, JSON and exit code.
  • The lists belong to one lexicon (a WeakMap keyed by it). A theme's lexicon is made for its project, so nothing carries from one theme to another. Each copy is the one globalOf or plainOf already keeps for its pattern, as the other readers of the lexicon use.
  • A kept global pattern answers as a fresh copy: replace with a global pattern starts at index 0 and leaves lastIndex at 0, and a pattern with no flags keeps no state between runs. Every state word has no flags, so its plain copy is the copy the check made before.
  • A made pattern is skipped only on a text without its word, where its own exec already answers no match.

Change

  • api/theme-edit/_how-question.mjs: gatePatternsOf(lex) lists, once for each lexicon, the global copies of its part patterns and the plain copies of the state words, taken from the copies the module already keeps for each pattern (globalOf, plainOf); blankParts(text, parts) blanks part names and skips a made pattern whose word the text lacks; the every-word check uses both.
  • api/theme-edit/theme-how-gate-patterns.test.mjs: the patterns are made once for a lexicon and apart for another; the kept patterns blank the same part names as fresh patterns on made, written, case-blind and global patterns, run twice; the state words keep their sources with no flags.
  • No record names how the every-word check runs its patterns, so no record changes.

Evidence

  • Test time of the theme editor's how test files (61 files, 1,426 tests; test seconds, three alternating runs each, this branch's base against it with this change, in one container): 411.7 / 416.7 / 409.8 s → 372.1 / 374.2 / 385.8 s, a mean of 412.7 → 377.4 s (−8.6%).
  • Where it went: in theme-how (723 tests), the every-word check took 9.2 s of the test worker's 107.5 s of CPU: 5.8 s running every part pattern through replace, and 2.8 s making the copies.
  • Answers unchanged: across the whole theme editor test folder, every call computed the blanked text both the old way and the new way and compared them, with the state-word matches: 4,896 calls (each over the lexicon's 5,343 part patterns), 0 differences.
  • Product/runtime behavior verified unchanged: the theme editor tests pass with this change (557 files, 6,063 tests, CI=1).
  • CI impact: none (no workflow, action or CI script changes).

Scope

Components: cli (experimental theme editor)

  • 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

  • vitest run --project node packages/cli/api/theme-edit (CI=1): 557 files, 6,063 tests pass.
  • vitest run --project node packages/cli/api/theme-edit/theme-how-gate-patterns.test.mjs packages/cli/api/theme-edit/theme-how-lexicon-need.test.mjs: 6 tests pass.

replay: worse 0 at c538427
preflight: pass c538427

…exicon

The every-word check of `theme editor how` blanks each part name out of a
clause before it looks for state words. For each clause, it made a global
copy of every part pattern in the lexicon (more than 5,000 for a theme) and
a copy of each state-word pattern, and ran each copy through `replace`. A
theme's lexicon does not change, so the copies are now made once for each
lexicon and kept with it (a WeakMap keyed by the lexicon). A made pattern
whose word the clause does not hold matches nothing there, so it is not run
on that clause.

A global pattern's `replace` starts from index 0 and leaves its lastIndex at
0, and a pattern with no flags keeps no state between runs, so a kept copy
answers as a fresh one. A test compares the kept patterns with fresh ones on
each text, twice.

[skip ci]
@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 1:50pm 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
🟢 Reviewed (for maintainers only) Nov 21, 2026, 2:11 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 for one fix. The rest of the change is sound: the kept copies blank the same text and find the same state words as fresh copies, the theme editor tests pass, and the gate step is much faster.

  • gatePatternsOf (packages/cli/api/theme-edit/_how-question.mjs:3112-3133) adds a second module-level cache of lexicon-pattern copies beside the module's existing globalOf and plainOf caches (:3182-3213), so please build the gate's lists from globalOf(re) and plainOf(re) and keep one copy path.
Claims and files checked

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

  • Changeset, how reads each clause faster: verified; the gate step drops from about 7 ms to about 0.2 ms per clause on a neutral-based fixture.
  • Changeset, the gate used to remake more than 5,000 part-name patterns and the state-word patterns for each clause: verified; that is 5,343 part patterns and 22 state words, rebuilt on every run at the merge base.
  • Changeset, the patterns are now made once for each theme: verified; they are made once per lexicon, and each project caches one lexicon.
  • Changeset, a part-name pattern is skipped on a clause without its word: verified at blankParts, for made patterns.
  • Changeset and description, answers do not change: verified; 1,218 clause runs show 0 differences against the old code and a plain-RegExp oracle.
  • Description, the old code copied every part pattern and state word per clause: verified; the state-word copies ran through exec, not replace.
  • Description, the lexicon does not change while it is read, and the copies are kept per lexicon in a WeakMap: verified; nothing changes lex.parts after it is built.
  • Description, a kept global copy answers like a fresh one: verified by replace semantics and by the new test's second run.
  • Description, a pattern is skipped only where its own exec already finds no match: verified against NeedRegExp.exec.
  • Description, the new test's coverage: verified in theme-how-gate-patterns.test.mjs.
  • Description, no record describes how the gate runs its patterns: verified against current records.
  • Description, the CPU profile split and the 4,896-call comparison: not reproduced; the 5,343 pattern count is verified, and an independent equivalence and timing run agrees with the claims.
  • Description, the theme editor tests pass with 557 files and 6,063 tests: verified, with the same totals.
  • Description, the two named test files pass with 6 tests, and there is no CI impact: verified.
  • .changeset/how-gate-patterns-once.md: clear.
  • packages/cli/api/theme-edit/_how-question.mjs: one finding (the second copy cache).
  • packages/cli/api/theme-edit/theme-how-gate-patterns.test.mjs: clear.

Automated review (maintainer link)

…ones

The gate's lists now hold the copies `globalOf` and `plainOf` already make
once for each lexicon pattern, so the file keeps one copy path. Every state
word has no flags, so its plain copy is the copy the gate made before.

[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 its commits skip CI, so it needs to run and pass before merge.

The earlier request is addressed: the gate's lists now come from the shared globalOf and plainOf copies, so the module keeps one copy path. The kept copies blank the same text and find the same state words as before, the theme editor tests pass, and the gate step is about 35 times faster per clause.

Claims and files checked

Review mode: incremental; reason: none

  • changed rules (0): none
  • Changeset, how reads each clause faster: verified; the gate step drops from about 7.35 ms to about 0.21 ms per clause on a neutral-based fixture.
  • Changeset, the check used to remake more than 5,000 part-name patterns and the state-word patterns for each clause: verified; 5,343 part patterns and 22 state words were copied on every run at the merge base.
  • Changeset, they are now made once for each theme: verified; the copies are made once per pattern and listed once per lexicon, and each project builds one lexicon.
  • Changeset, a part-name pattern is skipped on a clause without its word: verified in blankParts, for made patterns.
  • Changeset and description, answers do not change: verified; 1,218 clause runs show 0 differences against the old gate and a plain-RegExp oracle, and the theme editor tests pass.
  • Description, the old check copied every part pattern and state word for each clause: verified; the state-word copies ran through exec, not replace.
  • Description, the lists belong to one lexicon, kept in a WeakMap keyed by it, and the lexicon is made for its project: verified.
  • Description, each copy is the one globalOf or plainOf already keeps, as the other lexicon readers use: verified.
  • Description, a kept global pattern answers as a fresh copy, and every state word has no flags: verified, including with lastIndex left set on every shared copy.
  • Description, a made pattern is skipped only on a text without its word, where its own exec finds no match: verified.
  • Description, the new test's coverage: verified in theme-how-gate-patterns.test.mjs; the state-word test expects the flags without g, which is no flags for every state word.
  • Description, no record describes how the check runs its patterns: verified against current records.
  • Description, the CPU profile split and the 4,896-call comparison: not reproduced; the 5,343 pattern count is verified, and an independent equivalence and timing run agrees.
  • Description, the theme editor tests pass with 557 files and 6,063 tests: verified, with the same totals.
  • Description, the two named test files pass with 6 tests, no public API or product change, and no CI impact: verified.
  • .changeset/how-gate-patterns-once.md: clear.
  • packages/cli/api/theme-edit/_how-question.mjs: clear; the earlier copy-cache finding is fixed.
  • packages/cli/api/theme-edit/theme-how-gate-patterns.test.mjs: clear.

Automated review (maintainer link)

@josephfarina
josephfarina marked this pull request as ready for review November 21, 2026 14:56
@josephfarina
josephfarina merged commit c58321c into feature/theme-editor Nov 21, 2026
7 checks passed
josephfarina added a commit that referenced this pull request Nov 21, 2026
…exicon (#13309)

Reviewed pull request #13309, 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
…exicon (#13309)

Reviewed pull request #13309, 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
- #13284 experimental theme: the newer-recipe release note agrees with the kept-palette one
- #13159 fix(cli): experimental theme editor - rounder corners never make the chat corners less round
- #13243 set: a text size token a part never reads goes into the one its held parts read
- #13299 experimental theme: text in a see-through region is measured over the region as drawn
- #12772 experimental theme how: a label that names the spacing or corners setting reads its value as that setting's; sans after a kind of typeface is the typeface
- #12773 experimental theme how: a contradiction holds back only its own pair; a decimal is one value; a color for the whole theme takes its role
- #13309 perf(cli): theme how makes its every-word check's patterns once per lexicon
- #13224 fix(cli): experimental theme editor - a group height narrowed off one control stays a control height show lists
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed on main in #13377.

@github-actions
github-actions Bot deleted the perf/how-gate-patterns-once branch November 22, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — c5384278 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