DCSIMG

 Subscribe in a reader

What Gives? DEBUG, RELEASE & Inline (Answer To Quiz) - Guy kolbis
Tuesday, December 02, 2008 6:34 AM kolbis

What Gives? DEBUG, RELEASE & Inline (Answer To Quiz)

In my recent post I have asked what will be the outcome of a method. You can view the post here. So, it is time for an answer.

The Answer

It depends! Let me explain...

Here is the output when executing it in DEBUG:

image

As you can see, we get the full trace that starts with Main(), A(), B(), C() and finally BadMethod().

Now, lets try to execute it in RELEASE:

image

Now you can see that the outcome changed. The trace is shorter and we only see Main() and BadMethod().

What Is The Reason?

DEBUG and RELEASE build configurations are different in a way that RELEASE are optimized for performance. Most of the performance optimizations are done by the JIT compiler. So, back to the outcome, we can see the the JIT had optimized our code for better performance. In fact not every method got their own local stack frame as they were optimized into fewer methods.

Method Inline

It is possible to force the JIT not to inline the code, or in other words, not to optimize the code for us. You can do that in several ways:

  1. [MethodImpl(MethodImplOptions.NoInlining)]
  2. Use Try & Catch on every method.
  3. Turn off JIT optimizations.

If you try each of the above you will get the same outcome for both DEBUG and RELEASE. Having said that, my personal opinion on the matter is that we should try to let the JIT do its work and what it does best...Optimization!

kick it on DotNetKicks.com תגים:,

תוכן התגובה

# What Gives? DEBUG, RELEASE

DotNetKicks.com כתב/ה

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Tuesday, December 02, 2008 6:40 AM

שלח תגובה

(שדה חובה) 
(שדה חובה) 
(אופציונלי)
(שדה חובה) 

Enter the numbers above: