C# 调试与发布

发布于 2024-09-13 15:46:43 字数 49 浏览 5 评论 0原文

Windows 服务在调试版本和发布版本之间可以获得多少性能增益(如果有)?为什么?

How much performance gain (if any) can a windows service gain between a debug build and release build and why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弱骨蛰伏 2024-09-20 15:46:43

对于托管代码,除非您有很多东西有条件地编译为 DEBUG 构建,否则应该没有什么区别 - IL 应该几乎相同。无论是否在调试器下运行,抖动都会产生不同的结果 - IL 的编译不会受到太大影响。

编译为 IL 时,/optimize 会执行一些操作,但它们并不是特别激进。其中一些 IL 优化可能会由抖动优化来处理,即使它们没有在 IL 中进行优化(例如删除 nop)。

请参阅 Eric Lippert 的文章 http://blogs.msdn.com/ericlippert/archive/2009/06/11/what-does-the-optimize-switch-do.aspx 了解详细信息:

/optimize 标志不会改变大量的发射和生成逻辑。我们尝试始终生成简单、可验证的代码,然后在生成真实机器代码时依靠抖动来完成繁重的优化工作。但我们将使用该标志集进行一些简单的优化。

阅读 Eric 的文章,了解有关 /optimize 在 IL 生成中确实有不同作用的信息。

For managed code, unless you have a lot of stuff conditionally compiled in for DEBUG builds there should be little difference - the IL should be pretty much the same. The Jitter generates differently when run under the debugger or not - the compilation to IL isn't affected much.

There are some things the /optimize does when compiling to IL, but they aren't particularly aggressive. And some of those IL optimizations will probably be handled by the jitter optimizations, even if they aren't optimized in the IL (like the removal of nops).

See Eric Lippert's article http://blogs.msdn.com/ericlippert/archive/2009/06/11/what-does-the-optimize-switch-do.aspx for details:

The /optimize flag does not change a huge amount of our emitting and generation logic. We try to always generate straightforward, verifiable code and then rely upon the jitter to do the heavy lifting of optimizations when it generates the real machine code. But we will do some simple optimizations with that flag set.

Read Eric's article for information about /optimize does do differently in IL generation.

绿光 2024-09-20 15:46:43

好吧,虽然这个问题是重复的,但我觉得原始问题中的一些更好的答案位于最底部。就我个人而言,我见过调试模式和发布模式之间存在明显差异的情况。 (示例:属性性能,访问属性之间存在 2 倍的差异调试和发布模式)。这种差异是否会出现在实际的软件(而不是类似基准测试的程序)中是有争议的,但我已经在我开发的一个产品中看到了这种情况的发生。

来自尼尔对原始问题的回答,来自 msdn 社交

没有详细记录,这是我所知道的。编译器发出 System.Diagnostics.DebuggableAttribute 的实例。在调试版本中,IsJitOptimizerEnabled 属性为 True,在发布版本中为 False。您可以使用 ildasm.exe 在程序集清单中看到此属性。

JIT 编译器使用此属性来禁用会使调试变得困难的优化。那些像循环不变提升一样移动代码的东西。在某些情况下,这会对性能产生很大的影响。但通常不会。

将断点映射到执行地址是调试器的工作。它使用由 JIT 编译器生成的 .pdb 文件和信息,提供 IL 指令到代码地址映射。如果您要编写自己的调试器,则可以使用 ICorDebugCode::GetILToNativeMapping()。

Well, though the question is a duplicate, I feel that some of the better answers in the original question are at the very bottom. Personally I have seen situations where there is an appreciable difference between debug and release modes. (Example : Property performance, where there was a 2x difference between accessing properties in debug and release mode). Whether this difference would be present in an actual software(instead of benchmark like program) is debatable, but I have seen it happen in one product I worked on.

From Neil's answer on the original question, from msdn social:

It is not well documented, here's what I know. The compiler emits an instance of the System.Diagnostics.DebuggableAttribute. In the debug version, the IsJitOptimizerEnabled property is True, in the release version it is False. You can see this attribute in the assembly manifest with ildasm.exe.

The JIT compiler uses this attribute to disable optimizations that would make debugging difficult. The ones that move code around like loop-invariant hoisting. In selected cases, this can make a big difference in performance. Not usually though.

Mapping breakpoints to execution addresses is the job of the debugger. It uses the .pdb file and info generated by the JIT compiler that provides the IL instruction to code address mapping. If you would write your own debugger, you'd use ICorDebugCode::GetILToNativeMapping().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文