Why Does My Stl Code Run So Slowly When I Have the Debugger/Ide Attached

Why does my STL code run so slowly when I have the debugger/IDE attached?

Running under a Microsoft debugger (windbg, kd, cdb, Visual Studio Debugger) by default forces Windows to use the debug heap instead of the default heap. On Windows 2000 and above, the default heap is the Low Fragmentation Heap, which is insanely good compared to the debug heap. You can query the kind of heap you are using with HeapQueryInformation.

To solve your particular problem, you can use one of the many options recommended in this KB article: Why the low fragmentation heap (LFH) mechanism may be disabled on some computers that are running Windows Server 2003, Windows XP, or Windows 2000

For Visual Studio, I prefer adding _NO_DEBUG_HEAP=1 to Project Properties->Configuration Properties->Debugging->Environment. That always does the trick for me.

Visual Studio application running extremely slow with debug

Set the _NO_DEBUG_HEAP environment variable to 1 (as seen on http://preshing.com/20110717/the-windows-heap-is-slow-when-launched-from-the-debugger).

This can be done from inside Visual Studio, too.

Now this is just a workaround, and I'm curious to know how to refactor a program which suffers from this kind of problem. Do you have many std::map's, shared_ptr, or any other big indirections by any chance?

Calling C++ dll from .Net code is excruciatingly slow when a debugger is attached

My best guess would be that loading the debugging symbols is what's slowing you down. I've seen the exact same thing happen with purely unmanaged C++ projects that are set to automatically load the symbol files for all of the Windows system libraries. Make sure that you're not automatically loading debugging symbols:

  1. In the "Tools" menu, click "Options".
  2. Expand the "Debugging" category to the left, and select the "Symbols" subcategory.
  3. Check the checkbox labeled "Search the above locations only when symbols are loaded manually".

Check "Search the above locations only when symbols are loaded manually"


Additionally, consider that mixed-mode debugging is extremely slow.

If you don't need the ability to step into the code in the C++ DLL, you can try turning off the "Enable unmanaged code debugging" option in your project's properties:

  Uncheck "Enable unmanaged code debugging"

/MT and /MD builds crashing, but only when debugger isn't attached: how to debug?

One little know difference between running with debugger attached or not is the OS Debug Heap (see also Why does my code run slowly when I have debugger attached?). You can turn the debug heap off by using environment variable _NO_DEBUG_HEAP . You can specify this either in your computer properties, or in the Project Settings in Visual Studio.

Once you turn the debug heap off, you should see the same crash even with debugger attached.

That said, be aware memory corruptions can be hard to debug, as often the real cause of the corruption (like some buffer overrun) may be very far from where you see the symptoms (the crash).

destroying a protocol buffer message in debug mode is almost 500 times slower than in release mode

STL containers in VS Debug are notoriously slow. Game programmers forums are rife with complaints about this. Often people choose alternative implementations. However, from what I've read, you can get a performance boost up front by disabling iterator debugging/checking:

#define _HAS_ITERATOR_DEBUGGING 0
#define _SECURE_SCL 0

Other things that can affect debug performance are excessive calls to new and delete. Memory pools can help with that. You haven't provided details for PropMsg::add_v_var_repeated() or PropMsg::~PropMsg(), so I can't comment. But I assume there's a vector or other STL container inside that class?

Console program in debug/release

The default build options for release mode will not give you sensible debugging in release mode. The optimizations the compiler uses in release mode means that the compiled code can look quite different (but be logically the same) as what you have written.

There's already a good answer to this, see How to debug in release mode?

Boost::geometry::intersection performance in Debug mode

The Boost.Geometry speed is heavily influenced by the speed of stl (vector, deque, map) which is considerably slower in Debug Mode.

You might try to solve that, e.g. by this links:

Why does my STL code run so slowly when I have the debugger/IDE attached?

Why is this code 100 times slower in debug?

Especially the second link suggests setting _HAS_ITERATOR_DEBUGGING to 0 which might help a lot because iterators are heavily used inside Boost.Geometry

Alternatively you might try using stl port.

Very slow compile times on Visual Studio 2005

The Chromium.org team listed several options for accelerating the build (at this point about half-way down the page):

In decreasing order of speedup:

  • Install Microsoft hotfix 935225.
  • Install Microsoft hotfix 947315.
  • Use a true multicore processor (ie. an Intel Core Duo 2; not a Pentium 4 HT).
  • Use 3 parallel builds. In Visual Studio 2005, you will find the option in Tools > Options... > Projects and Solutions > Build and Run > maximum number of parallel project builds.
  • Disable your anti-virus software for .ilk, .pdb, .cc, .h files and only check for viruses on modify. Disable scanning the directory where your sources reside. Don't do anything stupid.
  • Store and build the Chromium code on a second hard drive. It won't really speed up the build but at least your computer will stay responsive when you do gclient sync or a build.
  • Defragment your hard drive regularly.
  • Disable virtual memory.

How to cope with slow vectorstring destructor?

Okay, since nobody figured it out...

It was because heap tail checking was turned on in my system. Once I removed it, the code finished quickly.



Related Topics



Leave a reply



Submit