Repository navigation
perf(cli): the first theme build after a CLI upgrade reuses the JavaScript it compiled from a theme's local modules - #12658
josephfarina wants to merge 4 commits into
Conversation
…cript it compiled from a theme's local modules
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
…ile stamps the CLI's own files; name the browserslist fix
There was a problem hiding this comment.
Approval waits on an engineering owner deciding the spec:AST-081 FR7 change. The pull request adds three sentences to FR7 that exempt the kept theme-module JavaScript from the rule that the CLI's build id and folder stand for its own files. It also changes theme build so that an invalid browserslist setting in the project no longer fails the compile, and no current record covers that. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request (the author may do so as an engineering owner), or says how FR7 should read instead.
These text fixes are needed either way:
- The changeset says a project's browserslist setting "no longer affects or breaks" the compile, but only an invalid setting ever broke it and a valid one never changed the output, so please write "An invalid browserslist setting in the project no longer makes that compile fail."
- The Scope checklist marks "no intended product behavior or policy change" and "product changes discovered during the work were removed or split", but the pull request changes an error path and the FR7 kept-value rule, so please uncheck those boxes or split the browserslist option into its own pull request.
- The writing-rubric result says the record changes by one sentence, but FR7 gains three sentences.
Non-blocking: the proposed FR7 text could also say that the entry no longer depends on the CLI's folder, and that its key names the Babel file the CLI loads, so the record matches the code.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim: the first build after an upgrade that leaves the compiling code and Babel's files unchanged reads the kept JavaScript back without loading Babel. Verified: the upgrade test row passes on the head and fails on the base.
- Claim: the first build is about 0.15–0.4 s faster. Not re-measured; this is the author's measurement.
- Claim: the browserslist setting no longer affects or breaks the compile. Partly false: "breaks" is verified (an invalid query throws on the base), but a valid setting never changed the output.
- Claim: every other answer is unchanged. Verified: only the compile entry opts in, and the built theme files are identical on base and head.
- Claim: the compiled JavaScript is the only kept value independent of the build id and folder. Verified in
self-contained.mjsandgather-cache.mjs. - Claim: the key names the source, the options, the rewrites, the compiling module's content and the Babel and plugin files. Verified in
self-contained.mjs. - Claim: reuse needs Babel's file stamps and lookup folders unchanged, and nothing is kept if they changed during the run. Verified in
loaded-files.mjsand by the existing reinstall rows. - Claim: a Babel reinstall or change, Babel found elsewhere, or a change to the compiling module compiles again. Verified: the upgrade-change row passes, and it fails when the module hash is left out of the key.
- Claim: the browserslist option is safe because neither plugin reads targets, and an invalid query failed before. Verified by the plugin sources and by removing the option.
- Claim: no CLI file is among the stamps. Verified by its test row.
- Claim: no CI changes. Verified from the changed-file list.
- Claim: the Scope checklist says there is no product behavior or policy change. False.
- Claim: the record changes by one sentence. False: there are three.
- File
.changeset/theme-compile-kept-across-upgrades.md: wording finding. - File
docs/specs/AST-081-global-mode/spec.md: waits on an owner decision. - File
packages/cli/api/theme/build/self-contained.mjs: clear. - File
packages/cli/api/theme/build/self-contained.kept.test.mjs: clear (the added.browserslistrccannot fail its row). - File
packages/cli/foundation/fs/gather-cache.mjs: clear. - File
packages/cli/foundation/fs/loaded-files.mjs: clear. - File
packages/cli/foundation/runtime/lazy-dependencies.mjs: clear.
…n the key, Babel's file named; changeset names only the invalid-setting fix
|
Owner decision (engineering owner, covering this pull request): the first theme build after a CLI upgrade reuses the JavaScript it compiled from a theme's local TS or JSX module when nothing that changes that output has changed: the module's source, the compile options, the import rewrites, the compiling code and Babel. The theme source, the files it imports and Core are still read fresh on every build. |
|
/approve-spec d906175 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, since the pull request is a draft.
The spec:AST-081 FR7 sentences and the browserslist fix now carry an engineering owner's approval for this head. The three text fixes from the last review are in.
Non-blocking, for a follow-up if you like:
- Miss: the
acrossBuildsdoc comment ingather-cache.mjssays the entry is "kept for every build of the CLI in its folder", but the key no longer names the folder; "wherever it runs from" would match the code and FR7. - Miss: the test row that checks no kept compile stamps the CLI's own files skips every path under
node_modules, so it also passes withfromLookups: true; asserting that no stamp names a folder under the CLI's ownnode_moduleswould guard the new option.
Claims and files checked
Review mode: full; reason: spec-record
- Claim (changeset): after an upgrade that leaves the compiling code and Babel's files alone, the first build reads the kept JavaScript back without loading Babel. Verified: the upgrade test row passes on the head and fails on the base code.
- Claim (changeset): that first build is about 0.15–0.3 s faster, about 0.4 s with an empty compile cache. Not re-measured; the author's measurement.
- Claim (changeset): an invalid project browserslist setting no longer fails the compile. Verified: the theme build exits 1 on the base and 0 on the head, and the new test row fails without the option.
- Claim (changeset): every other answer is unchanged. Verified: only the compile entry opts in, and the seven published themes build identical files.
- Claim: the kept JavaScript was discarded by every upgrade because its key held the build id. Verified in the base key code.
- Claim: an upgrade made the build load 240–580 Babel modules. Not re-measured.
- Claim: only an invalid browserslist setting changes the outcome, and a valid one never changed the output. Verified: the base with an
ie 11setting writes the same files as the head. - Claim: the compiled JavaScript is the one kept value tied to neither the build id nor the CLI's folder, keyed by source, options, rewrites, the compiling module's content and the Babel and plugin files. Verified in
self-contained.mjsandgather-cache.mjs. - Claim: reuse needs Babel's file stamps and lookup folders unchanged, and nothing is kept if they changed during the run. Verified in
loaded-files.mjsand by the reinstall rows. - Claim: a Babel reinstall or change, Babel found elsewhere, or a change to the compiling module compiles again. Verified: the upgrade-change row passes and fails when the module hash leaves the key.
- Claim: every other kept entry still depends on the build id and folder. Verified: only the compile passes the new option.
- Claim: the new
persistedSummaryoption,codeDigest, the lookup-folder option andbabelCorePathwork as described. Verified by reading the code. - Claim: the browserslist option is safe because neither plugin reads targets. Verified by identical output; the 4 ms figure was not re-measured.
- Claim: no kept compile stamps a file of the CLI's own. Verified by its test row, which skips
node_modulespaths (see above). - Claim: FR7 gains three sentences naming the value, its inputs and its rule. Verified; owner-approved for this head.
- Claim: the listed test rows exist and pass. Verified; the upgrade and browserslist rows fail on the base code.
- Claim: reused JavaScript gives byte-identical builds. Verified for the seven published themes; the timing tables were not re-measured.
- Claim: shipped themes carry an icon registry. Verified: every published theme here has one.
- Claim: the Scope boxes are unchecked for the FR7 rule and the error-path change. Accurate.
- Claim: the strict type check and ESLint on the changed files pass. Verified; the full 90-file test run was not repeated, and the seven suites run here pass.
- Claim: no CI impact. Verified: no workflow, action or CI script changes.
- File
.changeset/theme-compile-kept-across-upgrades.md: clear. - File
docs/specs/AST-081-global-mode/spec.md: clear (owner-approved). - File
packages/cli/api/theme/build/self-contained.mjs: clear. - File
packages/cli/api/theme/build/self-contained.kept.test.mjs: clear, with the non-blocking test note above. - File
packages/cli/foundation/fs/gather-cache.mjs: clear, with the non-blocking comment note above. - File
packages/cli/foundation/fs/loaded-files.mjs: clear. - File
packages/cli/foundation/runtime/lazy-dependencies.mjs: clear.
| * summary that holds more only once a caller asks for it); `keep`: whether | ||
| * a value just made is stored at all (a failed or partial answer is not). | ||
| * a value just made is stored at all (a failed or partial answer is not); | ||
| * `acrossBuilds`: kept for every build of the CLI in its folder, for a |
There was a problem hiding this comment.
Non-blocking: "kept for every build of the CLI in its folder" reads as if the entry stays tied to the CLI's folder, but entryKey drops the folder for an across-builds summary (line 643), as FR7 now says. Maybe "kept for every build of the CLI, wherever it runs from".
| .filter( | ||
| (/** @type {string} */ file) => | ||
| file.startsWith(CLI_SOURCE + path.sep) && | ||
| !file.includes(`${path.sep}node_modules${path.sep}`), |
There was a problem hiding this comment.
Non-blocking: this filter skips every path under node_modules, so the row also passes with fromLookups: true (the CLI's own lookup folder for @babel/core sits under the CLI's node_modules). Asserting that no stamp names a folder under the CLI's own node_modules would guard the new option.
josephfarina
left a comment
There was a problem hiding this comment.
Review of the theme-module compile kept across CLI builds, from the side of self-contained.mjs (head d906175).
Verdict: good to ship.
Key. I checked every input that shapes the compiled bytes:
- the source, the compile options and the import rewrites;
- the plugin paths, which ride in the options (absolute paths, resolved by the theme adapter);
- the plugin options, which
compileOptionswrites in this module, so the module's content hash covers them; rewriteImports, which lives in this module too, soString(rewriteImports)is now redundant but harmless;- the Babel environment name;
babelCorePath(), which resolves through the samerequirethatbabelCore()loads with, so the key names the Babel that actually runs.
Leaving out this module's own lookups across builds is sound, because the key names the files those lookups reach. Babel's own transitive lookups stay stamped.
Stamps. A kept compile is checked against the full stamp of every Babel file: size, modification time, change time and inode. A reinstall that writes the same sizes and dates still changes the change time and inode, so it misses.
browserslistConfigFile: false. Neither the TypeScript plugin nor the JSX plugin reads targets, so the output bytes are unchanged. The one changed answer is an error path: an invalid browserslist query in the project used to make the compile fail, and now it compiles. The changeset says so, and a test row covers it.
Tests checked on Node 24:
- At this head, all 12 rows in
self-contained.kept.test.mjspass. - With the four source files reverted to the base and the new tests kept, the two rows for the new behavior fail: "read back after a CLI upgrade" and "the same bytes whatever browserslist setting". The guard rows pass on the base, as expected, because the base never reuses across builds.
- Mutation checks at this head:
- dropping the module's content hash from the key fails the "compiles again after an upgrade" row on its compiling-module case;
- dropping the Babel entry path fails it on its other-copy case;
- removing the browserslist option fails the browserslist row;
- making the fixed-date rewrite keep the change time and inode fails the fixed-date case. So that case depends on the full stamp, as intended.
No change requested.
|
/approve-spec 8a0fa64 |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet, since its runs here were skipped.
The spec:AST-081 FR7 sentences carry an engineering owner's approval for this head, and the newest commit only rewords the changeset, accurately. The two earlier non-blocking inline notes still apply: the acrossBuilds doc wording in gather-cache.mjs, and the test row that does not guard fromLookups: false.
Claims and files checked
Review mode: incremental; reason: none
- Claim (changeset): after an upgrade that leaves the compiling code and Babel's files alone, the first theme build reads the kept JavaScript back without loading the Babel compiler. Verified: the upgrade test row passes at this head and fails on the base code.
- Claim (changeset): that first build is about 0.15–0.3 s faster, about 0.4 s with an empty compile cache. Not re-measured; the author's measurement.
- Claim (changeset): an invalid project browserslist setting no longer fails the compile. Verified: the theme build exits 1 on the base and 0 at this head, and the new test row fails on the base code.
- Claim (changeset): every other answer is unchanged. Verified: only the compile entry opts in, and the seven published themes build identical files.
- Claim: the kept JavaScript was discarded by every upgrade because its key held the build id. Verified in the base key code.
- Claim: the first build after an upgrade loaded 240–580 Babel modules. Not re-measured.
- Claim: one error path changes (an invalid browserslist setting from a config file, a
package.jsonkey or the environment), and a valid setting never changed the output. Verified: the option turns off Babel's browserslist lookup, and the base with anie 11setting writes the same files as this head. - Claim: the compiled JavaScript is the one kept value tied to neither the build id nor the CLI's folder, keyed by source, options, rewrites, the compiling module's content and the Babel and plugin files. Verified in
self-contained.mjsandgather-cache.mjs. - Claim: reuse needs every Babel file's size, modification time, change time and inode and every lookup folder unchanged, and nothing is kept if they changed during the run. Verified in
loaded-files.mjsand by the reinstall rows. - Claim: a Babel reinstall or change, Babel found elsewhere, or a change to the compiling module compiles again, and every other kept entry still depends on the build id and folder. Verified: the upgrade-change row passes, and only the compile passes the new option.
- Claim: the new
persistedSummaryoption,codeDigest, the lookup-folder option andbabelCorePathwork as described. Verified by reading the code. - Claim: the browserslist option is safe because neither plugin reads targets, and it removes a lookup of about 4 ms. Output identity verified; the 4 ms figure was not re-measured.
- Claim: no CLI file is loaded during a compile, so none is stamped. Verified by its test row, which skips
node_modulespaths (see the inline note). - Claim: FR7 gains three sentences naming the value, its inputs and its rule. Verified; owner-approved for this head.
- Claim: the listed test rows exist and pass, and the new-behaviour rows fail on the base. Verified: 12 of 12 pass at this head; the upgrade and browserslist rows fail on the base code.
- Claim: reused JavaScript gives byte-identical builds, with the timing tables. Byte identity verified for the seven published themes; the timing tables were not re-measured.
- Claim: shipped themes carry an icon registry. Verified: every published theme here has one.
- Claim: the Scope boxes are unchecked for the FR7 rule and the error-path change, and the rubric reports three sentences. Accurate.
- Claim: the strict type check, ESLint and the listed suites pass. Verified: the strict type check, ESLint on the changed files and the kept and lazy-dependency suites pass, and the file-system suites match the base; the full 90-file run was not repeated.
- Claim: no CI impact. Verified: no workflow, action or CI script changes.
- File
.changeset/theme-compile-kept-across-upgrades.md: clear. - File
docs/specs/AST-081-global-mode/spec.md: clear (owner-approved). - File
packages/cli/api/theme/build/self-contained.mjs: clear. - File
packages/cli/api/theme/build/self-contained.kept.test.mjs: clear, with the non-blocking test note. - File
packages/cli/foundation/fs/gather-cache.mjs: clear, with the non-blocking comment note. - File
packages/cli/foundation/fs/loaded-files.mjs: clear. - File
packages/cli/foundation/runtime/lazy-dependencies.mjs: clear.
- #12072 fix(templates): payment form and checkout wrap the summary below the form on a narrow first paint Author: Joey Farina <[email protected]> - #12274 fix(core): cap the Selector family's trigger-width list minimum at the viewport Author: josephfarina <[email protected]> - #12215 fix(cli): advise keeping one dependency when two packages declare one provider ID Author: Joey <[email protected]> - #12322 [experimental] export --reverse: use the project's own copy of an aliased file, or restore the page's copy with its paths entry Author: josephfarina <[email protected]> - #12403 docs(core): Text's as and PowerSearch's statusVariant list every value their types allow Author: Joey Farina <[email protected]> - #12494 fix(templates): dashboard templates use page sections, not cards, for page regions Author: Joey Farina <[email protected]> - #12282 fix(cli): theme build --check and doctor ignore which CLI release, and which command name, built a theme Author: Joey Farina <[email protected]> - #12420 fix(Chat): ChatToolCalls and ChatDictationButton without a required prop name it and the fix in development Author: Joey Farina <[email protected]> - #12205 fix(cli): equally scored icons put first one whose id the query names in full Author: Joey Farina <[email protected]> - #12455 fix(core): a theme sets the room between a checkbox or a switch and its label Author: josephfarina <[email protected]> - #12658 perf(cli): the first theme build after a CLI upgrade reuses the JavaScript it compiled from a theme's local modules Author: Joey <[email protected]> - #12323 [experimental] export: React logs no render timings while the export draws a page Author: Joey Farina <[email protected]>
|
Landed in #12713. |
Maintainer impact
A theme with local TypeScript or JSX modules (an icon registry, as both shipped Meta themes have) makes
theme buildcompile them with Babel. The JavaScript is kept between runs, but under the CLI's build id, so every CLI upgrade discarded it. The first theme build after each upgrade then loaded Babel (240 to 580 modules) and compiled again, even when Babel and the theme had not changed.In user terms: the first theme build after a CLI upgrade is about 0.15–0.3 s faster when the upgrade leaves Babel's installed packages as they were (about 0.4 s when Node's compile cache is also empty).
Intended invariant
.browserslistrc, abrowserslistkey inpackage.json, orBROWSERSLIST) made the compile of a theme's local module fail, since Babel read that setting on every compile; it now compiles, and a valid setting never changed the output.Change
foundation/fs/gather-cache.mjs:persistedSummarytakesacrossBuilds. Such an entry's name and key hold a fixed marker in place of the build id and the CLI's folder, and it keeps the stamps of the CLI's own files too. OnlycompileModuleuses it.foundation/fs/loaded-files.mjs:codeDigest(file), a code file's content as a hash;loadedCodeStampscan leave out the folders the caller's own lookups took, for an answer whose key names the files they resolve to.foundation/runtime/lazy-dependencies.mjs:babelCorePath(), the filebabelCore()loads.api/theme/build/self-contained.mjs: the key adds the compiling module's content and the file the CLI loads Babel from (the plugin files are already in the options), and the entry is kept across builds. The compile also setsbrowserslistConfigFile: false. It already read no project Babel config (babelrc: false,configFile: false), and neither plugin it uses reads browserslist targets, so a valid setting never changed the output: with a.browserslistrcofie 11in the project, the compiled JavaScript is byte-identical with or without the option. Without the option, Babel still looked the setting up on every compile, which failed on an invalid query; with it, nothing of the project's is read, for any later plugin too, and the lookup (about 4 ms) is gone.docs/specs/AST-081-global-mode/spec.md: FR7's kept-catalogs bullet names this one value, that it depends on neither the build id nor the CLI's folder, what its key names (the Babel and plugin files the CLI loads among them), and the rule that keeps it exact.api/theme/build/self-contained.kept.test.mjs:.browserslistrcbeside the theme;Evidence
npm i/pnpm addof the second pack. Arm "kept" is the user cache the first pack left; arm "dropped" is the same cache with the kept compiled modules removed (11 interleaved pairs, Node's compile cache warm, output byte-identical in every pair):--jsonoutput are byte-identical between the two:icons.tsx)icons.tsx.jsincluded: identicalexperimental theme editor new brand)When an upgrade does change Babel, it compiles again, as it must. In one pnpm run the upgrade re-resolved
@babel/parserand@babel/typesto newer patch releases under the same@babel/core: Babel's lookup stamps changed and the build compiled again. In another run, packs that differed in the compiling module made every upgrade compile again. A global reinstall writes Babel's files again (new change times and inodes), so it compiles again too.With Node's compile cache also empty, as on the first run after an install that replaces the CLI's files, an earlier measurement of the same reuse saved about 0.4 s (−415 ms median, 11 runs).
Product/runtime behavior verified unchanged: every battery command's output, error output and exit code matched before and after, in a Core-only project and in a project with an integration, including real theme builds. Warm runs are unchanged (weighted −0.1% and +0.2%; the two real theme builds +1 and +3 ms, both intervals across 0), and so is a first theme build on a fresh cache (−7 ms [−20, +17]).
CI impact: none (no workflow, action or CI script changes).
Writing rubric results
The record gains three sentences in
spec:AST-081FR7's kept-catalogs bullet.Scope
Components: cli (theme build, kept catalogs)
spec:AST-081FR7 rule for kept values gains one exempt value (the record change above), and one error path changes (an invalid browserslist setting in the project no longer makes the theme-module compile fail).Testing
self-contained.kept, the theme build suites,foundation/fs,foundation/runtime, render, doctor, the lazy-dependency check, the installed, fresh, changes and records packed kept-catalog files and the theme build transpile-cache test pass (90 files, 1,631 tests). After the review round,self-contained.keptpasses with its two new rows (12 tests).