Why shouldn't I use the / optimize switch to compile my C # code?

Visual Studio 2008 has the Optimize Code option, which probably matches the / optimize option. It never turns on even when it is in Release mode.

Why shouldn’t I constantly enable this option?

+7
compiler-construction visual-studio
source share
3 answers

It is used by default to build releases (maybe you changed the settings for Release versions?). Disable it to make debugging easier. For release code, enable it.

+9
source share

Code optimization got a pretty good role in C # 3 - it has a lot of smart performance tweaks that change your code a lot more in IL than you might expect.

Some obfuscation tools (and some other IL tools, such as ILMerge) can sometimes break an assembly with optimizations. The more IL tools you use, the more likely you are to run into serious optimization problems.

Just like @Brian Rasmussen said (+1) - you want to debug it, for releases.

+7
source share

To make this clear, optimization performs built-in functions and excludes some variables. When debugging optimized code, you will not get the same help from the IDE as usual, as part of the code actually no longer exists. Therefore, for debugging, disable (by default).

In languages ​​such as C ++ optimization, sometimes (often) it has a decisive side effect that needs to be considered. As far as I know, this is not the case or almost not related to C #, so from the point of view of the correctness of your code, it probably does not matter if you optimize or not.

+3
source share

All Articles