Debug vs. release in .NET
Asked Answered
S

9

65

Continuing from my previous question, is there a comprehensive document that lists all available differences between debug and release modes in a C# application, and particularly in a web application?

What differences are there?

Slough answered 18/9, 2008 at 8:13 Comment(1)
B
55

"Debug" and "Release" are just names for predefined project configurations defined by Visual Studio.
To see the differences, look at the Build Tab in Project Properties in Visual Studio.

The differences in VS2005 include:

  • DEBUG constant defined in Debug configuration

  • Optimize code enabled in Release configuration

as well as other differences you can see by clicking on the "Advanced" button

But you can:

  • Change the build settings for Debug and Release configurations in Project Propeties / Build

  • Create your own custom configurations by right-clicking on the solution in Solution Explorer and selecting Configuration Manager

I think the behaviour of the DEBUG constant is fairly clear (can be referenced in the #if preprocessor directive or in the ConditionalAttribute). But I'm not aware of any comprehensive documentation on exactly what optimizations are enabled - in fact I suspect Microsoft would want to be free to enhance their optimizer without notice

Bonine answered 18/9, 2008 at 10:1 Comment(9)
This answer is correct but superficial, i wanted to know more details about how code will behave code optimization is used and DEBUG constant is used. There a lot of differences in how code will behave , you can see my previous question for an exampleSlough
Sorry if this isn't helpful. I suggest you modify your question in order to get a better answer. I think the behaviour of the DEBUG constant is fairly clear (can be referenced in the #if preprocessor directive or in the ConditionalAttribute) (contd...)Bonine
... (cont'd to get over 300c limit). But I'm not aware of any comprehensive documentation on exactly what optimizations are enabled - in fact I suspect Microsoft would want to be free to enhance their optimizer without notice.Bonine
1) What about the following issues? There are 3 configs in an ASP.NET MVC project: base (web), debug (web.debug), release (web.release). Assume we set debug and release connection string by transformation to the corresponding config (debug and release). When publishing, we can publish according to our selection in the publish dialog. But, when running application, despite I select Debug, it uses release config (bacause I set debug config in base and debug config), is that normal?Ewe
2) When running the application in Debug or Release mode, does VS use base web config or corresponding web config (web.debug.confg or web.release.config)?Ewe
@Jason, when running the project in Visual Studio,the web.config transformations are not used. They are only used when publishing. So you will get the connection string in your base web.config file,irrespective of whether you are in Debug or Release mode.Bonine
@Bonine Thanks a lot for confirmation. But anyhow, I remember that in one of our application works by using the corresponding config (web.debug / web.release) when running them on VS according to the selected mode (Debug / Release). Of course it would be possible by some changes or settings. But I also wonder, in this scene, why do I run the application in Release mode instead of Debug mode? That is the point I cannot understand.Ewe
@Jason, perhaps in that application you are using SlowCheetah, which I believe does the transform at build time: marketplace.visualstudio.com/…Bonine
I hear it, but have never used.Ewe
L
18

I'm not aware of one concise document, but:

  • Debug.Write calls are stripped out in Release
  • In Release, your CallStack may look a bit "strange" due to optimizations, as outlined by Scott Hanselman
Latia answered 18/9, 2008 at 8:20 Comment(0)
B
17

There isn't one document that lists the differences. In addition to some of the differences already listed, compiling in Debug mode turns off most of the JIT compiler optimizations that are performed at runtime and also emits more complete debug information in to the symbol database file (.pdb).

Another big difference is that the GC behavior is somewhat different in that the JIT compiler will insert calls to GC.KeepAlive() as appropriate/needed in order to support debugging sessions.

Byars answered 23/2, 2009 at 21:39 Comment(0)
R
17

Debug and Release are just labelling for different solution configurations. You can add others if you want. If you wish you can add more configurations from configuration manager–

http://msdn.microsoft.com/en-us/library/kwybya3w.aspx

Major differences –

  1. In a debug DLL several extra instructions are added to enable you to set a breakpoint on every source code line in Visual Studio. Also, the code will not be optimized, again to enable you to debug the code. In the release version, these extra instructions are removed.

  2. PDB file is created in only Debug mode and not in release mode.

  3. In release mode, code is optimized by the optimizer that's built into the JIT compiler. It makes the following optimizations:

    • Method inlining - A method call is replaced by the injecting the code of the method.

    • CPU register allocation - Local variables and method arguments can stay stored in a CPU register without ever (or less frequently) being stored back to the stack frame

    • Array index checking elimination - An important optimization when working with arrays (all .NET collection classes use an array internally). When the JIT compiler can verify that a loop never indexes an array out of bounds then it will eliminate the index check.

    • Loop unrolling - Short loops (up to 4) with small bodies are eliminated by repeating the code in the loop body.

    • Dead code elimination - A statement like if (false) { /.../ } gets completely eliminated.

    • Code hoisting- Code inside a loop that is not affected by the loop can be moved out of the loop.

    • Common sub-expression elimination. x = y + 4; z = y + 4; becomes z = x

Reger answered 19/2, 2014 at 19:15 Comment(1)
My code runs ok in debug mode, but breaks in release mode. I have no idea what happens there.Quinque
B
7

One major performanance area if you are using any of the ASP.NET Ajax controls: debug information is removed from the JavaScript library when running in release, and I have seen major preformance improvements on complicated pages. Other web based resources may be either cached or not cached based on this setting.

Also, remember that Debug / Release in a web application is dictated by the web.config file, not your settings within Visual Studio.

<system.web>
    <compilation debug="true">

More information:

Belize answered 23/2, 2009 at 21:33 Comment(0)
M
6

You can also manage some part of code that you want to run only in debug or only in release with preprocessor markups:

 #if DEBUG
    // Some code running only in debug
 #endif

or

 #if NOT DEBUG
    // Some code running only in release
 #endif
Morley answered 26/7, 2013 at 22:5 Comment(0)
E
5

Drawing with GDI+ is considerably slower in Debug mode.

Expunction answered 18/9, 2008 at 8:26 Comment(0)
A
3

Release version:

  1. is considerable faster (most important), optimized

  2. can't be debuged (step by step)

  3. and code written in "debug" directive is not included

See What's the difference between a Debug vs Release Build?.

Aculeus answered 18/9, 2008 at 8:52 Comment(1)
not like can not be debugged at all, but instead gives trouble.Pachston
P
1

I got an error message when I distribute executable file to another machine indicating that the system missed MSVCP110D.dll.

The solution to this issue is stated in Stack Overflow question Visual Studio MSVCP110D.dll is missing.

IN XXXXD.dll D means that the DLL file is a debug version of the DLL file. But MS Visual C++ Redistributable packages include only the release version of DLL files.

That means if you need to distribute a program developed by Visual C++ you need to build it in Release mode. And also you need to install MS Visual C++ Redistributable (correct version) on the target machine.

So I think this a one of key difference between debug and release mode.

Perhaps answered 9/5, 2013 at 2:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.