Oct. 2021: this is improved from VSCode 1.61 (Sept. 2021, see below)
VSCode 1.62 includes:
File watching in VS Code changes to a new library, thanks to the work of the Parcel team with their @parcel/watcher
.
We will gradually roll out this change to all users in the upcoming weeks.
Linux users will be happy to learn that the files.watcherExclude
now applies natively so that the number of file handles VS Code needs to open for file watching can be greatly reduced.
The existing files.legacyWatcher
setting was changed to an enumeration with these values:
on
- The new file watcher will never be used.
off
- The new file watcher will always be used.
default
- The new file watcher will only be used when you open multi-root workspaces (via .code-workspace
file).
Feb. 2021: As noted in issue 40898, the issue persists for the multi-root workspace (see the last part, for VSCode 1.61 improvements)
Initial problem is that the npm
install takes twice as long to install dependencies when VSCode is running.
I've figured out that this is because of file watching for the node_modules folder so I added it to files.watcherExclude
.
I use the following combinations (but non of them seems to be working):
"files.watcherExclude": {
"**/node_modules": true,
"**/node_modules/**": true,
"**/node_modules/*/**": true
}
This comment points out a script from Dirk Feytons to see which inotify watches are actually being created to confirm whether my watcher excludes were being used or not.
/*
* If you want to see which inotify watches are being created by an application then you can
* use this simple piece of code, compile it to a shared library and LD_PRELOAD it when starting
* the application. Keep an eye on syslog to see the list of watches.
* **NOTE**: This only logs the watches, it won't actually create the watch and thus watching
* for changes WON'T actually WORK!
*
* More details (adjust as needed for your environment/distribution):
* - Save this file in e.g. $HOME/inotify.c
* - Compile: gcc -shared -o inotify.so inotify.c
* - Start monitoring syslog: tail -f -n 0 /var/log/syslog | tee $HOME/watches.log
* - Run your application with: LD_PRELOAD=$HOME/inotify.so <application>
*/
#include <sys/inotify.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
int inotify_add_watch(int fd, const char *pathname, uint32_t mask)
{
syslog(LOG_USER | LOG_ERR, "********** [%u] inotify_add_watch for %s", getpid(), pathname);
return 100000;
}
Update Sept. 2021, from Lionel Gatibelza:
I was able to fix the problem, I don't know the real cause and why Vscode performed this check for the error, but I did the known fix on the remote server and on my local machine:
- Add this
fs.inotify.max_user_watches=524288
to /etc/sysctl.conf
- Reload the configuration:
sudo sysctl -p
- Close and reopen vscode
After that I didn't have the error again!
And from issue 132483 from Benjamin Pasero (software engineer at Microsoft in Zurich):
Just to clarify, nsfw
is used on Windows as well in multi-root workspaces.
It was our original intent 5y ago to replace all other watching solutions with nsfw
so we enabled it only for multi-root scenarios, which target a lower user base (maybe 200.000 users) to get some testing and feedback.
The next step in this journey is to enable it for all users and remove the others.
PS: the only platform where nsfw
is currently not enabled by default (unless you are in a multi-root workspace) is Linux because unfortunately nsfw
does not support ignore patterns (our files.watcherExclude
setting) and each folder in a hierarchy is counted as an opened file handle against the limited set of file handles in the OS, forcing users to increase that limit.
The plan is to implement that support in October and then also get Linux on board.
Sept. 2021, VSCode 1.61:
The file watcher used to detect changes to files and folders on disk changed to a library that can handle all of our supported platforms (Windows, Linux, macOS) and reduces the overhead of maintaining different watchers for different platforms.
We plan to enable this library by default on all platforms. This iteration we enabled it on Windows and macOS, while Linux is planned shortly after.
The new watcher should be faster on startup, resulting in fewer CPU cycles spent on large folders.
One downside of using the library is that the file watcher no longer automatically detects folders in a workspace that are symbolic links on macOS.
If you have such a setup, you can use the new files.watcherInclude
setting to add symbolic link paths to include for file watching explicitly.
On the upside, you can use this new setting on Windows to explicitly include symbolic link folders inside the workspace - something that was not possible before on Windows.
You should not notice any difference in your day to day work, but if file watching is broken for you, please report an issue.
There is a setting files.legacyWatcher
to enable the old watcher in case of problems.
/etc/sysctl.conf
and adding this line to the end of the file:fs.inotify.max_user_watches=524288
”, followed bysudo sysctl -p
.