Skip to content

perf(create): stop loading Vite at startup - #3580

Open
fengmk2 wants to merge 1 commit into
mainfrom
perf/create-skip-eager-vite
Open

fengmk2 wants to merge 1 commit into
mainfrom
perf/create-skip-eager-vite

Conversation

@fengmk2

@fengmk2 fengmk2 commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

vp create loaded Vite and vitest/config at startup, also on paths that read no config. This PR moves one small function so that Vite loads only when vp create reads a config.

Why vp create loaded Vite

Node.js loads and evaluates every static import of an entry, and the imports of those modules, before the entry runs its first line. In the built CLI, vite is an external package. Thus a chunk that uses Vite starts with import ... from "vite", and each chunk that imports that chunk loads Vite first.

vp create reached Vite through this static chain:

create/bin.ts
  → create/org-resolve.ts, create/register-template.ts
    → resolve-vite-config.ts
      → define-config.ts        (only for withConfigMetadataResolution)
        → vite, vitest/config   (top-level imports)

From define-config.ts, resolve-vite-config.ts used only withConfigMetadataResolution. This function only sets and restores an environment variable. But an import cannot take one function without loading its module. Tree shaking does not remove the vite import either:

  • define-config.ts is also an entry (index, define-config), so its code stays in one shared chunk.
  • Rolldown keeps an import of an external package, because the package can have side effects.

The change

withConfigMetadataResolution and its counter move into config-metadata.ts, which imports only utils/constants.ts:

create/bin.ts
  → ... → resolve-vite-config.ts
            → config-metadata.ts

define-config.ts re-exports the function, so its callers do not change. define-config and resolve-vite-config still share one counter.

Vite now loads only in resolveViteConfig, through its existing await import('./index.js'). vp create calls this function only when the monorepo root, or the start directory outside a monorepo, has a vite.config.* file. It then reads the create block.

Startup

Startup is the time from process start until vp create parses its arguments. The values use a warm compile cache.

Metric Node.js Before After Change
vp create startup 24.22.3 72.1 ms 47.5 ms −24.6 ms (−34%)
vp create startup 26.13.1 77.4 ms 57.4 ms −20.0 ms (−26%)
Load of the imports of create/bin.js 24.22.3 43.3 ms 20.2 ms −23.1 ms (−53%)
Load of the imports of create/bin.js 26.13.1 39.7 ms 18.1 ms −21.6 ms (−54%)

The change affects only the startup. The rest of vp create (prompts, file writes, install) does not change.

Behavior changes

  • vp create loads Vite only when it reads the create block of a config, for example in a monorepo with a root vite.config.ts. It then loads Vite later than before.
  • vp staged and vp pack load Vite when they resolve the config, not when the command starts. Each normal run still loads Vite.

🤖 Generated with Claude Code

resolve-vite-config.ts imported withConfigMetadataResolution from
define-config.ts, which imports Vite and vitest/config at the top level.
Thus `vp create` loaded Vite at startup, also when it only looked up
config files. resolveViteConfig already loads Vite with a dynamic import.

Move withConfigMetadataResolution and its counter into config-metadata.ts,
which does not import Vite. define-config.ts re-exports it, so its callers
do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fengmk2
fengmk2 marked this pull request as ready for review November 25, 2026 16:14
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://perf-create-skip-eager-vite-viteplus-dev.voidzero-docs.workers.dev (commit 79bcd87)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://f59dbf42-viteplus-dev.voidzero-docs.workers.dev 79bcd87 2026-11-25T15:55:02.785Z Visit the dashboard ↗

@fengmk2 fengmk2 self-assigned this Nov 25, 2026
@fengmk2
fengmk2 requested review from cpojer and wan9chi November 25, 2026 16:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants