"Start Debugging" vs "Start without Debugging" speed in VS2005

I experienced extremely slow performance in VS2005, when I "Start Debugging" an application which uses System.Drawing.Bitmap (might be anything that uses interop, but that's just my wild guess). Everything is fast if I "Start withoug Debugging" and it does not matter if I compile a release or a debug version.

Please check this little piece of code:


namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
System.Drawing.Bitmap b = new System.Drawing.Bitmap(1000, 1000);
int bla = 0;
for (int x = 0; x < 1000000; ++x) bla = bla + b.Width;
}
}
}

 


It demonstrates the difference in speed nicely and I can reproduce it on different computers. In VS2003 it's always fast. I already checked all debugging options I could find in VS2005 but none helped.
I already started a thread on gamedev.net some time ago -> http://www.gamedev.net/community/forums/topic.asp topic_id=357621
And I think, this one is related -> http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=138755&SiteID=1


Answer this question

"Start Debugging" vs "Start without Debugging" speed in VS2005

  • Kristijan M.

  • Robert_Hildebrand

    Roko - not sure if you are tracking this thread, but they closed the bug as no repro which is a joke.... its not my bug so I can't reopen it but if you want to try its up to you. I am local to MS and I can repro and I'm happy to go sit in someones office if they can't :-)

  • saadsal

    No he means he reopened the bug becuase the repro case works perfectly and the workarounds do not :-)



  • Waqar Ahmed

  • amleth

    The relationship to the gaming forum post (http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=138755&SiteID=1) is because managed directX uses bitmap.getpixel to create textures in some overloads. Since each pixel is read there are X*Y calls into the bitmpa object. With the overhead that RoKo describes about this means some create texture calls take minutes to complete when run in the debugger as opposed to seconds without (and seconds in VS2003).

  • farming

    Hi Mike,

    I'm an avid reader of your blog so had seen that already and disabled MDAs. My code is approximately 10 times slower in the debugger even after disabling all MDAs using the registry method. I'm not sure disabling them made any difference to performance at all, and wonder whether it took effect -- any way to check

    My code is very similar to the code above, but with calls to GetPixel as well. GetPixel now calls both .Height and .Width on every call (it didn't on .NET 1.1) so there's plenty of PInvoking going on. It's all very inefficient, but I expect the change is for security reasons.

    I haven't timed RoKo's code yet without MDAs -- I will if nobody else does in the next few days and will post the timings.

    Cheers


  • Nightmare1980

    No, but I did that now. It's called "Using System.Drawing.Bitmap (interop ) is extremely slow when using the debugger".
  • Russel Harvey

    This issue is now resolved thanks to Chris Goldfarb's comment at the Product Feedback Centre.

    In order to debug most processor intensive applications in VS2005, it is necessary to disable MDAs and disable the Visual Studio hosting process. This option can be found on the Debug tab of the project properties.

    (It is also necessary to disable Edit and Continue to prevent VS from crashing when working on multiple project solutions. Maybe it would be a good idea to disable every new feature in VS2005...)

    My code still runs much slower on .NET 2.0 than on 1.1 due to the abovementioned change to Bitmap.GetPixel in the new framework. I wonder if there's any mileage in reporting that as a bug My code is secure so rolling my own interop is not an option.

    Cheers


  • Hr_Ind

    Thanks ZMan. I was confused because RoKo wrote this on the 19th: "Looking at the workaround, I'm quite sure, it's a duplicate of FDBK38347." That's the MDA performance problem. Microsoft then seem to agree and close the bug back down (again ) as a dup. So does it need to be reopened again or am I misunderstanding completely !


  • fleetfingers

    Are you finding that disabling MDAs as they suggest is fixing this It's not working for me.
  • jmealing

    This is very likely the issue described here:

    http://blogs.msdn.com/jmstall/archive/2006/01/17/pinvoke_100x_slower.aspx

    Pinvokes are significantly slower under the debugger in VS2005 because of the MDAs. Does this still happen when MDAs are disabled



  • Vedat Nommaz

    A little late, but: done.

  • "Start Debugging" vs "Start without Debugging" speed in VS2005