Skip to content

vp migrate reads and scans gitignored directories in the Vitest v5 preflight, making it 13× slower in repos with large ignored folders #3585

In review

Description

@shijithpk

Describe the bug

vp migrate reads every source-like file under each workspace package, including directories that .gitignore excludes. In our monorepo the shell app has a gitignored static/ folder (2.1 GB of editorial assets that are synced to S3/CDN and never committed). With that folder present, vp migrate on an already-migrated project takes 53s and peaks at 1.47 GB RSS. Without it, the same worktree takes 4.0s and 320 MB. No files change in either case. Our main checkout has about 1.2 GB of matching files in ignored directories (release artifacts, caches, generated SvelteKit output dirs such as .svelte-kit-build), so migrate there runs for several minutes.

The cause seems to be filesInProject() in dist/migration/bin.js, called from planVitestV5Migration(). It recursively walks each package directory, skipping only the fixed SKIP_DIRS names (node_modules, dist, build, .svelte-kit, ...). It reads every .js/.ts/.json/.yml/.sh file with readFileSync and passes each to scanAndRewriteFile. It never consults .gitignore, although the same file already uses the native isDirectoryGitignored() binding for the .vitest check.

Gitignored files can't be part of the committed project, and migrate never writes to them, so reading them only costs time and memory. There is also no CLI option or config to exclude directories (#3406 discussed a migrate.ignorePatterns option, but for a different purpose: excluding projects from rewriting).

Suggested fix: skip directories that git ignores in filesInProject(), for example with isDirectoryGitignored() or git ls-files --cached --others --exclude-standard. Fall back to SKIP_DIRS outside a git repo.

Reproduction

No repository; the script in "Steps to reproduce" creates the reproduction.

Steps to reproduce

setup() {
  mkdir "$1" && cd "$1" && git init -q
  cat > package.json <<'EOF'
{ "name": "repro", "private": true, "type": "module",
  "devDependencies": { "vite": "^8.0.0", "vitest": "^4.0.0" } }
EOF
  printf 'node_modules/\nstatic/\n' > .gitignore
  mkdir -p src && echo 'export const add = (a, b) => a + b;' > src/add.js
  git add -A && git commit -qm init
  cd ..
}
setup with && setup without

# 400 gitignored bundles (~158 MB), standing in for an S3-synced asset folder
(cd with && node -e "const fs=require('fs');const s='export const d='+JSON.stringify(Array.from({length:60000},(_, i)=>i*1.5))+';\n';for(let i=0;i<400;i++){fs.mkdirSync('static/d'+i,{recursive:true});fs.writeFileSync('static/d'+i+'/bundle.js',s)}")

for d in without with; do
  (cd "$d" && /usr/bin/time -f "$d: %es, peak %M KB" vp migrate --no-interactive --no-agent --no-editor --no-hooks > /dev/null)
done

Result:

without: 1.20s, peak 371316 KB
with: 5.15s, peak 849416 KB

Run time and memory grow with the size of the ignored folder, though nothing in it is tracked.

System Info

vp v1.8.0 (vite 8.3.8, rolldown 1.2.19, vitest 5.1.1, oxlint 1.94.0, oxfmt 0.79.0)
Node.js 26.8.2, pnpm 12.4.1
Linux arm64 (4 cores, 23 GB RAM)

Used Package Manager

pnpm

Logs

No errors; migrate completes normally, just slowly.

Validations

Activity

  1. added
    bug
    on Nov 26, 2026
  2. added theissue type on Nov 26, 2026
  3. self-assigned this
    on Nov 26, 2026
  4. voidzero-bot commented on Nov 26, 2026

    @voidzero-bot
    Contributor

    Triage failed unexpectedly (attempt 1 of 3).

    Run: https://github.com/voidzero-dev/vite-plus/actions/runs/45734783217

    I can retry if a new comment provides more information or asks me to try again.

    Error:

    [flue] skill("triage") failed: terminated
    
  5. added
    enhancement
    and removed
    bug
    on Nov 26, 2026
  6. changed the issue type fromtoon Nov 26, 2026
  7. added a commit that references this issue on Nov 26, 2026
    f899f8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Fields

Priority

None yet

Start date

None yet

Target date

None yet

Effort

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions