Benefits of 'Optimize code' option in Visual Studio build

后端 未结 5 781
情歌与酒
情歌与酒 2020-12-24 06:29

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.

5条回答
  •  一个人的身影
    2020-12-24 06:43

    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.

提交回复
热议问题