Sign in to follow this  
jakovo

running 400% slower on Debug mode

Recommended Posts

jakovo    476
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!

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites
Adam_42    3629
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/

Share this post


Link to post
Share on other sites
Hodgman    51230
[quote name='SiCrane' timestamp='1352332895' post='4998651']
You may want to consider using three configurations:debug mode, release mode and release with no optimizations.
[/quote]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

Share this post


Link to post
Share on other sites
wqking    761
[quote name='Hodgman' timestamp='1352338449' post='4998682']
Development - most assertions + mostly optimised + debug symbols
[/quote]
How do you have "most assertions"? You have different kinds of "assert" statements?

Share this post


Link to post
Share on other sites
Washu    7829
[quote name='wqking' timestamp='1352340574' post='4998698']
[quote name='Hodgman' timestamp='1352338449' post='4998682']
Development - most assertions + mostly optimised + debug symbols
[/quote]
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.

Share this post


Link to post
Share on other sites
Hodgman    51230
You can use something like this:
[code]#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" );
}[/code]

Share this post


Link to post
Share on other sites
L. Spiro    25621
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.
[url="http://msdn.microsoft.com/en-us/library/chh3fb0k(v=vs.80).aspx"]MSDN[/url]


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites
tanzanite7    1410
[quote name='L. Spiro' timestamp='1352343525' post='4998716']
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.
[url="http://msdn.microsoft.com/en-us/library/chh3fb0k(v=vs.80).aspx"]MSDN[/url]
[/quote]
I can strongly recommend this. Except i use it in reverse - disable optimizations in sections i currently have problems with.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this