设置为最高性能版本C#应用程序 [英] Setting up a C# application for max performance build

查看:160
本文介绍了设置为最高性能版本C#应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此​​,我们与我们的计划很高兴。它的快速和稳定的在调试模式下,到目前为止,这就是生活的版本与客户。现在,我们渴望自由提升我们从一个发布版本获得



我现在已经编译了该项目与代码优化版本:开。
我有TRACE常数:关。
高级 - >输出 - >调试信息 - >无



除了高效编码pracsises和系统架构等,什么是调整优化的Visual Studio设置为最大性能C#应用程序?



据我所知抖动优化默认情况下释放IL编译生成。该代码优化。(:开)涉及编译器以及它如何与内联等涉及



时,它还是有更多?正在启动跟踪的恒定关断错了吗? (我们的应用程序的邮件我们与堆栈树,如果事情严重应该去错了,我不知道,如果TRACE这里有关)


解决方案
<



    $ b:p>这是推荐的设置,我会选择一个发布版本中,所有的这些设置项目属性的生成选项卡上找到$ b
  • 取消选中定义DEBUG常数

  • 取消选中定义TRACE常数

  • 查看Opimize代码

  • 在高级...对话框中设置调试信息,以PDB-只有


您的可能的也考虑使用的 NGEN 来加快应用程序的启动时间。这个过程必须在最终用户的PC上进行(通常作为安装过程的一部分),但是通常只提高第一次运行它*应用性能。我的建议是考虑使用NGEN只有当你有在你的应用程序的冷启动时间特别关注。



做这些设置实际上做?



调试和跟踪常量



DEBUG TRACE 常量影响封闭在条件指令的任何代码,例如:(适用于根据需要TRACE替代DEBUG)

 #如果DEBUG 
//什么在这里将不会出现在最终的输出,除非DEBUG常量定义
#ENDIF

据也会影响到标有 条件等属性作为 Debug.Write Trace.Write

  //下面的调用,除非DEBUG常量定义
的Debug.WriteLine(测试)将不会出现在最终输出;

您可以通过使用类似的IL间谍的。



请注意,这些常量没有其他的效果,例如JITer不表现不同的,如果 DEBUG 定义常量。你可能会发现,这些在你的应用可以忽略不计的效果,除非你做出沉重的使用条件指令。



优化代码



这是什么控制既优化编译器(cs.exe)和编译代码时,JIT编译器执行。你可能会看到大量的你的表现的改善,此设置的结果。



下面的问题涵盖了这个设置详细所做的:





调试信​​息



PDB-仅设置告诉编译器把所有调试信息在一个单独的.PDB(程序数据库)文件。至于端组件而言,这是完全一样的设置,该组件不会受到影响,但是如果你使用 PDB -only 设置(在设置)符号,至少可如果你希望(你没有,如果你不给他们分发吨要)。这可以是例如非常有用的调试故障转储时



请注意,你不能回头,并​​为现有装配重新生成符号 - 一旦你有一个失去了.PDB一个组件(或选择不创建一个摆在首位),它几乎永远失去了! 。照顾它(尤其是对您发布野生组件)



唯一的区别,你将在这里看到的是输出的装配尺寸 - 这可能会影响加载时间和内存占用,但最终这个设置可能不会有一个特别noticable效果。






(*)假设用户行使大多数/所有的应用程序的运行,他们在第一次的功能 - 作为一种方法被称为JIT编译过程完成。阅读上JITting / NGEN了解更多详情。


So we are pretty happy with our program. It's fast and stable in Debug mode and so far that's the version live with customers. We now desire that free boost we get from a release build.

I have now compiled the project for Release with Code Optimization : On. I have TRACE constant : Off. Advanced -> output -> debug info -> None.

Besides efficient coding pracsises and system architecture etc, what are the optimal Visual Studio settings for adjusting the C# application for max performance?

As far as I know the JITter optimizes the IL compilation by default in Release builds. The Code Optimization (: On) concerns the compiler and how it deals with inlining etc.

Is that it or is there more? Is turning the TRACE constant off a mistake? (our application mails us with the stack tree if something serious should go wrong, I'm not sure if TRACE is related here)

解决方案

These are the recommended settings that I would choose for a release build, all of these settings are found on the "Build" tab of the project properties:

  • Uncheck "Define DEBUG constant"
  • Uncheck "Define TRACE constant"
  • Check "Opimize code"
  • Under the "Advanced..." dialog set "Debug Info:" to "pdb-only"

You may also wish to consider using ngen to speed up application start time. This process must be done on the end user PC (normally as part of the installation process) however will generally only improve application performance the first time that it is run*. My advice would be to consider using ngen only if you have a specific concern over the cold boot time of your app.

What do these settings actually do?

DEBUG and TRACE constants

The DEBUG and TRACE constants impact any code enclosed in conditional directives, for example: (Substitute DEBUG for TRACE as desired)

#if DEBUG
// Anything here will not appear in the end output unless the DEBUG constant is defined
#endif

It also impacts any calls made to methods marked with the Conditional attribute such as Debug.Write and Trace.Write:

// The following call will not appear in the end output unless the DEBUG constant is defined
Debug.WriteLine("Test");

You can check both of these for yourself by using something like IL Spy.

Note that these constants have no other effect, for example the JITer doesn't behave differently if the DEBUG constant is defined. You will probably find that these have neglible effect in your application unless you make hefty use of conditional directives.

Optimize code

This controls what optimisation both the compiler (cs.exe) and the JIT compiler perform when compiling your code. You are likely to see the bulk of your performance improvements as a result of this setting.

The following question covers what this setting does in more detail:

Debug info

The pdb-only setting tells the compiler to put all debug information in a separate .pdb (program database) file. As far as the end assembly is concerned this is exactly the same as the none setting in that the assembly is not impacted, however if you use the pdb-only setting (over the none setting) symbols are at least available if you wish (you don't have to distribute them if you don't want to). This can be pretty useful for example when debugging crash dumps.

Note that you can't "go back" and re-generate symbols for an existing assembly - once you have a lost the .pdb for an assembly (or chose not to create one in the first place) it is pretty much lost forever! Take care of it (especially for assemblies that you release "to the wild").

The only real difference that you will see here is output assembly size - this may impact loading times and memory footprint, but ultimately this setting probably wont have a particularly noticable effect.


(*) assuming that the user exercises most / all of the features of the application the first time they run it - the JITing process is done as a method is called. Read up on JITting / ngen for more detail.

这篇关于设置为最高性能版本C#应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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