Repository navigation
perf(cli): theme how makes its every-word check's patterns once per lexicon - #13309
Conversation
…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]
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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 existingglobalOfandplainOfcaches (:3182-3213), so please build the gate's lists fromglobalOf(re)andplainOf(re)and keep one copy path.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Changeset,
howreads 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, notreplace. - Description, the lexicon does not change while it is read, and the copies are kept per lexicon in a WeakMap: verified; nothing changes
lex.partsafter it is built. - Description, a kept global copy answers like a fresh one: verified by
replacesemantics and by the new test's second run. - Description, a pattern is skipped only where its own
execalready finds no match: verified againstNeedRegExp.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.
…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]
There was a problem hiding this comment.
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,
howreads 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, notreplace. - 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
globalOforplainOfalready 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
lastIndexleft set on every shared copy. - Description, a made pattern is skipped only on a text without its word, where its own
execfinds no match: verified. - Description, the new test's coverage: verified in
theme-how-gate-patterns.test.mjs; the state-word test expects the flags withoutg, 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.
- #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
|
Landed on main in #13377. |
Maintainer impact
astryx experimental theme editor howchecks 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 throughreplace. 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:
howreads long questions faster, and every answer is unchanged.Intended invariant
globalOforplainOfalready keeps for its pattern, as the other readers of the lexicon use.replacewith a global pattern starts at index 0 and leaveslastIndexat 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.execalready 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.Evidence
howtest 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%).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 throughreplace, and 2.8 s making the copies.Scope
Components: cli (experimental theme editor)
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