【发布时间】:2008-09-16 07:44:52
【问题描述】:
我正在寻找可用于通过向加载程序、JIT 编译器或 ngen 提供提示来确保我的 .Net 应用程序的最佳运行时性能的属性。
例如,我们有 DebuggableAttribute 应设置为不调试且不禁用优化以获得最佳性能。
[Debuggable(false, false)]
还有其他我应该知道的吗?
【问题讨论】:
标签: .net performance runtime
我正在寻找可用于通过向加载程序、JIT 编译器或 ngen 提供提示来确保我的 .Net 应用程序的最佳运行时性能的属性。
例如,我们有 DebuggableAttribute 应设置为不调试且不禁用优化以获得最佳性能。
[Debuggable(false, false)]
还有其他我应该知道的吗?
【问题讨论】:
标签: .net performance runtime
Ecma-335 在附件 F“不精确的错误”中为宽松的异常处理(所谓的 e-relaxed 调用)指定了更多的 CompilationRelaxations,但它们尚未被 Microsoft 公开。
这里特别提到了 CompilationRelaxations.RelaxedArrayExceptions 和 CompilationRelaxations.RelaxedNullReferenceException。
当您在 CompilationRelaxationsAttribute 的 ctor 中尝试一些整数时会发生什么会很有趣;)
还有一个:文字字符串(在源代码中声明的字符串)默认情况下interned 进入池以节省内存。
string s1 = "MyTest";
string s2 = new StringBuilder().Append("My").Append("Test").ToString();
string s3 = String.Intern(s2);
Console.WriteLine((Object)s2==(Object)s1); // Different references.
Console.WriteLine((Object)s3==(Object)s1); // The same reference.
虽然在多次使用相同的文字字符串时会节省内存,但维护池会花费一些 cpu,并且一旦将字符串放入池中,它就会一直停留在那里直到进程停止。
使用CompilationRelaxationsAttribute,您可以告诉 JIT 编译器您真的不希望它实习所有文字字符串。
[assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
【讨论】:
我找到了另一个:NeutralResourcesLanguageAttribute。根据this 博客文章,它通过指定当前(中性)程序集的区域性来帮助加载程序更快地找到正确的附属程序集。
[NeutralResourcesLanguageAttribute("nl", UltimateResourceFallbackLocation.MainAssembly)]
【讨论】: