调试与发布性能 [英] Debug vs. Release performance

查看:120
本文介绍了调试与发布性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下段落:


在Visual Studio中编译代码时,IDE中的调试与发布设置对性能几乎没有什么不同...生成的代码几乎是一样的。 C#编译器没有做任何优化。 C#编译器只是吐出IL ...,而在运行时它是所有优化的JITer。 JITer确实具有调试/释放模式,对性能造成巨大的影响。但是,无论您是否运行项目的Debug或Release配置,都无法关闭它,无论是否附加了调试器。




<来源是 here ,播客是这里



有人可以指示我到Microsoft文章可以证明这一点吗?



Googling C#debug vs release performance 主要返回结果说调试有很多性能打击发布被优化不要将调试部署到生产

解决方案

部分是真的。在调试模式下,编译器会为所有变量发出调试符号,并按原样编译代码。在发布模式中,包括一些优化:




  • 未使用的变量不会被编译

  • 循环变量被编译器从循环中取出,如果它们被证明是不变量

  • 在#debug指令下编写的代码不包括在其中。



    • 其余的是由JIT。



      编辑:完整的优化列表这里 Eric Lippert


      I've encountered the following paragraph:

      "Debug vs. Release setting in the IDE when you compile your code in Visual Studio makes almost no difference to performance… the generated code is almost the same. The C# compiler doesn’t really do any optimization. The C# compiler just spits out IL… and at the runtime it’s the JITer that does all the optimization. The JITer does have a Debug/Release mode and that makes a huge difference to performance. But that doesn’t key off whether you run the Debug or Release configuration of your project, that keys off whether a debugger is attached."

      The source is here and the podcast is here.

      Can someone direct me to a Microsoft article that can actually prove this?

      Googling "C# debug vs release performance" mostly returns results saying "Debug has a lot of performance hit", "release is optimized", and "don't deploy debug to production".

      解决方案

      Partially true. In debug mode the compiler emits debug symbols for all variables and compiles the code as is. In release mode some optimizations are included:

      • unused variables do not get compiled at all
      • some loop variables are taken out of the loop by the compiler if they are proven to be invariants
      • code written under #debug directive is not included etc.

      The rest is up to the JIT.

      Edit: Full list of optimizations here courtesy of Eric Lippert

      这篇关于调试与发布性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆