Welcome to MSDN Blogs Sign in | Join | Help

Disabling Optimizations

OK, so like 20 years ago (yes, I'm exaggerating a little) it was quite common to run across compiler bugs, where you needed to disable some optimization locally or globally to get your program to work correctly.  I think that's mostly gone now, but there are still the occasional cases.  Now days the most common reason for turning off optimizations is because you actually want to debug your code.

Am I right?  The CLR has one neat little custom attribute that allows you to turn off just one optimization in the JIT at a very local level: MethodImplAttributes.NoInlining

My question is this: Why would you ever want to use this?  My best guess is that people are wanting to the the StackTrace class to somehow compensate for C#'s lack of an equivalent for the __FILE__ macro (or it's friends __LINE__, __FUNC__, etc.)

What do you use this?  Or do you not use it?

--Grant

Published Wednesday, May 12, 2004 10:55 AM by grantri
Filed under:

Comments

# re: Disabling Optimizations

I've never used it, and probably never will. If anything, I wish there was a : MethodImplAttributes.PleaseInline or a more-general [PerformanceCritical] attribute to give the JIT a kick in the rear :)
Wednesday, May 12, 2004 11:16 AM by Ryan Lamansky (Kardax)

# re: Disabling Optimizations

Why?

It is simple.

consider the following code.

// Frequency of execution < 50%
[NoInlining]
fn1()
{
// IL size is 16
}

// Frequency of execution > 50%
fn2()
{
// IL size is 16
}

fn3(bool condition)
{
if (condition)
fn1();
else
fn2();
}


In the above code path,
Not only fn3() would have been inlined. It would have also inlined fn2() within the inlining of fn3().

Thanks
Wednesday, May 12, 2004 12:11 PM by S N
Anonymous comments are disabled
 
Page view tracker