Skip to content

perf: lowers peak memory usage when using --changed on a large graph - #10866

Merged
sheremet-va merged 1 commit into
vitest-dev:mainfrom
jszumski:changed-memory-usage
Aug 5, 2026
Merged

sheremet-va merged 1 commit into
vitest-dev:mainfrom
jszumski:changed-memory-usage

Conversation

@jszumski

@jszumski jszumski commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Lowers peak memory usage when using --changed on an interconnected graph. In a large monorepo where poor test architecture makes them highly connected, machines with limited memory frequently see OOMs when computing vitest list --changed=<sha>:

<--- Last few GCs --->
--
  |  
  | [66440:0x273df000]   135185 ms: Mark-Compact 3936.3 (4169.8) -> 3862.4 (4165.5) MB, pooled: 5 MB, 3187.97 / 9.72 ms  (average mu = 0.279, current mu = 0.192) allocation failure; scavenge might not succeed
  | [66440:0x273df000]   138676 ms: Mark-Compact 3927.9 (4166.5) -> 3871.9 (4158.8) MB, pooled: 12 MB, 3074.38 / 0.00 ms  (average mu = 0.208, current mu = 0.119) allocation failure; scavenge might not succeed
  |  
  | FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

This change updates the specifications algorithm to more closely match how watcher.ts traverses the graph, changing the complexity from O(tests x modules) to O(modules).

On the failing graph from above, the peak memory usage dropped from 16.94 GB down to 2.83 GB and wall time improved from 336s to 17s.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify

netlify Bot commented Aug 3, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7d783e3
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a712683fc8a54000840148b
😎 Deploy Preview https://deploy-preview-10866--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@jszumski
jszumski marked this pull request as ready for review August 3, 2026 23:51
@jszumski

jszumski commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

CI failures seem to be existing issues on main

}
}

return runningTests
}
const cachedExists = (filepath: string): boolean => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing this, I wonder if we can reuse fsModuleCache cache somewhere here too 🤔

Not required for this PR, but worth considering

@jszumski
jszumski force-pushed the changed-memory-usage branch from 7d783e3 to f2811db Compare August 5, 2026 13:09
@jszumski
jszumski force-pushed the changed-memory-usage branch from f2811db to fbede55 Compare August 5, 2026 13:22
@jszumski
jszumski requested a review from sheremet-va August 5, 2026 14:52

@sheremet-va sheremet-va left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sheremet-va
sheremet-va merged commit 9f23f8e into vitest-dev:main Aug 5, 2026
26 of 28 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants