Repository navigation
perf(compiler): skip parsing modules the Vite plugin only passes through - #1852
Merged
Merged
Conversation
Nitro rebundles the SSR build's chunks from node_modules/.nitro through Octane's Vite plugin. The plugin's preflight parsed every module in full before checking ownership. The compiler then attributed the chunks to the application package.json by walking up past node_modules. Code samples in the chunks' strings also matched the hook-import text gate, so slotHooks parsed them a second time and returned them unchanged. - Stop the nearest-manifest walk at a node_modules directory, as Node's package scope lookup does. Build caches no longer inherit the app manifest. - Preflight parses only when compilation, hook slotting, or a virtual barrel's descriptor re-exports can read a fact. The decision comes from a parse-free compiler scope that shares transform's slot gates. - Read a plain JavaScript module's server import requests with the module lexer instead of a full parse. Website production build, local: Nitro phase 2m 50s -> 0.5s. All 967 emitted files keep their hashes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 7, 2026 17:25
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | 1773cd8 | Commit Preview URL Branch Preview URL |
Oct 07 2026, 05:31 PM |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | 1773cd8 | Commit Preview URL Branch Preview URL |
Oct 07 2026, 05:33 PM |
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 60 measured values. Public-import reachability bundles (bytes)No changes across 108 measured values. |
trueadm
added a commit
that referenced
this pull request
Oct 7, 2026
Conflicts: app-budgets.json and minimal-budgets.json, where #1854 and #1855 lowered the rows this branch had tightened. Take main's values, then write this branch's measurements (`--write-budgets`) on the merged tree, which only lowers: bindings app gzip and total raw, one app brotli, and three minimal gzip rows. hydrate-frame stays at main's 364,882 raw. It measures 364,886 here and on main alike, and main's own CI fails the same check, so the raise belongs in a budget-only change on main, not in this PR. #1852 stops the Vite plugin parsing modules it only passes through, such as the SSR chunks Nitro re-bundles. The @tsrx/core patch still bounds every module the plugin does compile, so its guard now transforms a 540 kB project module that uses a hook instead of a Nitro chunk: about 2 s patched, 20 s unpatched, against a 6 s bound. The patch note says so. Reformat main's new hydrate-frame fixture; its output is unchanged once position-derived ids are masked. main's changed test files pass on this branch (bundler-compiler, compiler-vite-options, behavior-root, binding-handoff, style-transaction-rollback). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Nitro (TanStack Start) rebundles the SSR build's own chunks from
node_modules/.nitro/vite/services/ssr/assets/*.js, and Octane's Vite plugin runs over each one again. Onmain, each big chunk was parsed twice by@tsrx/coreparseModule, whose comment attachment is quadratic. Both parses were wasted:vite.jspreflightForparsed every module in full, then derived facts that only compiled modules, hook-slotted modules, or virtual barrels can read._isInstalledOctaneSourcewalked fromwebsite/node_modules/.nitro/…/docs-*.jsup pastnode_modulestowebsite/package.json, which declaresoctane. The plain-module text gate/from\s*['"]octane['"]/matched code samples inside the chunk's strings, soslotHooksparsed the 5 MB chunk again and returned it unchanged.This PR removes both parses in Octane itself. The
@tsrx/coreparser patch in #1399 is apatchedDependenciesentry, and patches don't ship in the published tarball, so without this change Octane + TanStack Start + Nitro apps keep paying the cost. #1399's patch is not touched.Changes
Ownership boundary (
bundler.js_nearestOctanePackageRule). The nearest-manifest walk now stops at anode_modulesdirectory. A file that reaches one without its own manifest belongs to no package. Node's package scope lookup (getPackageScopeConfig) draws the same boundary. It covers.vite,.nitro, and.cachebuild caches, and loose files innode_modules. Real installed packages are unaffected because their own manifest sits below the boundary, and so are linked or symlinked packages, which resolve to real paths.Parse-free preflight scope (
bundler.js_preflightScope/_mayHookSlot). The compiler classifies a module without parsing it:compile: a full-compile source. Preflight collects every fact, as today.slots: a plain.ts/.jsmodule that passestransform's parse-free slot gates. Preflight collects void imports only.none: everything else.transform's plain-module branch now calls the same_mayHookSlot, so the two can't drift.Preflight parses only when a fact needs the AST (
vite.js). These facts can't arise for a module the compiler won't compile:_isFullCompileSource)preparedDescriptorChildrenExports)null!existsSyncfilter only for a module absent from disk.js/.tsvirtual barrels still publishDESCRIPTOR_CHILDREN_EXPORTS_METAslotHooksslotsassertNoLiveClientOnlyImports)Server import requests without a parse (
findServerImportRequests+runtime-requests.js). For.js/.mjs/.cjs, the requests come fromes-module-lexer, which Octane already uses for runtime-request targeting. When the lexer rejects a module, for example JSX in.js, the parse path runs as before..tskeeps the parse because of type-only imports.Measurements
All measurements are local on an Apple M5 Max (load average around 6–7, other sessions running), with
@tsrx/core0.4.0 as on main.Website production build (
pnpm --filter website build, fresh worktree,main83eaaf4 vs this branch):Semantic control: all 967 emitted files in the client, SSR, and Nitro phases have identical hashed names and sizes in both build logs. The SSR chunks under
node_modules/.nitro/vite/services/ssrare byte-identical (diff -rq).Plugin transform on the 304 real Nitro-phase chunks. Same harness, server environment, website config with
threeRenderers, main'ssrcextracted withgit archive:Every chunk's result is a
nullpass-through in both trees. Before this PR, the docs time split as 44.7 sparseModulein preflight plus 49.0 s incompiler.transform(slotHooks). Benchmarks was 78 s of preflight parse.Lexer vs. parser differential.
es-module-lexerstatic requests (d === -1) were compared withfindStaticRuntimeImportRequests:.js/.mjsfiles fromnode_modules/.pnpm: 0 under-reports. The 4 over-reports are Flowimport typelines in@emotion/*/src, which the client-only live-use check already skips.Validation
--project octane:compiler/bundler-compiler.test.tsandcompiler/compiler-vite-options.test.ts: 108 passedvite-void-import-cycles,external-hook-slot,manual-state-getters,vite-text-types, andcompiler/renderer-boundary-analysis: 61 passeddoes not attribute a node_modules build cache to the package that installed itfails with the boundary disabled (client: expected 'slots' to be 'none').checks a rebundled server chunk's imports, not the code samples in its stringsfails if the lexer path returns no requests, and fails if it is replaced by a regex scan that reads strings (it then resolves./Leak.object.tsrxandoctane). It passes on main, because it pins behavior this change preserves.slotsfails 4vite-void-import-cyclesreal-build tests.carries descriptor-children export metadata through the Vite module graph.prettier --writeon the changed files (no changes);pnpm sync(no generated changes);react-parity/check.mjs --validate-only(current)pnpm format:check,pnpm typecheck,pnpm test: left to CI, per the local test-load rule.typecheck:fileson the touched test files reports only its known tsgo selection artifacts on existing lines, none on changed lines.Risk / follow-ups
.jsmodule that@tsrx/corecannot parse but the lexer can read, such as the website's playground chunk. On main it got no server import requests, so the client-only check was skipped silently. Now its static imports are classified. If one of them resolved to a client-only module, the live-use check would report a parse error instead of passing silently. No website module hits this..ts/.jsfile with Octane code samples in strings still passes the regex gate and gets parsed byslotHooks. This PR only fixes ownership for build caches. Making that gate lexical is separate work, because it decides which modules reach slotting.findServerImportRequestscan over-report Flowimport typerequests, at the cost of one extra resolve each. The live-use check ignores type imports.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches compiler ownership boundaries, preflight gating, and server client-only import discovery; behavior changes for edge cases (e.g. lexer-readable but parser-failing
.jsmodules) though outputs are intended to stay hash-identical.Overview
Speeds up Octane’s Vite/Nitro path by not fully parsing modules that only pass through, and by fixing wrong package ownership for rebundled SSR chunks under
node_modules/.nitro(and similar caches).Package scope stops at a bare
node_modulesdirectory when walking forpackage.json, so cache chunks no longer inherit the app’s Octane manifest and trigger hook-slotting from string-matched samples inside chunk strings.Preflight classifies each module as
compile,slots, ornonevia_preflightScope/_mayHookSlot(shared withtransform); it parses withparseModuleonly when an AST-backed fact is needed. Pass-through modules still collect server static imports vialexStaticImportRequests(es-module-lexer) for plain.js/.mjs/.cjs, so imports in strings/comments are ignored.Tests cover cache ownership and Nitro chunk client-only resolution behavior.
Reviewed by Cursor Bugbot for commit 1773cd8. Bugbot is set up for automated code reviews on this repo. Configure here.