.NET Geek

"It is upon the Trunk that a gentleman works" - Confucius

Visual Studio "View Code" soo slow...

I don't know exactly why, but for some time, the first time I display a code window within Visual Studio there's intense disk activity for about 10 seconds. From that point on opening other source files is a snap.
It's late so I'm going to make this a short one.

Locating the problem:
1) I fired up SysInternals fileMon.
2) set it to monitor only the C: drive
3) turned off some disk intensive applications (Folding@Home, MSN Desktop search...)
4) Created a new project in Visual Studio
Stared at the fileMon log for about 30 seconds while Visual Studio was writing to the file:
C:\Documents and Settings\kim\Local Settings\Application Data\Microsoft\VisualStudio\8.0\1033\ExpansionsXML.xml
5) Googled for ExpansionsXML.xml

Turns out this is Visual Studio's cache for snippets. The size was about 800KB. I deleted the file and created a new project. Visual Studio created a new file, but this time the size was 210KB. It still took close to 10 seconds to display the first source file. I deleted all the snippet templates from:
C:\Program Files\Microsoft Visual Studio 8\VC#\Snippets\1033\*.*
and
C:\Program Files\Microsoft Visual Studio 8\VB\Snippets\1033\*.*

Now opening a source file was instantaneous! Not that I use snippets a lot (I'm using CodeRush), but I still wanted the snippets to stay around so I restored the deleted snippets.

At this point I took a step back since something was puzzling me. Why does Visual Studio need to recreate the snippet cache every time I open Visual Studio? I only have a small amount of custom snippets and I almost never update my snippets.
How can I tell Visual Studio to stop caching the snippets if the cache is present?

I made the ExpansionsXML.xml read-only and that was sign enough for Visual Studio to stay away from the file!!!
I'm only smacking my head since this has been bugging me for a few days...

Comments

David Carroll said:

I encountered exactly the same problem: my Visual Studio 2005 would freeze for over 40 seconds every time I built, refactored (including merely "Find All References"), or saved a file.  Ugh!  Following your recommendation, I made "ExpansionsXML.xml" read-only, and things got better: now I had only a 5-10 second freeze.

Still, I wondered: why was VS writing to the file hundreds & hundreds of times?  

Turns out that there is a search path for snippets in the registry, key name "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Languages\CodeExpansions\Visual C#", value name "Path".  The search is, apparently, recursive: all directories under the listed directories are also searched.  And somehow, my search path had gotten modified point to the root directory of our entire hierarchy of VS projects.  Since we have several large solutions under source control with hundreds of subdirectories and thousands of files each, this was taking a horrible amount of time.

I modified the registry entry value data string to search only those directories where we actually had snippets, and the problem went away entirely.

Thanks for the pointer!

# June 22, 2007 4:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: