22.6.10

Difference between Debug & Release Build Mode

Debug Mode:
* In debug mode, many of the compiler optimizations are turned off which allow the generated executable match up with the code. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. Debugging information is also generated help the debugger figure out where it is in the source code.
* Debug compile generates .pdb files containing debugging information.
* When an application is built using Debug build, a .pdb file is generated in the bin folder while this does not happen in Release build.
* There will be a speed difference, because of disabling debug methods.
* In release mode, most of the compiler's optimizations are turned on. Chunks of your code could be completely deleted, removed, or rewritten. The resulting executable will most likely not match up with your written code. However, normally release mode will run faster than debug mode due to the optimizations.

Release Mode:
* Production release should be strictly release mode only. This is because debug compilation considerably increases memory footprint since debug symbols are required to be loaded. Additionally it will hit the performance because that will include the optional debug and trace statements in the output IL code.
* The compiler emits an instance of the System.Diagnostics.DebuggableAttribute. In the debug version, the IsJitOptimizerEnabled property is True, in the release version it is False. You can see this attribute in the assembly manifest with ildasm.exe.
* The JIT compiler uses this attribute to disable optimizations that would make debugging difficult. The ones that move code around like loop-invariant hoisting. In selected cases, this can make a big difference in performance. Not usually though.
* Mapping breakpoints to execution addresses is the job of the debugger. It uses the .pdb file and info generated by the JIT compiler that provides the IL instruction to code address mapping. If you would write your own debugger, you'd use ICorDebugCode::GetILToNativeMapping().
* The Debug mode does not optimize the binary it produces (as optimizations can greatly complicate debugging), and generates additional data to aid debugging.
* The Release mode enables optimizations and generates less (or no) extra debug data.

You can append the following code to the AssemblyInfo.cs file:

#if DEBUG

[assembly: AssemblyDescription("Debug")]

#else

[assembly: AssemblyDescription("Release")]

#endif

After compiled to Assembly file (.dll or .exe), right-click the file and check its version property: Comments item is Dubug or Release.

No comments: