I have a solution that has only 1 project, with about 30 class files. If I use "Find and Replace" to search the currently open document it is lightning fast, but if I try to search the entire solution it seems to take 3-4 seconds between each result. Even if there are matches right next to each other that I can see, there is still a 3-4 second lag. The hard drive isn't doing anything, and the CPU is idle - what could be causing this stall?
Check what path(s) VS searches. This may be a top-level directory resulting in large times. If this is so -- narrow down on the directory to search.
Bad program design and code from MS. If you use Resharper or similar tools you will see that this can be done much faster. Not that I get anything for the recommendation but if you learn to use Resharper (a commercial addon) you can save on so much time, not just on search and replace, but a myriad of other arduous daily programming tasks.
I found an answer by using the Microsoft Sysinternals tool ProcMon.exe. A search using Ctrl-Shift-H in VS 2008 is very slow; which is to find in all files, including Entire Solution, with the Find Options field "Look at these file types" textbox is empty.
I found through the ProcMon.exe that it shows for the DevEnv.exe process that it's searching resource files (DLLs that are included, JPG, GIF, etc). =( Ouch. I decided to change the "Look at these file types" to only process against a long text filter ".vb;.resx;*.xsd", etc. and voila, it's fast. Hmmm, that seems a little odd that it would search files that are not searchable (practically speaking). =(
The results of "devenv.exe" was significantly less, and faster with these filtered file types set.
Here are the entire steps to reproduce, so if you have other situations that you need to use this process, feel free to follow along.
- Download and run the ProcMon.exe, disable the capture for the moment (Ctrl-E)
- In ProcMone.exe, add a new Include filter where "ProcessName is devenv.exe", this helps to weed out any extraneous activity from the machine, and isolates the VS environment. Leave all other Excludes there.
- Prepare a full Entire Solution Search and Replace with lots of files and dlls in the project (the DLLs, in the BIN should of course be Excluded from the project)
- In ProcMan.exe, start the Capture (Ctrl-E). Nothing will show because the filter is narrowed to VS activity.
- In VS, to a find next, and/or do a replace
- When the search is completed, stop the filter in ProcMone.exe (Ctrl-E)
- Examine the results and see the types of files being opened and queried.
In the end, make sure the "Look at these file types" match the exact items you want to search in. Does anyone have any ideas on Excluding files like GIF, PNG, JPG, and other files that don't require searching? Probably with Regular Expressions!? Anyone want to provide some feedback so we could all benefit from a much better search and replace experience?
Ah, that's much better, I don't have to wait 5-8 seconds for finding the next hit.