Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the negative consequences of turning debug heap off? (_NO_DEBUG_HEAP==1)

The initial phase of my program loads in significant amounts of data into STL containers. I found that it was taking several minutes before I could reach the real meat of my program.

After some searching, I found that I could set _NO_DEBUG_HEAP==1 within my VS2012 Configuration Properties->Debugging->Environment variable...turning off utilization of the windows debug heap. This gave me a 10x improvement in debugging speed. I have not yet found any description what what debugging functionality I lose by doing so.

In summary: what checks were completed and what debug info was being generated by using the windows debug heap?

Thank you.

like image 676
PaulD Avatar asked Mar 26 '13 14:03

PaulD


People also ask

What is the debug heap?

The debug heap provides powerful tools to solve memory allocation problems of this kind. The Debug versions of the heap functions call the standard or base versions used in Release builds.

Is this the debug CRT heap?

It is not the Debug CRT heap. It's actually quite nice, but can be slow if you're allocating/freeing a lot of memory. This is something OpenSG's 3ds-importer does, and the difference is a 3-5 times slowdown when debugging.

Do you have performance problems when debugging Heisenbugs?

Usually I haven't had performance problems, but rather Heisenbugs that disappear when debugging (since allocated memory is 0xbaadfood instead of pseudo-random), which I've solved by attaching the debugger afterwards. Those are not many, so it's been ok to do that at times.

How do I assign a memory block in the debug heap?

Every memory block in the debug heap is assigned to one of five allocation types. These types are tracked and reported differently for purposes of leak detection and state reporting. You can specify a block's type by allocating it using a direct call to one of the debug heap allocation functions such as _malloc_dbg.


1 Answers

The debug heap impacts performance in two ways:

First, it adds checks to the heap integrity during heap operations. I haven't found details on these checks, but one assumes that on each allocation or free, it involves verifying the integrity of the data structures used to manage the heap.

Second, it disables the low-fragmentation heap (LFH) option. In a release build, you get LFH by default. In a debug build, you don't--unless you use the _NO_DEBUG_HEAP. This isn't necessarily a speed penalty, but it might be.

There are clues in the documentation for HeapSetInformation.

Note that the C and C++ runtime libraries provide memory management built on top of the system heap APIs, and they also have debug and non-debug modes that can affect performance. There is more detailed documentation about what the debug CRT does. You might check and see if turning off the CRT debugging is enough to get you a significant boost in performance without messing with the debug mode of the process heap.

like image 125
Adrian McCarthy Avatar answered Oct 05 '22 01:10

Adrian McCarthy