views:

87

answers:

2

I am working with mixed Native and Managed Visual C++, using STL in the Native. I have a strange problem. It seems that when I compile my software in Release mode with all the optimizations set, my software consistently runs slower than in Debug mode. What could be wrong here?

These are my Debug command line options:

/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Fo"Debug\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"

These are my Release command line options:

/Oi /Ot /Oy /GT /GL /D "WIN32" /D "_SECURE_SCL=0" /D "_HAS_ITERATOR_DEBUGGING=0" /D "VC_EXTRALEAN" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Fo"Release\" /Fd"Release\vc90.pdb" /W3 /nologo /c /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"

+1  A: 

That's utterly impossible to diagnose from the command line switches, you have to use a profiler.

One thing that's relevant however is you using the /clr option. Unless you explicitly use #pragma managed in your code, everything will be translated to IL, even the STL template code. Which means that your optimization settings have no effect whatsoever since they only apply to generated machine code. You are then subject to what the JIT compiler does for optimization. It will not optimize by default when you have a debugger attached for example.

Hans Passant
Did you mean #pragma unmanaged?
Nigel
Sure, could work too. I never use it because I prefer to keep all unmanaged bits in a separate DLL. And #pragma managed(push,off) and pop around the header files and the glue.
Hans Passant
A: 

Try profiling the release version to see if you notice any obviously incorrect slowness. If needed, compare it to a profile output from the debug version.

Alternately if the debug version is subjectively "fast enough", just release that (although there might be reverse-engineering implications).

Mark B