running 400% slower on Debug mode

Started by
8 comments, last by tanzanite7 11 years, 5 months ago
Hi,

I was looking at the framerate I get between an executable (C++) compiled on Debug mode (with VisualStudio), and on Release mode. I expect Debug mode to run slower, but I'm getting ~8fps running in Debug mode versus ~30fps running in Release mode.

I've analyzed what functions the performance comes from, but, but... I really don't know how to tackle the issue, since it's Debug mode I'm not too worried about, but sometimes it's not easy to debug other stuff running so slow...

Obviously the code is the same on both, so... how could I improve the performance running in Debug mode?

Any ideas?..

Thanks!
"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"
Advertisement
Unfortunately, the only way to make debug mode faster is to disable debugging helpers. You may want to consider using three configurations:debug mode, release mode and release with no optimizations. This gives you something that you can step through intuitively, but not encumbered performance-wise by things like extra fill patterns, but then you still have a build with those helpers when some goes screwy that you can't figure out without them.
Debug mode does tend to be slower than release but for many games with a modern CPU the graphics card is the bottleneck. You'll probably not only have issues in debug mode, but also on lower end CPUs. However running without the debugger attached may gain you some or more speed, depending on how much you use the heap. See http://www.altdevblogaday.com/2011/07/27/the-unexpected-performance-of-debug-builds/

The next thing to do to speed up the debug code is to change some compiler settings. See http://randomascii.wordpress.com/2011/07/22/visual-c-debug-buildsfast-checks-cause-5x-slowdowns/

You can also adjust your compiler settings on a per project, or per file basis which means you can leave optimizations off for easy debugging in the part of the code you're working on while having optimizations enabled elsewhere (e.g. debug game play code, with optimized rendering).

After that you need to profile the code, so you know where to optimize. You can do this on the debug code, but I'd suggest starting with the optimized code. You can get a decent free profiler at http://www.codersnotes.com/sleepy/

You may want to consider using three configurations:debug mode, release mode and release with no optimizations.
The 3 builds that I use are:
Debug - all assertions + no optimisation + debug symbols
Development - most assertions + mostly optimised + debug symbols
Shipping - no assertions + fully optimised + debug symbols

Development - most assertions + mostly optimised + debug symbols

How do you have "most assertions"? You have different kinds of "assert" statements?

https://www.kbasm.com -- My personal website

https://github.com/wqking/eventpp  eventpp -- C++ library for event dispatcher and callback list

https://github.com/cpgf/cpgf  cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.


[quote name='Hodgman' timestamp='1352338449' post='4998682']
Development - most assertions + mostly optimised + debug symbols

How do you have "most assertions"? You have different kinds of "assert" statements?
[/quote]

Yes.
assert is just a macro, and you can define your own versions which can be optionally excluded based on preprocessor conditions. It can be useful to have a larger set of assertions for debug build, and a smaller set of them for a test build.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

You can use something like this:
#define DEBUG_LEVEL 2 //this shouldn't be a #define; it should be set by the project config

#define DECLARE_DEBUG_MODULE( name, level ) const static bool dbg_##name = level <= DEBUG_LEVEL;
#define ASSERT( module, condition, message ) \
do { if( dbg_##module && !(condition) ) { AssertionFailure(__FILE__,__LINE__,message,#condition,#module); } } while(0)
void AssertionFailure( const char* file, int line, const char* message, const char* condition, const char* module )
{
//print text, show dialog, __debugbreak(), etc...
}

DECLARE_DEBUG_MODULE( FooBar, 2 ); // 2 == only debug, 1 == debug and development, 0 == all builds
void Test()
{
ASSERT( FooBar, 1==2, "test" );
}
Note that you can enable certain optimizations for certain sections of code if you are sure those sections work and are causing you performance problems.
MSDN


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

You can toggle debug settings (optimizations) per project or even per file in VS.

Note that you can enable certain optimizations for certain sections of code if you are sure those sections work and are causing you performance problems.
MSDN

I can strongly recommend this. Except i use it in reverse - disable optimizations in sections i currently have problems with.

This topic is closed to new replies.

Advertisement