Repository navigation
Studio: optimize startup by deferring fine-tuning actions - #8624
Conversation
… the bundle The new test read one file, so a static import of finetune-recipe added to any other eagerly reached module would put the whole Recipe Studio chunk back into startup with the assertion still green. It now walks src/ and fails on a static import anywhere, ignoring the deferred import() forms this PR introduces. Verified against a negative control: re-adding a static import to settings-section.tsx fails the test. The second comment was also inaccurate. unsloth_training_config_v1 is in the eager bundle on both sides, because __root.tsx and app-sidebar.tsx import the @/features/training barrel that re-exports the training config store and datasets-api, both of which finetune-recipe also pulls. What leaves is Recipe Studio, which is where the whole 575 KB comes from, so the first comment is right and this one would have sent the next person auditing startup looking for something that is not there.
|
Thanks, this one checks out. I verified it by building the bundles rather than reading the diff: I also built this together with #8623: -934 KB and -575 KB alone, -1,509 KB merged, exactly the sum. Disjoint module sets, no shared files, both merge clean into current Pushed The new test held one file rather than the property. A static import of The second comment is inaccurate. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e466c9df8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!/finetune-recipe/.test(line)) continue; | ||
| if (/\bimport\s*\(/.test(line)) continue; | ||
| if (/^\s*(import|export)\b/.test(line)) { |
There was a problem hiding this comment.
Parse multi-line imports before declaring the graph clean
When another source file uses a normally formatted multi-line static import such as the one removed from data-tab.tsx, the finetune-recipe path appears on a } from ... line rather than a line beginning with import or export. This loop therefore skips it and the test passes even though that import can restore the workflow to the eager bundle. Match complete import declarations or parse each file's import graph instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, and it was a live hole rather than a theoretical one: the import this PR removes from data-tab.tsx is exactly the four-line shape, so the check could not have caught the regression it exists to prevent.
Fixed in 42624b684 by parsing instead of scanning. The test now builds a ts.SourceFile per file under src/ and collects the moduleSpecifier of every ImportDeclaration and ExportDeclaration, which is the edge set that actually fixes bundle membership. A deferred import(...) parses as a call expression, not a declaration, so the pattern this PR adopts stays allowed.
Proved both directions rather than assuming:
- multi-line static import injected into
settings-row.tsx(eagerly reached, and deliberately notdata-tab.tsxsince the first assertion would have caught that by another route): old line-based check passes 2/2, new check fails withfeatures/settings/components/settings-row.tsx: ../components/finetune-recipe - the same import collapsed to one line: old check now fails too, which isolates the gap to line spanning and nothing else
- injection removed: 2/2 green
- all three dynamic forms injected at once (single-line, multi-line, bare non-awaited): 2/2 green, so the deferral pattern is not flagged
export * from "./finetune-recipe"and a nesteddeclare modulevariant both fail, covering theExportDeclarationarm and proving the recursion is live
Cost is 1.9s for the file, 608ms of which is parsing all 1138 sources. Suite 2009/2009, typecheck clean.
The repo-wide check walked each file line by line and keyed the match off the line beginning with `import`, so a multi-line import left its specifier on the closing `} from "..."` line and was skipped. That is exactly the shape of the static import removed from data-tab.tsx, so the regression this test exists to catch would have gone through green. Collect module specifiers from the TypeScript AST instead. Import and export declarations carry a moduleSpecifier, while a deferred `import(...)` parses as a call expression and is never collected, so the pattern the two actions now use stays allowed. Parsing all 1138 source files costs about 0.6s.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 42624b684b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for await (const file of walk(SRC)) { | ||
| const text = await readFile(file, "utf8"); | ||
| for (const specifier of staticSpecifiers(file, text)) { | ||
| if (RECIPE_MODULE.test(specifier)) | ||
| offenders.push(`${path.relative(SRC, file)}: ${specifier}`); |
There was a problem hiding this comment.
Limit the startup guard to eagerly reachable modules
When a lazy route or another action-scoped chunk statically imports this helper, the workflow remains deferred, but this repo-wide loop still reports it as part of startup because it examines every source file without tracing reachability from the eager entry points. This creates a false test failure for valid lazy-chunk reuse; restrict the check to the eager import graph or validate the generated bundle manifest instead.
Useful? React with 👍 / 👎.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Every Studio page load currently pulls fine-tuning workflow code into the initial frontend bundle because the Settings Data tab imports it eagerly. This loads Recipe Studio database and UI code plus training helpers even when the user never opens Settings or uses either fine-tuning action.
What changed
Results
Measurements are medians from 10 interleaved fresh Chromium contexts against production builds with the browser cache disabled.
A live browser run also confirmed that running Open in Recipes fetched the deferred fine-tuning and Recipe Studio chunks and continued into the existing chat export flow.
Testing
npm test(2,008 passed)npm run typechecknpm run buildgit diff --check