Repository navigation
perf(cli): the first how ask compiles only the lexicon patterns it can match - #13190
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
…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.
There was a problem hiding this comment.
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.jsonconflicts with the refreshed record now onmain(19 hunks), and 9 of the 236 entries here are rescaled from valuesmainhas since re-measured (for exampletheme-readers-part-named-color.test.mjsis 157.5 onmainand 69.8 here), so drop the times-only commit and let the scheduled refresh re-measure, or rebase and rescale those entries frommain'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
needingcall sites andmayMatch). - Such a pattern is now a
NeedRegExpwhoseexecreturnsnullfor a text without its word, without running or compiling: verified (NeedRegExp.exec; the new unit test spies on the built-inexec). test,match,matchAll,replace,searchandsplitall go throughexec: verified (unit test across three flag sets).- Copies keep the word through
lexCopyandlexAround, 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 plainnew 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 withmain.
| "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, |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
"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.
860af5a to
5d6c171
Compare
Reviewed pull request #13248, merged into the theme working branch. It reaches main with the branch's next landing.
Reviewed pull request #13248, merged into the theme working branch. It reaches main with the branch's next landing.
- #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
|
Landed on main in #13315. |
Why
astryx experimental theme editor howruns 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 askshow, 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, aRegExpwhoseexecreturnsnullat once for a text without its word, without running or compiling the pattern.test,match,matchAll,replace,searchandsplitall go throughexec, so every call site that runs a lexicon pattern gets the same skip without changing.gcopy, a pattern built around it) keep the word:lexCopyandlexAroundreplacenew RegExp(re.source, …)at those sites.Evidence
howanswer from the how and asks test files was dumped before and after, with 0 differences (1,949 calls on the current main).theme-how-lexicon-need.test.mjs):RegExp.prototype.exec.Times-only record update, on top of the refreshed record:
scripts/vitest-node-durations.jsonupdates 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.mjspreflight: pass 5d6c171