I found out why DEVENV spikes the CPU and hogs memory in visual st

Giganews Newsgroups
Subject: I found out why DEVENV spikes the CPU and hogs memory in visual st
Posted by:  GC Email Manager (GCEmailManag…@discussions.microsoft.com)
Date: Tue, 29 Apr 2008

There are a ton of posts about this so I thought I'd share my experience in
hopes that people who search for this will find this post. I don't have an IT
blog otherwise I'd post it there.

To start I'll mention that I'm using Visual Studio 2005 Pro.

I built a project over the past two years and all of a sudden i couldn't do
anything (like even typing a space bar) without the CPU spiking at 99% for
about 30 seconds. This made troubleshooting very difficult.

I tried all the tips I could find online from:

Removing startup page
Disabling Animation
Hiding all the sidebars
Copy/Paste code into new project
Reinstall SP1 (i had it already)
Re-added references to DLLs or other projects
Removed datasources on project. (don't forget to re-add if needed)

I tried disabling intellisense but I don't see that option anymore. Besides
to me that wasn't a viable option since I love it (can you tell I make
mistakes in my code?).

Anyway since I knew my other projects didn't freak out like this I figured
it must be something about my code. But I hadn't changed anything so it made
no sense to me.

So here's what I did.

I cut all my code out except the main module function and imports
statements. Now everything worked fine.

Then I pasted everything back in and waited 30 seconds.

Then I went through one function at a time and cut it, waited 30 seconds,
checked and pasted it back in when it didn't fix anything. About three
quarters of the way do  I cut one function and it didn't freak out anymore. I
pasted it back in and voila it freaked out. for kicks I left it in and tried
cutting a few others but it still freaked out.

Now I looked at the function.

Turns out this was a one time use function I created last year to do some
task. But what I had done was create a single string line of a large number
of distinguished names of active directory users. It was an ldap query I was
using and probably a year ago I was too new to ldap to know how to do the
query easier.

Turns out after pasting this one string into Word I saw that it was over
fifty seven thousands characters long.

I noticed one other important thing. When i collapsed all my function
definitions to just their first line the code worked fine. But if I expanded
just this one, the CPU spiked for 30 seconds.

So to me this is what happened: every time you change even one character or
line in your code, VS uses intellisense and "quickly" scans the whole code
for errors. But this ridiculously large string caused intellisense to take
forever. When the function code was hidden when collapsed intellisense skips
over it. There's nothing wrong with the code in the sense that it compiled
just fine.

So moral of the story? If VS CPU is spiking when writing code and nothing
else, you should check for some rogue code that could be causing it. And if
you can easily figure out how to disable intellisense, chances are it'll go
away and you can start narrowing things down like I did and still continue
using intellisense.

Good luck everyone. I hope this helps someone out.

Replies