microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.94k stars 29.18k forks source link

Multiline text search over binary files uses lots of memory and CPU #113378

Open m-born opened 3 years ago

m-born commented 3 years ago

When using multi-file search on multi-line segments of code - i.e. such that include at least one line-break - VSCode locks up my computer by way of rg.exe running wild to eat up all RAM memory. Happens since a few weeks, used to work without problems earlier.

No regular expressions in use when this happens. Not a huge site at approx 50 files. Happens in files of all languages I work with (HTML, CSS, JS, PHP) and just as much with all extensions disabled. There are image and (large) video files in the site, but I exclude all folders containing them from the search (as good as I know how to using the respective field in the multi-file search sidebar).

I searched existing issues on this matter and in VSCode settings deactivated following sym-links, to no avail.

Steps to Reproduce:

  1. Select a code segment across more than one line (i.e. so that at least one line-break is included in the selection)
  2. Press Ctrl-Shift-F to initiate multi-file search
  3. Watch rg.exe eat up all RAM and lock up the computer

Does this issue occur when all extensions are disabled?: Yes

roblourens commented 3 years ago

How much RAM is it using? Is your computer low on RAM? I don't see any new issue here and nothing really has changed

m-born commented 3 years ago

It will use up all RAM available at the moment it starts escalating this way.

I have a total of 4 GB RAM which outside of the occurence of the described issue is easily sufficient to run VS Code plus a range of other apps in parallel at full machine performance.

What "new issue" do you reckon you should be seeing? What do you mean by "nothing really has changed"? Since it hangs up my computer every single time, I have refrained on my side from triggering multi-line / multi-file search in expectance of assistance here. Can you reproduce the issue?

roblourens commented 3 years ago

No, I can't reproduce an issue. I'll try some more.

Happens since a few weeks, used to work without problems earlier.

By "nothing has changed" I mean that nothing major in the code related to search has changed.

If you want to try to debug a little, you try searching in different folders to look for a way to narrow it down.

Or you could get the logs from the search which include the exact rg command like this:

image

m-born commented 3 years ago

Thank you, Rob.

Following your advice, I tried multi-line/multi-file search in a different folder and indeed everything worked well.

So, by way of shifting, one by one, all folders in my site to a fresh root folder and invoking ML/MF search after each move, it appeared that the issue occurs as soon as rg.exe encounters video and large images files. (In my case, a few PSDs and MP4s.) Excluding their containing folders from the search by adding patterns such as "**/__img" under "Search: Exclude" in my user settings has now seemed to resolve the problem.

I will get back to this thread in case the issue re-occurs. Until then - thank you!

roblourens commented 3 years ago

Ah, I just realized that ripgrep does not skip binary files when doing a multiline search. Filed https://github.com/BurntSushi/ripgrep/issues/1781 for this.

m-born commented 3 years ago

Success! 🤗