views:

362

answers:

4

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.

A: 

The optimizations done by the compiler are fairly low level and shouldn't affect your users' experience.

If you'd like to quantify the optimization on your application, simply profile a non-optimized and an optimized build and compare the results.

Ben S
+6  A: 

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.

Zian Choy
+2  A: 

In fact, there is a difference, sometimes quite significant. What can really affect the performance (as it is something that JIT does not fully take care of):

  • Unnecessary local variables (i.e., bigger stack frames for each call)
  • Too generic conditional instructions, JIT translates them in quite a straightforward manner.
  • Unnecessary branching (also not served well by a JIT - after all, it does not have too much time to do all the smart optimisations)

    So, if you're doing something numerical - turn on the optimisation. Otherwise you won't see any difference at all.

SK-logic
+3  A: 

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

Eric Lippert