Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits of 'Optimize code' option in Visual Studio build

Much of our C# release code is built with the 'Optimize code' option turned off. I believe this is to allow code built in Release mode to be debugged more easily.

Given that we are creating fairly simple desktop software which connects to backend Web Services, (ie. not a particularly processor-intensive application) then what if any sort of performance hit might be expected?

And is any particular platform likely to be worse affected? Eg. multi-processor / 64 bit.

like image 971
g t Avatar asked Mar 15 '10 00:03

g t


People also ask

What does optimize code do in Visual Studio?

The Optimize option enables or disables optimizations performed by the compiler to make your output file smaller, faster, and more efficient.

Does code Optimisation improve the system performance?

Optimization can reduce readability and add code that is used only to improve the performance. This may complicate programs or systems, making them harder to maintain and debug. As a result, optimization or performance tuning is often performed at the end of the development stage.

What does it mean to Optimise code?

We say that code optimization is writing or rewriting code so a program uses the least possible memory or disk space, minimizes its CPU time or network bandwidth, or makes the best use of additional cores. In practice, we sometimes default to another definition: Writing less code.


2 Answers

You are the only person who can answer the "performance hit" question. Try it both ways, measure the performance, and see what happens. The hit could be enormous or it could be nonexistant; no one reading this knows whether "enormous" to you means one microsecond or twenty minutes.

If you're interested in what optimizations are done by the C# compiler -- rather than the jitter -- when the optimize switch is on, see:

http://blogs.msdn.com/ericlippert/archive/2009/06/11/what-does-the-optimize-switch-do.aspx

like image 188
Eric Lippert Avatar answered Sep 27 '22 22:09

Eric Lippert


The full details are available at http://blogs.msdn.com/jaybaz_ms/archive/2004/06/28/168314.aspx.

In brief...

In managed code, the JITter in the runtime does nearly all the optimization. The difference in generated IL from this flag is pretty small.

like image 30
Zian Choy Avatar answered Sep 27 '22 21:09

Zian Choy