PHP Tools is watching way too many files.

I have these settings:

    "**/.cache/**": true,
    "**/.vscode-server/**": true,
    "**/node_modules/**": true,
    "**/var/**": true,
    "**/vendor/**": true
  },
  "php.problems.exclude": {
    "/.cache/**": true,
    "/.vscode-server/**": true,
    "/node_modules/**": true,
    "/var/**": true,
    "/vendor/**": true
  }

Using a script to find the number of watched files, 11,852 files are being watched by the process ~/.vscode-server/extensions/devsense.phptools-vscode-1.6.8448/out/server/Devsense.PHP.LanguageServer

This is kind of insane as there are only 2,293 php files in the project, including ones which are excluded. Only 328 of these php files are in folder which are included. Even if you want to make the case that every file which isnt excluded, should be watched no matter the type, that would only be 1,778 files

The only conclusion I can draw from this is either multiple watchers are being created on the same files, or every file type is being watched including files in excluded directories. Whatever the reason, this is madness. People who use file watchers to compile css/js will be totally unable to use this program as it quickly maxes out the maximum number of files being watched on medium to large projects. sysctl fs.inotify.max_user_watches

For completeness here is a breakdown of file count by directory (total 1,827,428)

Hello,

Thank you for the feedback.

I'm not sure if there are any performance issues with the file watchers? The process creates two file watchers on the workspace folder - to watch for file changes where mostly it does nothing, and to watch changes to the configuration in .editorconfig file which can be added/updated in any subdirectory.

This approach is fine on Windows, but we'll check if it can't cause any problems on Mac/Unix.

    JakubMisek On Linux systems nodejs uses the inotify subsystem. Each watched file takes up 1KB of unswappable memory (on 64bit systems). The subsystem has a limit of 8192 watchers (by default) so that not all the memory becomes unswappable.
    Even though 1KB is small, imagine working on an amazon ec2 instance where the total memory is limited to 0.5 GB (free tier), or if multiple devs are working on the same server.

    Because of these issues vscode offers features to reduce the amount of files being watched.

    Here is how vscode sets up their watchers:
    https://github.com/microsoft/vscode/blob/97bc3739bd428f91f46f70e4db471dc5c05506ae/src/vs/workbench/contrib/files/browser/workspaceWatcher.ts#L106-L153

      Also wanted to say: besides this issue, your extension is far and away the best for php on vscode. Thank you!

      Thank you @Vac1911 ! and thank you for the explanation.

      We'll try to review our watchers. I think it will be possible to get rid of them.

        I'm on Ubuntu, since few updates I had to wait from 3 to 5 minutes before it started processing workspace changes and get intellisense. I was thinking that my project is growing too big... Now it starts processing right after vs code start. I'm not 100% sure if it's because file watchers being removed but update 1.6.8588 fixed the issue.

          @wiechecprzemyslaw that may be the case! Thank you for the information.

          Initializing the workspace should be really almost instant, and removing our File Watchers on the entire workspace folder might be the problem on Unix.

            a year later

            Thank you for all the feedback;

            We have removed all of our file watchers - we only let VSCode itself notify us about changes.

            Also, we have reduced the number of I/O operations during workspace load.

              Write a Reply...