In Visual Studio 2008 there is an option "Optimize Code" that probably corresponds to the /optimize option. It is never enabled, not even when in "Release" mode.
Why should I not want this option to be enabled at all times?
In any case optimization is done by compiler, which is language-dependant, not by the assembler. No because one instruction in assembly corresponds to one instruction in machine code.
So, with the same degree of knowledge, humans can produce assembly code that is at least as performant as the compilation result. It can probably be even better, as a human developer can optimize for a given task, while the compiler can only apply generic optimizations.
Code optimization is an important phase to improve the time and space requirement of the generated target code. Given a code in intermediate form it applies optimizing techniques and reduces the code size and returns the code in intermediate form.
It is on per default for release builds (perhaps you changed the settings for Release builds?). Turn it off to make debugging easier. For release code, turn it on.
Code optimisation has gotten pretty good in C#3 - it does lots of clever performance tweaks that change your code quite a lot more in the IL than you might expect.
Some obfuscation tools (and some other IL tools like ILMerge) can sometimes break the assembly with optimisation on. The more IL tools you use the more likely you are to get serious issues with optimisation.
Also as @Brian Rasmussen already said (+1) - you want it off for debugging, on for releases.
To make this clear, optimization does inline functions and eliminate some variables. When debugging optimized code, you won't get as much help by the IDE as usual, since some of the code actually does not exist anymore. So for debugging, turn if off (default).
In languages like C++ optimization sometimes (often) has critical side effect that need to be considered. As far as i know, this is not or almost not the case for C#, so from the point of correctness of your code, it probably does not matter if you optimize or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With