Skip to content

[BUG] VSCode freezes on file change in large repo #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
christianvuerings opened this issue Nov 12, 2024 · 3 comments · May be fixed by #1233
Open

[BUG] VSCode freezes on file change in large repo #1196

christianvuerings opened this issue Nov 12, 2024 · 3 comments · May be fixed by #1233

Comments

@christianvuerings
Copy link

Describe the bug

VSCode freezes when making a file change (create / rename / delete) in a repo with lots of tests.

To Reproduce
Steps to reproduce the behavior:

  1. Clone repo with many test files: git clone https://github.com/christianvuerings/vscode-jest-large-repo.git
  2. Open VSCode with that repo: cd vscode-jest-large-repo; code .
  3. Run all tests in test explorer (running just 1 test also repros the issue)
    Image
  4. After tests finish to run, rename a non-test file src/main.js to src/main_renamed.js: mv src/main.js src/main_renamed.js

Expected behavior
VSCode doesn't freeze

Actual behavior
VSCode freezes for 5-10 seconds

Screenshots
If applicable, add screenshots to help explain your problem.

First part: shows freezing issue with 2 separate renames.
Second part: renaming works smoothly without the VSCode Jest extension

vscode-jest-free-file-rename.mp4

Environment:

  • vscode-jest version: v6.4.0
  • node -v: v18.16.1
  • npm -v or yarn --version: 9.5.1
  • jest or react-scripts (if you haven’t ejected) version: Jest 29.7.0
  • your vscode-jest settings:
    • jest.jestCommandLine? None
    • jest.runMode? on-demand
    • jest.outputConfig? None
    • anything else that you think might be relevant? Set deferred to true
  • Operating system: Mac OS 14.6.1

Prerequisite

  • are you able to run jest from the command line? Yes
  • where do you run jest CLI from? Root directory of the project
  • how do you run your tests from the command line? npm run test

Additional context
Add any other context about the problem here.

When debugging the root cause seems to be updateTestFileList:

private async updateTestFileList(): Promise<void> {
return new Promise((resolve, reject) => {
this.processSession.scheduleProcess({
type: 'list-test-files',
onResult: (files, error, exitCode) => {
this.setTestFiles(files);
this.logging('debug', `found ${files?.length} testFiles`);
if (error) {
const msg =
'failed to retrieve test file list. TestExplorer might show incomplete test items';
this.extContext.output.write(error, 'new-line');
const errorType = getExitErrorDef(exitCode) ?? 'error';
this.extContext.output.write(msg, errorType);
this.logging('error', msg, error);
reject(error);
} else {
resolve();
}
},
});
});
}

Which gets called on every file create, delete or rename

onDidCreateFiles(_event: vscode.FileCreateEvent): void {
this.updateTestFileList();
}
onDidRenameFiles(_event: vscode.FileRenameEvent): void {
this.updateTestFileList();
}
onDidDeleteFiles(_event: vscode.FileDeleteEvent): void {
this.updateTestFileList();
}

If we comment out the contents of updateTestFileList everything works smoothly

@connectdotz
Copy link
Collaborator

@christianvuerings, this is an interesting use case... The behavior you see in JestExt/core.ts is intended to keep the internal test file list up-to-date upon file lifecycle changes. But I can see this could impact a large repo even with the "on-demand" setting.

I guess we could explore a "just-in-time" updateTestFileList(), which only executes, if needed, when the next test run is scheduled...

christianvuerings added a commit to christianvuerings/vscode-jest that referenced this issue Apr 14, 2025
This change optimizes file system event handling by implementing a just-in-time
approach to updating test file lists. Rather than immediately refreshing the
test file list on every file system event, we now mark it as dirty and only
update it when necessary (before running tests).

- Add testFileListDirty flag to track when updates are needed
- Only update test file list when running or debugging tests
- Force update on initial startup for completeness
- Significantly improves performance when renaming files in large repositories

fixes jest-community#1196
@christianvuerings
Copy link
Author

@connectdotz Were you thinking something along these lines? #1233

@connectdotz
Copy link
Collaborator

@christianvuerings, yes indeed. But I am still struggling with a few questions, let's discuss in your PR. Thanks for your quick action!!👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants